Class LeapSeconds
- All Implemented Interfaces:
- Iterable<LeapSecondEvent>,- Comparator<LeapSecondEvent>
Holds all leap seconds occurred since the official start of UTC in 1972.
The source is either an implementation of the SPI-interface
 Provider loaded by a ServiceLoader or an internal
 standard implementation of Provider which accesses the file
 "leapseconds.data". This resource file must be in the
 classpath (in folder data). It has the format of a CSV-ASCII-text
 which has two columns separated by comma. The first column denotes
 the calendar day after the leap second shift in ISO-8601-format (for
 example 1972-07-01). The second column determines the sign of the
 leap second (+/-). 
The source will mainly be loaded by the context classloader else by application classloader. If there is no source at all then Time4J assumes that leap seconds shall not be used.
The system property "net.time4j.scale.leapseconds.suppressed"
 determines if leap seconds shall be active at all. If this system
 property has the value true then this class will never
 register any leap seconds equal if the underlying sources are filled
 or not. Furthermore, the system property
 "net.time4j.scale.leapseconds.final" determines if leap seconds
 are only registered at system start or if new ones can be lazily
 registered at runtime using the methods registerXYZ().
 Setting one of both properties can improve the performance. 
Note: This implementation is threadsafe.
- Author:
- Meno Hochschild
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic booleanSystem property "net.time4j.scale.leapseconds.final" which determines that leap seconds can be loaded only one time at system start.static StringSystem property "net.time4j.scale.leapseconds.path" which determines the path of the leap second file.static booleanSystem property "net.time4j.scale.leapseconds.suppressed" which determines that no leap seconds shall be loaded and used.
- 
Method SummaryModifier and TypeMethodDescriptionintcompare(LeapSecondEvent o1, LeapSecondEvent o2)Compares two leap second events by their date in ascending order.longenhance(long unixTime)Enhances an UNIX-timestamp with leap seconds and converts it to an UTC-timestamp.intgetCount()Yields the count of all registered leap seconds.intYields the count of all registered leap seconds which happened before given timestamp.Determines the expiration date of underlying data.static LeapSecondsReturns the singleton instance.getNextEvent(long utc)Yields the next leap second event after given UTC time point.intgetShift(long utc)Yields the shift in seconds dependent on if given UTC time point represents a leap second or not.intgetShift(GregorianDate date)Yields the shift in seconds suitable for the last minute of given calendar date.booleanQueries if the leap second support is activated.booleanQueries if a lazy registration of leap seconds is possible.booleanisPositiveLS(long utc)Queries if given UTC-timestamp represents a registered positive leap second.iterator()Iterates over all leap second events in descending temporal order.voidregisterNegativeLS(int year, int month, int dayOfMonth)Registers a new negative leap second by defining the switch-over-day.voidregisterPositiveLS(int year, int month, int dayOfMonth)Registers a new positive leap second by defining the switch-over-day.stream()Creates a stream over all leap second events in descending temporal order.longstrip(long utc)Converts given UTC-timestamp to an UNIX-timestamp without leap seconds.booleanQueries if negative leap seconds are supported.toString()For debugging purposes.Methods inherited from class java.lang.Objectequals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Comparatorequals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLongMethods inherited from interface java.lang.IterableforEach, spliterator
- 
Field Details- 
SUPPRESS_UTC_LEAPSECONDSpublic static final boolean SUPPRESS_UTC_LEAPSECONDSSystem property "net.time4j.scale.leapseconds.suppressed" which determines that no leap seconds shall be loaded and used. Defined values: "true" (suppressed) or "false" (active - default). 
- 
FINAL_UTC_LEAPSECONDSpublic static final boolean FINAL_UTC_LEAPSECONDSSystem property "net.time4j.scale.leapseconds.final" which determines that leap seconds can be loaded only one time at system start. Defined values: "true" (final) or "false" (enables lazy regisration - default). 
- 
PATH_TO_LEAPSECONDSSystem property "net.time4j.scale.leapseconds.path" which determines the path of the leap second file. Setting this property will usually suppress other leap second providers even if they have registered more leap seconds. The path is an URL which must be understood by ClassLoader.getResourceAsStream(String). The default value is: "data/leapseconds.data" (relative to class path).- Since:
- 2.1.2
 
 
- 
- 
Method Details- 
getInstanceReturns the singleton instance. - Returns:
- singleton instance
 
- 
isEnabledpublic boolean isEnabled()Queries if the leap second support is activated. - Returns:
- trueif leap seconds are supported and are also registered else- false
- See Also:
- SUPPRESS_UTC_LEAPSECONDS
 
- 
isExtensiblepublic boolean isExtensible()Queries if a lazy registration of leap seconds is possible. If the leap second support is switched off then a registration of leap seconds is never possible so this method will be ignored. - Returns:
- trueif the method- registerXYZ()can be called without exception else- false
- See Also:
- registerPositiveLS(int, int, int),- registerNegativeLS(int, int, int),- FINAL_UTC_LEAPSECONDS,- isEnabled()
 
- 
getCountpublic int getCount()Yields the count of all registered leap seconds. - Returns:
- count of registered leap seconds
 
- 
getCountYields the count of all registered leap seconds which happened before given timestamp. - Parameters:
- until- the upper search limit (exclusive)
- Returns:
- count of registered leap seconds happening before
- Since:
- 3.28/4.24
- See Also:
- getCount()
 
- 
registerPositiveLSpublic void registerPositiveLS(int year, int month, int dayOfMonth)Registers a new positive leap second by defining the switch-over-day. - Parameters:
- year- proleptic iso year
- month- gregorian month in range (1-12)
- dayOfMonth- day of month in range (1-31)
- Throws:
- IllegalStateException- if support of leap seconds is switched off by configuration or if the value of system property "net.time4j.utc.leapseconds.final" is- true
- IllegalArgumentException- if the new event is not after the last stored event or if the date is invalid
- See Also:
- isExtensible(),- isEnabled(),- SUPPRESS_UTC_LEAPSECONDS,- FINAL_UTC_LEAPSECONDS
 
- 
registerNegativeLSpublic void registerNegativeLS(int year, int month, int dayOfMonth)Registers a new negative leap second by defining the switch-over-day. - Parameters:
- year- proleptic iso year
- month- gregorian month in range (1-12)
- dayOfMonth- day of month in range (1-31)
- Throws:
- IllegalStateException- if support of leap seconds is switched off by configuration or if the value of system property "net.time4j.utc.leapseconds.final" is- true
- IllegalArgumentException- if the new event is not after the last stored event or if the date is invalid
- See Also:
- isExtensible(),- isEnabled(),- SUPPRESS_UTC_LEAPSECONDS,- FINAL_UTC_LEAPSECONDS
 
- 
supportsNegativeLSpublic boolean supportsNegativeLS()Queries if negative leap seconds are supported. - Returns:
- trueif negative leap seconds are supported else- false
- See Also:
- LeapSecondProvider.supportsNegativeLS()
 
- 
iteratorIterates over all leap second events in descending temporal order. - Specified by:
- iteratorin interface- Iterable<LeapSecondEvent>
- Returns:
- Iteratorover all stored leap second events which enables for-each-support
 
- 
streamCreates a stream over all leap second events in descending temporal order. - Returns:
- Streamover all stored leap second events in descending order
- Since:
- 4.24
 
- 
getShiftYields the shift in seconds suitable for the last minute of given calendar date. The result of this method can be added to the second value 59in order to calculate the maximum of the element SECOND_OF_MINUTE in given time context. The behaviour of the method is undefined if given calendar date is undefined.- Parameters:
- date- day of possible leap second event in the last minute
- Returns:
- shift of second element (most of the times just 0)
 
- 
getShiftpublic int getShift(long utc)Yields the shift in seconds dependent on if given UTC time point represents a leap second or not. - Parameters:
- utc- elapsed SI-seconds relative to UTC epoch [1972-01-01T00:00:00Z] including leap seconds
- Returns:
- 1, 0, -1if the argument denotes a positive leap second, no leap second or a negative leap second
 
- 
getNextEventYields the next leap second event after given UTC time point. - Parameters:
- utc- elapsed SI-seconds relative to UTC epoch [1972-01-01T00:00:00Z] including leap seconds
- Returns:
- following leap second event or nullif not known
- Since:
- 2.1
 
- 
enhancepublic long enhance(long unixTime)Enhances an UNIX-timestamp with leap seconds and converts it to an UTC-timestamp. Note: A leap second itself cannot be restored because the mapping between UNIX- and UTC-time is not bijective. Hence the result of this method can not represent a leap second. - Parameters:
- unixTime- elapsed time in seconds relative to UNIX epoch [1970-01-01T00:00:00Z] without leap seconds
- Returns:
- elapsed SI-seconds relative to UTC epoch [1972-01-01T00:00:00Z] including leap seconds
- See Also:
- strip(long)
 
- 
strippublic long strip(long utc)Converts given UTC-timestamp to an UNIX-timestamp without leap seconds. This method is the reversal of enhance(). Note that there is no bijective mapping, that is sometimes the expressionenhance(strip(val)) != valistrue.- Parameters:
- utc- elapsed SI-seconds relative to UTC epoch [1972-01-01T00:00:00Z] including leap seconds
- Returns:
- elapsed time in seconds relative to UNIX epoch [1970-01-01T00:00:00Z] without leap seconds
- See Also:
- enhance(long)
 
- 
isPositiveLSpublic boolean isPositiveLS(long utc)Queries if given UTC-timestamp represents a registered positive leap second. - Parameters:
- utc- elapsed SI-seconds relative to UTC epoch [1972-01-01T00:00:00Z] including leap seconds
- Returns:
- trueif the argument represents a registered positive leap second else- false
 
- 
getDateOfExpirationDetermines the expiration date of underlying data. - Returns:
- immutable date of expiration
- Throws:
- IllegalStateException- if leap seconds are not activated
- Since:
- 2.3
 
- 
compareCompares two leap second events by their date in ascending order. - Specified by:
- comparein interface- Comparator<LeapSecondEvent>
- Parameters:
- o1- first leap second event
- o2- second leap second event
- Returns:
- -1,- 0or- 1if first event is before, equal to or later than second event
- Since:
- 2.3
 
- 
toStringFor debugging purposes. 
 
-