News for hackers. Stuff that matters.
Re:Dates and Times in JavaScript – A New API for Dates from ... by mrlala on Thursday July 09, 2020 @04:44PM (#23784975)
I can't speak for every language you listed, but C# has great and clear datetime builtin.

Probably the only thing perhaps not the most standard are the names they use for actual time zones? So perhaps that could be improved.

But seriously I don't know how the fuck javascript people can work with dates. It's ATROCIOUS. I think my favorite one is 0 indexes on months? like if you do date(2020,07,09).. is that July 9th 2020? nope, fucking June! Not June 8th.. but June 9th.

I don't know what monster did that but there should be a special place in coding hell for him/her!

Re:Dates and Times in JavaScript – A New API for Dates from ... by tzs on Thursday July 09, 2020 @05:49PM (#23785634)
I believe that the logic behind 0 based months in many languages that use them, although I don’t know if this is true for JavaScript, is that month numbers are often used as an index into a table of month names so numbering months from 0 is convenient.
Re:Dates and Times in JavaScript – A New API for Dates from ... by mrlala on Friday July 10, 2020 @10:59AM (#23792143)
Well sure, I get the reason behind.. but the reality is it's just a horrible convention, especially when you pass multiple inputs (year, month, day, hour, minute, second) and "month" is based on 0 index but the rest are not.
Re:Dates and Times in JavaScript – A New API for Dates from ... by balfirevic on Thursday July 09, 2020 @10:58PM (#23787713)
> I can't speak for every language you listed, but C# has great and clear datetime builtin.

If you think built-in .NET DateTime is any good, give NodaTime a try. Standard DateTime is barely usable, compared to it.

For JavaScript, there is excellent js-joda library (same design as NodaTime and Joda-Time), but it's 43 kB minified and compressed, which is... not terrible but also not great, really depends on your use case if it's worth it.

Re:Dates and Times in JavaScript – A New API for Dates from ... by mrlala on Friday July 10, 2020 @10:57AM (#23792115)
>For JavaScript, there is excellent js-joda library

Well that was kind of my point- needing an external library to manage datetime is ludicrous. That's why I'm talking about what C# has builtin. No matter what new project you start, whoevers code you are working in- you can just use builtin.

>give NodaTime a try. Standard DateTime is barely usable, compared to it.

Went to the website to see some example code.. looks basically the same? Anyway thanks for the heads up but I work with datetime stuff constantly and I am not missing anything. It's easy to create datetimes, convert between time zones, add timespans etc.

Re:Dates and Times in JavaScript – A New API for Dates from ... by balfirevic on Friday July 10, 2020 @03:22PM (#23795270)
> Went to the website to see some example code.. looks basically the same?

The main difference is that there are separate types for the following concepts:

1) A point in time in global timeline

2) A specific date and time in specific time zone

3) Specific date and time but without any information about time zone (and two more related types that contain only date information or only time information).

There are a few more types, but these illustrate the main difference from .NET DateTime. In case you missed it, the basic concepts are explained here: https://nodatime.org/3.0.x/userguide/concepts (which I should have linked to in the first place).

This blog post by Jon Skeet explains the troubles with DateTime: https://blog.nodatime.org/2011/08/what-wrong-with-datetime-a... (he's also one of the authors of NodaTime).

Re:Dates and Times in JavaScript – A New API for Dates from ... by galvin on Thursday July 09, 2020 @09:25PM (#23787203)
Regarding JavaScript, either you avoid manipulating dates and just pass them to the server in ISO format, or you use a library like Moment.js.

The native API's are a disaster and using them is just asking for trouble!

Re:Dates and Times in JavaScript – A New API for Dates from ... by dmurray on Thursday July 09, 2020 @05:44PM (#23785590)
How does that work? Do you really mean it's August 9?