-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Date cannot handle leap seconds #3763
Comments
cc @floitschG. |
Leap seconds are handled by the operating system and are not exposed to client apps. The observed behavior is (until I fix issue #2771) working as intended. Short summary: However almost all operating systems internally work with (nano/milli)seconds since epoch (2007-01-01). During this mapping (from UTC timestamp to seconds-since-epoch) leap seconds are lost. You can still observe them by time standing still, by skewed times, or by time jumping backwards (or forwards), but that's it. According to http://www.ucolick.org/~sla/leapsecs/right+gps.html there are some systems (for example Android) that do not adjust their internal time-value with UTC, but rather with GPS time (no leap-seconds). This means that their would be about 15 seconds off. On my Android I cold not verify this behavior, though (maybe they hacked up the TZ files to deal with the leap-seconds?). TL;DR: the OS hides leap-seconds and Dart will thus not expose them. cc @lrhn. |
This comment was originally written by dhasenan@gmail.com It seems (with a bit of digging) that Linux handles leap seconds by saying that the number of seconds in a minute never changes, but sometimes there is a second that is twice as long as it should be. This means that interpreting time deltas between 1970 and today would be about 25 seconds' worth of duration off, but the number of seconds would be correct, according to the slightly strange but ultimately pragmatic way Linux has of handling leap seconds. Similarly, Windows Time service doesn't account for leap seconds. (WTS acts as an NTP client and server. As an intermediate NTP server, it can pass through a leap second value, but it will never generate one as a primary server.) WTS acting as an NTP client will ignore leap second indicators, and it will correct this error at the next synchronization -- in other words, leap seconds are treated as clock drift. Properly accounting for leap seconds, it seems, is a sufficiently specialized use case, and supporting them a sufficient opening for bugs, that it's probably best not to support them at all (even in the eventual Dart equivalent of jodatime). |
Correct. Only a very minor correction: I think the preferred way to deal with leap-seconds (when this is really necessary) is to set the system time to gps-time (no leap-seconds) and to handle leap-seconds as if it was a daylight saving problem (instead of shifting by 1 hour one would shift by 1 second). This would require using some modified TZ files, but almost all programs should behave consistently. |
This comment was originally written by dhasenan@gmail.com Leap seconds don't work like daylight savings, though. It's a fixed offset of +1 second that applies in perpetuity. I don't see a way to apply leap seconds using the rule system in the Olson database. Dart doesn't have any reason to do things differently than the OS it's on. Also, I'm honored that such a frivolous request has resulted in a non-trivial amount of activity. |
I'm no expert in tzfiles, but from what I can read in its man-page http://www.kernel.org/doc/man-pages/online/pages/man5/tzfile.5.html applying fixed perpetual offsets should be possible. However the user would see this offset when looking at the tzoffset value. So you are probably right that this is not the optimal solution either. Bug-reports like this one are pretty valuable. After double-checking I'm now confident that we are doing the right thing, but I prefer double-checking rather than missing something. |
This issue was originally filed by dhasenan@gmail.com
http://en.wikipedia.org/wiki/Leap_second
new Date(2008, 12, 31, 17, 59, 60, 0, false)
This yields:
Unhandled exception:
Illegal argument(s):
0. Function: 'DateImplementation.DateImplementation.' url: 'bootstrap_impl' line:88 col:42
1. Function: '::main' url: 'file:///usr/local/google/home/dhasenan/dart/tz/timetest.dart' line:4 col:9
The inability to represent leap seconds means that an application could be mistaken about the current time by as much as 25 seconds, presently, and the divergence will only get worse over time.
The text was updated successfully, but these errors were encountered: