An outline of a possible solution for sensible leap-second support.
Right now, very few people use the leap second support in tzcode. This may represent a lack of demand, or it may be due to the fact that you cannot have both leap second support and POSIX compliance at the same time. Even when people do use it, it's often done in an incomplete and incorrect way (e.g. by specifying the "right" folder directly in the TZ variable). If the tz project intends to provide leap second support, I would argue that it should be in a form that people can actually use. Also, general question: is there any standard on how leap seconds are to be handled in timezones that have an offset that is not a multiple of one whole minute? What does tzcode do now? ---- Abandon entirely the time2posix/posix2time functions, the "right" directory, and the notion of a time_t representation where e.g. 2000-01-01T00:00:00Z is represented by a value of 946684822 rather than 946684800. Very few people use them, and many of those who do use them do so incorrectly even disregarding the issue of programs they may run that do not call the conversion functions when they should. Remove support for generating tzdata files with leap second data, and report an error if one is loaded. Create a non-ambiguous representation for leap-aware timestamps. My suggestion is a pair of {time_t time; int leap;}, with time being (for leap seconds) the POSIX timestamp for the preceding normal second, and leap=1 for s=60, leap=2 for s=61, etc. Define a function interface which leap-aware systems may use to return the correct time, with leap seconds and without any skew to attempt to compensate for them. Tzcode to contain a dummy version that returns {time, 0}. The value of the existing time() function around leap seconds (e.g. whether it reports 23:59:59 twice, 00:00:00 twice, or implements some form of skew over the course of the minute/hour/day) is implementation-defined. (Arguably this new interface should also return the best known correct time immediately rather than implementing skew in the case of NTP adjustments as well, since unlike time() it is not expected to be used by legacy programs as a pseudo-monotonic counter) Define a file format and location (e.g. zoneinfo/leapdb) to store a single copy of leap second information for use by the following functions. Define leap-aware interval-measurement (difftime) and interval-addition (+ and - operator) functions. For example, since there was a leap second in June 2012, difftime_l({1341100802, 0}, {1341100798, 0}) [2012-07-01T00:00:02Z minus 2012-06-30T23:59:58Z] is 5 rather than the conventional 4. This is in contrast to the current implementation which represents these times with different values that differ by 5, and implements difftime by simple subtraction. Define leap-aware versions of mktime_r, localtime_r, mktime_rz, localtime_rz, gmtime_r, timegm_r, which use the new representation where the normal ones use time_t. Expanded scope (not part of tzcode/tzdata itself) - provide recommendations of how to represent leap second times in filesystem structures, archive structures, struct stat, struct timespec, and to maintain backwards compatibility with existing ABIs which do not provide this information (extending the range of an existing sub-second field is worth considering in some cases, though 32-bit signed nanoseconds only have room for one additional second in this way.)
On 15 Feb 2015, at 14:12, random832@fastmail.us wrote:
Also, general question: is there any standard on how leap seconds are to be handled in timezones that have an offset that is not a multiple of one whole minute? What does tzcode do now?
Leap seconds are inserted or deleted at midnight UTC at the end of March, June, September or December with at least three months notice. So a leap second could be inserted or deleted at about lunchtime in New Zealand or 5.30am in India. jch
Have there actually been any time zones that are not an even multiple of a whole minute since the advent of leap seconds? The only non whole minute time zone I know about is Dublin Mean Time, which hasn't been used since 1916. On Feb 15, 2015 3:48 PM, "John Haxby" <john.haxby@oracle.com> wrote:
On 15 Feb 2015, at 14:12, random832@fastmail.us wrote:
Also, general question: is there any standard on how leap seconds are to be handled in timezones that have an offset that is not a multiple of one whole minute? What does tzcode do now?
Leap seconds are inserted or deleted at midnight UTC at the end of March, June, September or December with at least three months notice. So a leap second could be inserted or deleted at about lunchtime in New Zealand or 5.30am in India.
jch
On 16 February 2015 at 06:28, Paul Ganssle <pganssle@gmail.com> wrote:
The only non whole minute time zone I know about is Dublin Mean Time, which hasn't been used since 1916.
The Netherlands comes to mind: "From 1909-05-01 (00:00:00 Amsterdam mean time) onwwards, the whole of the Netherlands (including the Dutch railways) was required by law to observe Amsterdam mean time (19 minutes 32.13 seconds ahead of GMT). This had already been the common practice (except for the railways) for many decades but it was not until 1909 when the Dutch government finally defined this by law. On 1937-07-01 this was changed to 20 minutes (exactly) ahead of GMT and was generally kown as Dutch Time ("Nederlands Tijd")." So, longer than 1916 but still quite a bit before leap seconds. Cheers, Philip
On 16 February 2015 at 00:28, Paul Ganssle <pganssle@gmail.com> wrote:
Have there actually been any time zones that are not an even multiple of a whole minute since the advent of leap seconds? The only non whole minute time zone I know about is Dublin Mean Time, which hasn't been used since 1916.
If I recall correctly, Africa/Monrovia is the only zone in the main files which has had an offset that is not an integer number of minutes at any point since 1970 (it was -0:44:30 until 1972-05). UTC was introduced in 1972, with the first leap second (as we know it today) coming at the end of 1972-06-30. So, no; this isn't a real concern in any existing zones. On 15 February 2015 at 09:12, <random832@fastmail.us> wrote:
Also, general question: is there any standard on how leap seconds are to be handled in timezones that have an offset that is not a multiple of one whole minute? What does tzcode do now?
In the interest of... well, interest ;) ...let's find out! Adding: Zone Test/Foo 0:00:30 - FooST to the data, and installing with make right_only, we can perform a zdump: $ zdump -c 2015,2016 -v Etc/UTC Asia/Tokyo Test/Foo ... Etc/UTC Tue Jun 30 23:59:60 2015 UT = Tue Jun 30 23:59:60 2015 UTC isdst=0 gmtoff=0 Etc/UTC Wed Jul 1 00:00:00 2015 UT = Wed Jul 1 00:00:00 2015 UTC isdst=0 gmtoff=0 ... Asia/Tokyo Tue Jun 30 23:59:60 2015 UT = Wed Jul 1 08:59:60 2015 JST isdst=0 gmtoff=32400 Asia/Tokyo Wed Jul 1 00:00:00 2015 UT = Wed Jul 1 09:00:00 2015 JST isdst=0 gmtoff=32400 ... Test/Foo Tue Jun 30 23:59:60 2015 UT = Wed Jul 1 00:00:30 2015 FooST isdst=0 gmtoff=30 Test/Foo Wed Jul 1 00:00:00 2015 UT = Wed Jul 1 00:00:30 2015 FooST isdst=0 gmtoff=30 ... So, it looks like it just keeps a constant offset (which is quite reasonable), even though in such cases it would explicitly require counting the same second twice (which is not quite so reasonable). I recalled seeing a proposed solution which took the opposite approach earlier on this list, which was to forsake the constant offset in favor of counting as normal, before "applying" the leap second at the end of the "local minute" which contained the UTC leap second. Upon further investigation, it seems that suggestion came from you, random832! http://mm.icann.org/pipermail/tz/2013-September/020155.html So in terms of behavior for the purposes of documentation, those are the two options. But, again, I doubt this is going to matter for any practical purposes anytime soon, so I would expect tzcode will likely stay as it is with respect to this matter. -- Tim Parenti
Paul Ganssle wrote:
Have there actually been any time zones that are not an even multiple of a whole minute since the advent of leap seconds?
Yes, some locations not in the tz database still use times that are not a multiple of a whole minute. One example is the Vatopedi monastery on Mt Athos. You can see Wim Voogd's 2013 photo of the Vatopedi clock, which still keeps Byzantine time, here: https://athosweblog.files.wordpress.com/2014/04/dscn2077-large.jpg Not much has changed since Harry Griswold Dwight's circa-1915 photograph: http://www.natgeocreative.com/comp/IR18/199/603213.jpg The tz code and data as currently constituted cannot feasibly represent Byzantine time.
random832@fastmail.us wrote:
(extending the range of an existing sub-second field is worth considering in some cases, though 32-bit signed nanoseconds only have room for one additional second in this way.)
One additional second is all one needs, no? Two leap seconds are never inserted adjacent to each other. So POSIX's 'struct timespec' suffices to represent leap seconds, and there's no need for a new data type here, just new operations on the type. You could start by adding a new clock to clock_gettime, a clock that respects leap seconds.
participants (6)
-
John Haxby -
Paul Eggert -
Paul Ganssle -
Philip Newton -
random832@fastmail.us -
Tim Parenti