Why does Java have support for time zone offsets with seconds precision?
Asked Answered
H

2

51

On Wikipedia time zone offsets are explained as the difference in hours and minutes from standard UTC time. However, DateTimeFormatter supports zone-offset pattern XXXXX, which "outputs the hour and minute and optional second, with a colon, such as '+01:30:15'."

Are offsets like +01:30:15 ISO valid? If not, based on which standard does Java define such offsets?

Hanus answered 23/4, 2019 at 12:5 Comment(6)
probably its development was not based on Wikipedia and/or ISOOina
If you have a look at the "See also" section under Wikipedia's article on UTC you'll see a selection of time standards that have second (and even fractional second) offsets from UTC.Of particular interst is TAI (International Atomic Time) on which UTC is based (the difference is 37s)Milden
@ChrisH the difference is currently 37s!Ounce
@LightnessRacesinOrbit yes, most of it is that one deals with leap seconds and the other doesn't. Thus supporting the parent standard requires offsets in seconds. Arguably the difference mainly concerns metrologists, space scientists and astronomers, but I share a building with the latter and you don't want to get on the wrong side of them.Milden
@ChrisH Absolutely! I worked in telecoms until last year and it's a big deal there too.Ounce
@ChrisH: As well as broadcast, where the traditional analog synchronization mechanisms (wordclock, black and burst, tri-level sync) are being replaced by network-based synchronization, namely PTP whose timebase is TAI. Broadcast is only the latest user of PTP, it is already well established in telco, robotics, and factory automation. Also, GPS time is based on TAI with a fixed offset of 19 seconds and thus currently 18 seconds to UTC.Recapture
S
82

It's not supported by ISO-8601, but it is a valid offset as recorded in the IANA time zone database.

Sub-minute offsets are common in the data for the late 19th and early 20th century, before time zones were properly standardized. For example, Europe/Paris had an offset of +00:09:21 until 1911 (according to the IANA database).

The latest occurrence I can find for this is Africa/Monrovia which had a sub-minute offset until 1972!

She answered 23/4, 2019 at 12:10 Comment(6)
Is it also involved in leap second?Incarnation
GPS time is also offset from UTC by a number of seconds (currently UTC+00:00:18).Timberwork
@Kundor: And TAI (which is used as the timebase for PTP, for example) is currently offset from UTC by 37 seconds, and has a fixed offset to GPS of 19 seconds.Recapture
@EricLippert: It does feel like it was almost written for me, yes :) (And I find it pleasant that the console app I used to find that latest occurrence was less than 25 lines long. Could probably have written it even more briefly with LINQ, but probably less readably...)She
@EricLippert: Turns out the LINQ version is more readable: gist.github.com/jskeet/f1c236d305ad5cb89daafd87941b4d88She
@JonSkeet: Your comments inspired me to figure out how to do this on a GNU system; I came up with this shell one-liner: find /usr/share/zoneinfo -type f -exec zdump -i '{}' + | awk '/^TZ/ {curtz=$1} /[+-][0-9]{6}/ {getline; print $1, curtz}' | sort. Judgment of readability is left to the beholder...Timberwork
M
3

One reason for extra precision is that the national timezones we're all familiar with aren't the end of the story.

If you have a look at the "See also" section under Wikipedia's article on UTC you'll see a selection of time standards that have second (and even fractional second) offsets from UTC.Of particular interest is TAI (International Atomic Time) on which UTC is based. The difference is 37 s at the moment, as UTC includes leap seconds and TAI doesn't. Thus to support the parent standard requires second-level precision.

GPS time is also offset from UTC by a number of seconds (the offset with respect to TAI is fixed at 19 s). GPS time and TAI (or its other derivatives) are important for navigation, telecoms/broadcast and space science.

Once you get into astronomy things get even more complicated. Terrestrial time (Wikipedia) has a fractional offset from more common scales: TT ≅ TAI + 32.184 s (to millisecond precision; TT is much more complicated than that).

Further reading as it hasn't been linked from this question yet: Falsehoods programmers believe about time (and timezones, dates, etc.) - includes some interesting background.

Milden answered 24/4, 2019 at 8:57 Comment(5)
The comments under the question had grown enough that I thought an answer was worth itMilden
OK, so seconds offsets exist, but is it common to represent them e.g. as 2017-03-28T23:40:06.000+01:30:15? It makes them not ISO-valid.Hanus
@MichalKordas having not had to deal with them at the level of writing code, I don't know. Arguably supporting these time standards at all means going beyond ISO-validity.Milden
does the ISO forbid this format or is it just not ISO-8601 conform? (which also has some versions) (sorry, too occupied to check whole ISO [:-) ) ((and ISO is one of many standards))Oina
@CarlosHeuberger I don't have access to the full text. From all the summaries I've seen it's not included. If not explicitly mentioned, does that mean it's forbidden? allowed? out of scope?Milden

© 2022 - 2024 — McMap. All rights reserved.