Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are leap seconds catered for by Calendar?

Tags:

java

calendar

Are leap seconds catered for by the GregorianCalendar class?

If not, does any 3rd party library cater for it?

like image 603
Bohemian Avatar asked Dec 28 '12 06:12

Bohemian


People also ask

How are leap seconds determined?

Insertion of each UTC leap second is usually decided about six months in advance by the International Earth Rotation and Reference Systems Service (IERS), to ensure that the difference between the UTC and UT1 readings will never exceed 0.9 seconds.

How often does a leap second occur?

Leap second events occur on either June 30th or December 31st and do not happen very often - about every two-three years. The International Earth Rotation and Reference Systems Service (IERS) is responsible for notifying the public when a leap second will be inserted.

What is the purpose of a leap second?

Leap seconds are added in order to keep the difference between UTC and astronomical time (UT1) to less than 0.9 seconds. The International Earth Rotation and Reference Systems Service (IERS), measures Earth's rotation and publishes the difference between UT1 and UTC.

Will 2022 have a leap second?

Latest update: In July 2022, the International Earth Rotation and Reference Systems Service (IERS) announced that “NO leap second will be introduced at the end of December 2022.” The next possible date is June 30, 2023.


2 Answers

  1. Leap seconds are not catered for by GregorianCalendar (a view of the source code at Oracle shows this - explicit assumption of 1 minute = 60 seconds always is given there). And furthermore: Oracle has now officially denied leap second support - see Bug-ID 4272347.
  2. In Java there is no standard 3rd party library supporting leap seconds - not even joda-time. Only specialized software like this does that.
  3. Note that many libraries do talk about leap seconds although not supporting, for example java.util.Date (see Dorofeevs answer). Also JSR 310 talks a lot, but does not support this feature. Officially JSR 310 gives support to UTC-SLS which does not count leap seconds and only describes smearing rubber seconds around a leap second event. Indeed JSR 310 is very confusing about if it supports UNIX time or UTC-SLS (see next point). And since leap second information (github/threeten/issues/197) has been removed from JSR 310 code base it is absolutely impossible to implement true UTC leap seconds within the scope of JSR 310. In best case you might expect a coming external module (Threeten-Extra) as supplement for JSR 310 which will give rudimentary support at best (it is rather a translation between UNIX time and TAI time scale, not more and uses in my opinion a fundamentally wrong domain model).
  4. System.currentTimeMillis() officially relates to OS timer. And since all OS I know including Microsoft, Linux and Apple are only based on UNIX specification this java system timer does not count leap seconds, only the normal milliseconds since 1970-01-01T00:00:00.000Z
  5. Because of all these facts I have decided to set up my own date and time java library named Time4J which fully supports leap seconds and is available as v1.0 with LGPLv2.1-licence. A dzone-article demonstrates how this support looks like with version v4.2.
like image 200
Meno Hochschild Avatar answered Sep 30 '22 04:09

Meno Hochschild


java.util.Date API says that

"...although the Date class is intended to reflect coordinated universal time (UTC), it may not do so exactly, depending on the host environment of the Java Virtual Machine. ... Most computer clocks are not accurate enough to be able to reflect the leap-second distinction."

Wiki says

"Because the Earth's rotation speed varies in response to climatic and geological events, UTC leap seconds are irregularly spaced and unpredictable. Insertion of each UTC leap second is usually decided about six months in advance by the International Earth Rotation and Reference Systems Service (IERS)"

that is, no class can know about future IERS decisions.

like image 21
Evgeniy Dorofeev Avatar answered Sep 30 '22 03:09

Evgeniy Dorofeev