6 ms·
>The exact way Unix time handles leap seconds* is complex and an unnecessary detail for this article, but it will suffice to say that (i) whenever a positive le
by Tenoke 4y ago
>The exact way Unix time handles leap seconds* is complex and an unnecessary detail for this article, but it will suffice to say that (i) whenever a positive leap second occurs, a timestamp is used twice, and (ii) if a negative leap second were to occur, a timestamp is skipped.
Huh, I always assumed that Unix time just ignores them and ticks forward. I get why e.g. UTC needs them but why would it make sense for Unix time to account for them given how it's defined.
- Cu3PO42 4y agoIf Unix time ignored them, the conversion between timestamps and UTC would no longer be possible with just arithmetic operations. You'd need a list of leap seconds and take them into account. Now one can argue if this is better or worse than the current solution, but it's not without its tradeoffs.
- jesprenj 4y agoEdit: My original comment is incorrect. Please read child comments. Original comment: Yes, to convert from UNIX time to UTC, you do need a list of leap seconds.
- masklinn 4y agoNo. You need a list of leap seconds to convert from Unix time to TAI.
- valleyer 4y agoOthers have already corrected you, but in case it makes it more concrete, here is the implementation of timegm() in musl (the libc used in Alpine Linux and some other Linux distributions). timegm() takes a time in UTC and converts it to Unix time. http://git.musl-libc.org/cgit/musl/tree/src/time/timegm.c http://git.musl-libc.org/cgit/musl/tree/src/time/timegm.c http://git.musl-libc.org/cgit/musl/tree/src/time/__tm_to_secs.c http://git.musl-libc.org/cgit/musl/tree/src/time/__tm_to_sec... You'll notice there is no handling or knowledge of leap seconds. (Leap years are handled, of course.)
- DemocracyFTW2 4y agoI'd argue that a very short and rather simple and infrequently changing list of delta seconds (which are only ever applicable around 23:59:59, December 31 of some years) is vastly preferable over any other of the solutions (or rather 'coping strategies' as it were) that are used now, things like Google and Amazon smearing their leap seconds but in ever so slightly incompatible ways.
- afiori 4y agoAccording to Wikipedia there are 27 leap seconds and obviously there is already a procedure in place to communicate new ones to the OS. Adding them into the conversion would add O(log(#leap_seconds)) complexity. I think that continued use of leap seconds is entirely due to inertia.
- qbrass 4y agoIt's usually set up to sync to NTP.