News for hackers. Stuff that matters.
Re:Dates and Times in JavaScript – A New API for Dates from ... by mattwad on Thursday July 09, 2020 @01:48PM (#23782898)
It's not just that. Timezones are the real bugger. Microsoft has their own list of names separate from the standard IANA timezones, for example. If it weren't for timezones, IMO dates are pretty damn trivial. It's just a matter of storing and transferring them properly (in UTC, always!)
Re:Dates and Times in JavaScript – A New API for Dates from ... by frenchyatwork on Thursday July 09, 2020 @02:09PM (#23783186)
Timestamps are damn trivial. When people use dates, that's all they want 90% of the time. The remaining 10% is where all the hard problems are.

For example, lets say I have a store that opens from 8:00-17:00 every day, and it's currently 22:00. How long is it till it opens next?

Re:Dates and Times in JavaScript – A New API for Dates from ... by noja on Thursday July 09, 2020 @02:14PM (#23783248)
Three days and an hour more than you think, because it's the weekend, and an extra day because the public holiday for tomorrow may or not be a working day. Oh and there was a timezone change.
Re:Dates and Times in JavaScript – A New API for Dates from ... by bonedangle on Thursday July 09, 2020 @02:44PM (#23783571)
And it's December 31st.. Still shocked by how many times I see a year rollover go bad.
Re:Dates and Times in JavaScript – A New API for Dates from ... by unilynx on Thursday July 09, 2020 @05:15PM (#23785314)
Even before the rollover it get's bad. I had a CI failure on 31 December 2018 for code which worked fine on 31 December 2017, because it was the first time for that code to have Dec 31 in week 1 of the next year.

And last year someone else's code failed on 30 December 2019, so I had a pretty good idea where to look.

Still need to fix a bug in code written only yesteryear because the 1st of July wasn't on a Monday this year, but I decided to snooze that test failure ... it'll work fine again in 9 years.

Re:Dates and Times in JavaScript – A New API for Dates from ... by aarong11 on Thursday July 09, 2020 @02:51PM (#23783668)
There was a leap second too, you forgot that one!
Re:Dates and Times in JavaScript – A New API for Dates from ... by timgilbert on Thursday July 09, 2020 @03:29PM (#23784075)
...oh, and I hope you know whether your customer is Israeli or Palestinian!

https://www.972mag.com/the-worlds-only-ethnic-time-zone/

Re:Dates and Times in JavaScript – A New API for Dates from ... by reggieband on Thursday July 09, 2020 @05:31PM (#23785462)
People joke, but I worked on a calendar application (well, it was a time series graph) where a leap second caused a rendering bug.
Re:Dates and Times in JavaScript – A New API for Dates from ... by yxhuvud on Thursday July 09, 2020 @05:47PM (#23785608)
There was this bug in Java related to a leap second that broke all Java servers in the world one summer..
Re:Dates and Times in JavaScript – A New API for Dates from ... by tigershark on Friday July 10, 2020 @03:14AM (#23788996)
No, they are not trivial at all as I explained in my previous comment. For more sauce: https://codeblog.jonskeet.uk/2019/03/27/storing-utc-is-not-a...

About your question it’s impossible to answer without further context. There may be DST tonight, or a leap second, or the enforcement of some strange treaty that will change the time zone..

Re:Dates and Times in JavaScript – A New API for Dates from ... by other_herbert on Thursday July 09, 2020 @05:40PM (#23785551)
This is a case for events! The store opens when the owner unlocks the door..... but since you are in that nebulous time when it is "closed" the next "open" may never happen.. so maybe what really needs to happen is a giant disclaimer around times for things...

like in your search results for let's say some M-F 8-5 business... it would say "Hours: 8:00-17:00, Closed right now, in 72% of the cases, the next opening time is tomorrow morning at 8"

Re:Dates and Times in JavaScript – A New API for Dates from ... by smichel17 on Thursday July 09, 2020 @10:58PM (#23787711)
As a shortcut for coming up with the corner cases yourselves, this document has a good list of them: https://moment.github.io/luxon/docs/manual/math.html
Re:Dates and Times in JavaScript – A New API for Dates from ... by jniedrauer on Thursday July 09, 2020 @09:40PM (#23787289)
I recently did this for a task scheduler. The logic lives in SQL. That was a "fun" query to write... You might think it's the wrong tool for the job, but it was a lot faster than reading every possible row and checking it in the application itself.
Re:Dates and Times in JavaScript – A New API for Dates from ... by mad182 on Thursday July 09, 2020 @02:41PM (#23783534)
You forgot there will be a leap second and switch to summer time.
Re:Dates and Times in JavaScript – A New API for Dates from ... by 1-more on Thursday July 09, 2020 @03:28PM (#23784062)
There is a case to not store a time in UTC: you schedule a meeting in the future and the local authorities change when they start DST in that location. Now your user gets the alert an hour too early or late for their meeting. The scenario is more fleshed out in the link below but I don't want to just copy and paste the article into the comment.

http://www.creativedeletion.com/2015/03/19/persisting_future...

Re:Dates and Times in JavaScript – A New API for Dates from ... by tigershark on Friday July 10, 2020 @03:09AM (#23788972)
No they are absolutely not. Ask Jon Skeet for example:

https://codeblog.jonskeet.uk/2010/12/01/the-joys-of-date-tim...

https://codeblog.jonskeet.uk/2019/03/27/storing-utc-is-not-a...

Or look at the usual falsehood list:

https://gist.github.com/timvisee/fcda9bbdff88d45cc9061606b4b...

Some interesting ones:

A week (or a month) always begins and ends in the same year.

Months have either 28, 29, 30, or 31 days.

There is a leap year every year divisible by 4.

The day before Saturday is always Friday.

Re:Dates and Times in JavaScript – A New API for Dates from ... by deathanatos on Thursday July 09, 2020 @07:18PM (#23786403)
> in UTC, always!

… which the proposal doesn't use. (It uses POSIX.)