News for hackers. Stuff that matters.
Re:JavaScript dates are about to be fixed by Etheryte on Saturday August 24, 2024 @01:27PM (#41339782)
While UTC timestamps look like they solve all of the problems in one passing, they have plenty of edge cases that can blow up spectacularly. A good example of this is daylight saving time and countries changing their rules around it. You would think this is a rare occurrence, but it actually happens pretty often [0]! In the last ten years, fourteen countries have abolished daylight saving time.

[0] https://en.wikipedia.org/wiki/Daylight_saving_time_by_countr...

Re:JavaScript dates are about to be fixed by mmis1000 on Saturday August 24, 2024 @03:24PM (#41340747)
Like, what if you only need the date but not the time? You can use timestamp to store a birthday, but which in which timezone should you transform it back to date?

Or what if it is specifically about time in timezone independent way? You want to wake up ate 06:00 no matter in any timezone. Just something like alert.

You could use part of ISO8601 like 2020-02-02 or 06:00:00 to store exactly what you specify. But with timestamp, not so much.

Re:JavaScript dates are about to be fixed by dunham on Saturday August 24, 2024 @01:59PM (#41340030)
We hit this with the US timezone change in 2005. The front-end devs were using moment.js which didn't know about the previous start/end dates.

These days I try to encode everything that is logically a date as yyyy-mm-dd. And if I need to do math with it, I often work with an offset julian date as an integer. But that only works if you stay on this side of September 1752:

    % cal 09 1752
       September 1752     
    Su Mo Tu We Th Fr Sa  
           1  2 14 15 16  
    17 18 19 20 21 22 23  
    24 25 26 27 28 29 30
Re:JavaScript dates are about to be fixed by Denvercoder9 on Saturday August 24, 2024 @04:07PM (#41341103)
If you're truly using Julian dates, the switch to the Gregorian calendar in the UK and US in September 1752 shouldn't affect you.
Re:JavaScript dates are about to be fixed by layer8 on Saturday August 24, 2024 @02:27PM (#41340274)
Before roughly 100 years ago, calendar dates were region-dependent anyway (Russia was still on the Julian calendar until 1918), and time zones didn’t really exist until roughly 150 years ago (their establishment mostly being motivated by the spreading of railways). It’s okay to apply the perpetual Gregorian calendar both into the past and the future by default. It probably won’t last more than a couple thousand years into the future as well, considering Earth’s decelerating rotation.
Re:JavaScript dates are about to be fixed by nradov on Saturday August 24, 2024 @06:41PM (#41342381)
Some Orthodox Churches still use the Julian calendar even today. Of course they aren't major software customers.
Re:JavaScript dates are about to be fixed by langcss on Sunday August 25, 2024 @04:18AM (#41345514)
I think time zones not existing really meant there were infinite time zones, because you use the sun to tell the time.
Re:JavaScript dates are about to be fixed by layer8 on Sunday August 25, 2024 @08:59AM (#41346978)
The solar day varies in length by more than a minute over the year. That doesn't correspond to a well-defined time zone. Also, "zone" implies a geographical area, which meridians arguably aren't.
Re:JavaScript dates are about to be fixed by LoganDark on Saturday August 24, 2024 @03:39PM (#41340872)
oof, there went 12 days. at least this isn't a regular occurrence outside of 1752 (unless you have DID, I guess)
Re:JavaScript dates are about to be fixed by thaumasiotes on Saturday August 24, 2024 @05:42PM (#41341824)
> if I need to do math with it, I often work with an offset julian date as an integer. But that only works if you stay on this side of September 1752

Wouldn't using Julian days prevent the ordinary problems involved with doing calendar math across a renumbering of the dates?

Re:JavaScript dates are about to be fixed by dunham on Saturday August 24, 2024 @09:47PM (#41343635)
The mapping from year, month, day that I use (based on the Wikipedia page, but starting on march 1, 1600) doesn't take that gap into account. So the days in that gap exist for me, but we don't deal with dates that far back.
Re:JavaScript dates are about to be fixed by RandomThoughts3 on Saturday August 24, 2024 @01:54PM (#41339985)
Technically you could use TAI for most things internally and use an offset when you display. It works perfectly for records. The only issue is with scheduled things when your users probably want to point at something in their timezone.
Re:JavaScript dates are about to be fixed by ikekkdcjkfke on Saturday August 24, 2024 @02:37PM (#41340364)
Or toLocalDisplayString(TAI timestamp). It seems like timezones and their rules change over time and geographic location, using todays rules to show dates back in time with previous rules would be broken right?
Re:JavaScript dates are about to be fixed by jitl on Saturday August 24, 2024 @02:59PM (#41340546)
Well, any correct time handling library will use something like the IANA timezone database (aka tz/tzdb/zoneinfo) which stores all the changes in timezone rules for localities over the years - a library that only knows "today's rules" would be fundamentally broken as you say. So the internals of toLocalDisplayString(timestamp, timezone, calendar, locale) should look up the appropriate rules in effect at the timestamp and use those to decide the local time to display.
Re:JavaScript dates are about to be fixed by labster on Saturday August 24, 2024 @02:25PM (#41340261)
The main problem is that future values of TAI converted into most time zones is nondeterministic. On the other hand, at least you can guarantee all TAI seconds will actually occur.
Re:JavaScript dates are about to be fixed by naasking on Saturday August 24, 2024 @02:52PM (#41340490)
Sure, but now you've reduced the scope of the problem to a few edge cases. Every other solution I've seen still has these edge cases and doesn't solve the core problem as simply as UTC. If you think otherwise, can you describe or provide a link to these other solutions?
Re:JavaScript dates are about to be fixed by lxgr on Saturday August 24, 2024 @03:07PM (#41340610)
For region-specific events (which includes most physical meetings, by convention many financial processes etc.), it's much safer to store both the local time and time zone city, as well as the UTC offset at the time of writing, and to convert to UTC only at runtime using an up-to-date time zone database.

That way, you can identify all of:

- Future timestamps you might want to re-process, e.g. for notification scheduling, because the future UTC conversion has changed between scheduling/updating the event and now.

- Equivalently, timestamps written by software/an OS running an outdated TZ database. You should talk to them; things are about to go wrong if the date is in the non-too-far future!

- Trivially and without conversion, the local time that people will use in the meeting notes, documenting that you missed the meeting because you didn't update your TZ database and dialed in to the meeting an hour late

Re:JavaScript dates are about to be fixed by 9dev on Saturday August 24, 2024 @04:27PM (#41341230)
I’ve been thinking about this; does a timestamp even work, then, without not only a time zone, but a location? I mean time zones are poor man’s locations, but if we want to do this properly…