Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Are leap seconds catered for by the GregorianCalendar class?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
275 views
Welcome To Ask or Share your Answers For Others

1 Answer

  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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...