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

JavaJava Time

Java Problem Overview


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?

Java Solutions


Solution 1 - Java

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!

Solution 2 - Java

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMichal KordasView Question on Stackoverflow
Solution 1 - JavaJon SkeetView Answer on Stackoverflow
Solution 2 - JavaChris HView Answer on Stackoverflow