public final class LeapSeconds extends Object implements 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 "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
"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.
| Modifier and Type | Field and Description |
|---|---|
static boolean |
FINAL_UTC_LEAPSECONDS
System property "net.time4j.scale.leapseconds.final"
which determines that leap seconds can be loaded only one time at
system start.
|
static String |
PATH_TO_LEAPSECONDS
System property "net.time4j.scale.leapseconds.path"
which determines the path of the leap second file.
|
static boolean |
SUPPRESS_UTC_LEAPSECONDS
System property "net.time4j.scale.leapseconds.suppressed"
which determines that no leap seconds shall be loaded and used.
|
| Modifier and Type | Method and Description |
|---|---|
int |
compare(LeapSecondEvent o1,
LeapSecondEvent o2)
Compares two leap second events by their date in ascending order.
|
long |
enhance(long unixTime)
Enhances an UNIX-timestamp with leap seconds and converts it to an
UTC-timestamp.
|
int |
getCount()
Yields the count of all registered leap seconds.
|
int |
getCount(UnixTime until)
Yields the count of all registered leap seconds which happened before given timestamp.
|
GregorianDate |
getDateOfExpiration()
Determines the expiration date of underlying data.
|
static LeapSeconds |
getInstance()
Returns the singleton instance.
|
LeapSecondEvent |
getNextEvent(long utc)
Yields the next leap second event after given UTC time point.
|
int |
getShift(GregorianDate date)
Yields the shift in seconds suitable for the last minute
of given calendar date.
|
int |
getShift(long utc)
Yields the shift in seconds dependent on if given UTC time point
represents a leap second or not.
|
boolean |
isEnabled()
Queries if the leap second support is activated.
|
boolean |
isExtensible()
Queries if a lazy registration of leap seconds is possible.
|
boolean |
isPositiveLS(long utc)
Queries if given UTC-timestamp represents a registered
positive leap second.
|
Iterator<LeapSecondEvent> |
iterator()
Iterates over all leap second events in descending temporal
order.
|
void |
registerNegativeLS(int year,
int month,
int dayOfMonth)
Registers a new negative leap second by defining the
switch-over-day.
|
void |
registerPositiveLS(int year,
int month,
int dayOfMonth)
Registers a new positive leap second by defining the
switch-over-day.
|
Stream<LeapSecondEvent> |
stream()
Creates a stream over all leap second events in descending temporal order.
|
long |
strip(long utc)
Converts given UTC-timestamp to an UNIX-timestamp without
leap seconds.
|
boolean |
supportsNegativeLS()
Queries if negative leap seconds are supported.
|
String |
toString()
For debugging purposes.
|
equals, getClass, hashCode, notify, notifyAll, wait, wait, waitforEach, spliteratorcomparing, comparing, comparingDouble, comparingInt, comparingLong, equals, naturalOrder, nullsFirst, nullsLast, reversed, reverseOrder, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLongpublic static final boolean SUPPRESS_UTC_LEAPSECONDS
System 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).
public static final boolean FINAL_UTC_LEAPSECONDS
System 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).
public static final String PATH_TO_LEAPSECONDS
System 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).
public static LeapSeconds getInstance()
Returns the singleton instance.
public boolean isEnabled()
Queries if the leap second support is activated.
true if leap seconds are supported and are also
registered else falseSUPPRESS_UTC_LEAPSECONDSpublic 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.
true if the method registerXYZ() can be
called without exception else falseregisterPositiveLS(int, int, int),
registerNegativeLS(int, int, int),
FINAL_UTC_LEAPSECONDS,
isEnabled()public int getCount()
Yields the count of all registered leap seconds.
public int getCount(UnixTime until)
Yields the count of all registered leap seconds which happened before given timestamp.
until - the upper search limit (exclusive)getCount()public void registerPositiveLS(int year,
int month,
int dayOfMonth)
Registers a new positive leap second by defining the switch-over-day.
year - proleptic iso yearmonth - gregorian month in range (1-12)dayOfMonth - day of month in range (1-31)IllegalStateException - if support of leap seconds is switched
off by configuration or if the value of system property
"net.time4j.utc.leapseconds.final" is trueIllegalArgumentException - if the new event is not after the
last stored event or if the date is invalidisExtensible(),
isEnabled(),
SUPPRESS_UTC_LEAPSECONDS,
FINAL_UTC_LEAPSECONDSpublic void registerNegativeLS(int year,
int month,
int dayOfMonth)
Registers a new negative leap second by defining the switch-over-day.
year - proleptic iso yearmonth - gregorian month in range (1-12)dayOfMonth - day of month in range (1-31)IllegalStateException - if support of leap seconds is switched
off by configuration or if the value of system property
"net.time4j.utc.leapseconds.final" is trueIllegalArgumentException - if the new event is not after the
last stored event or if the date is invalidisExtensible(),
isEnabled(),
SUPPRESS_UTC_LEAPSECONDS,
FINAL_UTC_LEAPSECONDSpublic boolean supportsNegativeLS()
Queries if negative leap seconds are supported.
true if negative leap seconds are supported
else falseLeapSecondProvider.supportsNegativeLS()public Iterator<LeapSecondEvent> iterator()
Iterates over all leap second events in descending temporal order.
iterator in interface Iterable<LeapSecondEvent>Iterator over all stored leap second events
which enables for-each-supportpublic Stream<LeapSecondEvent> stream()
Creates a stream over all leap second events in descending temporal order.
Stream over all stored leap second events in descending orderpublic int getShift(GregorianDate date)
Yields 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
59 in 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.
date - day of possible leap second event in the last minute0)public int getShift(long utc)
Yields the shift in seconds dependent on if given UTC time point represents a leap second or not.
utc - elapsed SI-seconds relative to UTC epoch
[1972-01-01T00:00:00Z] including leap seconds1, 0, -1 if the argument denotes a positive leap second,
no leap second or a negative leap secondpublic LeapSecondEvent getNextEvent(long utc)
Yields the next leap second event after given UTC time point.
utc - elapsed SI-seconds relative to UTC epoch
[1972-01-01T00:00:00Z] including leap secondsnull if not knownpublic 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.
unixTime - elapsed time in seconds relative to UNIX epoch
[1970-01-01T00:00:00Z] without leap secondsstrip(long)public 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 expression
enhance(strip(val)) != val is true.
utc - elapsed SI-seconds relative to UTC epoch
[1972-01-01T00:00:00Z] including leap secondsenhance(long)public boolean isPositiveLS(long utc)
Queries if given UTC-timestamp represents a registered positive leap second.
utc - elapsed SI-seconds relative to UTC epoch
[1972-01-01T00:00:00Z] including leap secondstrue if the argument represents a registered
positive leap second else falsepublic GregorianDate getDateOfExpiration()
Determines the expiration date of underlying data.
IllegalStateException - if leap seconds are not activatedpublic int compare(LeapSecondEvent o1, LeapSecondEvent o2)
Compares two leap second events by their date in ascending order.
compare in interface Comparator<LeapSecondEvent>o1 - first leap second evento2 - second leap second event-1, 0 or 1 if first event is before,
equal to or later than second eventCopyright © 2014–2017. All rights reserved.