S - source type in other libraryT - target type in Time4Jpublic class TemporalTypes<S extends Comparable<?>,T extends ChronoEntity<T>> extends BasicElement<S>
Serves as bridge to temporal types of JDK or other date and time libraries.
All singleton instances are defined as static constants and are immutable.
| Modifier and Type | Field and Description |
|---|---|
static TemporalTypes<Date,Moment> |
JAVA_UTIL_DATE
Bridge between a traditional Java timestamp of type
java.util.Date and the class Moment. |
static TemporalTypes<Long,Moment> |
MILLIS_SINCE_UNIX
Bridge between a traditional Java timestamp as count of milliseconds
since UNIX-epoch and the class
Moment. |
static TemporalTypes<Date,PlainDate> |
SQL_DATE
Bridge between a JDBC-Date and the class
PlainDate. |
static TemporalTypes<Time,PlainTime> |
SQL_TIME
Bridge between a JDBC-Time and the class
PlainTime. |
static TemporalTypes<Timestamp,PlainTimestamp> |
SQL_TIMESTAMP
Bridge between a JDBC-Timestamp and the class
PlainTimestamp. |
| Modifier and Type | Method and Description |
|---|---|
int |
compare(ChronoEntity<?> o1,
ChronoEntity<?> o2)
Applies an element-orientated sorting of any chronological
entities.
|
S |
getDefaultMaximum()
Returns the default maximum of this element which is not dependent
on the chronological context.
|
S |
getDefaultMinimum()
Returns the default minimum of this element which is not dependent
on the chronological context.
|
Class<S> |
getType()
Yields the reified value type.
|
boolean |
isDateElement()
Queries if this element represents a calendar date element.
|
boolean |
isTimeElement()
Queries if this element represents a wall time element.
|
T |
transform(S value)
Transforms the given temporal value of the JDK or external library to
a Time4J-type.
|
public static final TemporalTypes<Date,Moment> JAVA_UTIL_DATE
Bridge between a traditional Java timestamp of type
java.util.Date and the class Moment.
The conversion does not take in account any UTC-leapseconds. The
supported value range is smaller than in the class
Moment. Example:
java.util.Date instant = new java.util.Date(86401 * 1000);
Moment ut = TemporalTypes.JAVA_UTIL_DATE.transform(instant);
System.out.println(
ut.get(TemporalTypes.JAVA_UTIL_DATE).equals(instant));
// output: true
public static final TemporalTypes<Long,Moment> MILLIS_SINCE_UNIX
Bridge between a traditional Java timestamp as count of milliseconds
since UNIX-epoch and the class Moment.
The conversion does not take in account any UTC-leapseconds. The
supported value range is smaller than in the class
Moment. Example:
long instant = 86401 * 1000L; Moment ut = TemporalTypes.MILLIS_SINCE_UNIX.transform(instant); System.out.println(ut); // output: 1970-01-02T00:00:01Z
public static final TemporalTypes<Date,PlainDate> SQL_DATE
Bridge between a JDBC-Date and the class PlainDate.
If the system property "net.time4j.sql.utc.conversion" is set to the value "true" then the conversion will not take in account the system timezone anticipating that a SQL-DATE was created without any timezone calculation on the server side, too. That is more or less the case if UTC is the default timezone on the application server.
Example (UTC as default timezone):
java.sql.Date sqlValue = new java.sql.Date(86400 * 1000);
PlainDate date =
TemporalTypes.SQL_DATE.transform(sqlValue); // 1970-01-02
System.out.println(
date.get(TemporalTypes.SQL_DATE).equals(sqlValue));
// output: true
Note: The conversion is only possible if a date
has a year in the range 1900-9999 because else a JDBC-compatible
database cannot store the date per SQL-specification. It is strongly
recommended to interprete a SQL-DATE only as abstract JDBC object
because its text output via java.sql.Date.toString()-method
is not reliable (dependency on the gregorian-julian cutover day
+ possible timezone side effects). The concrete formatting can be
done by Time4J for example via PlainDate.toString() or
a suitable ChronoFormatter.
public static final TemporalTypes<Time,PlainTime> SQL_TIME
Bridge between a JDBC-Time and the class PlainTime.
If the system property "net.time4j.sql.utc.conversion" is set to the value "true" then the conversion will NOT take in account the system timezone anticipating that a SQL-DATE was created without any timezone calculation on the server side, too. That is more or less the case if UTC is the default timezone on the application server.
Example (UTC as default timezone):
java.sql.Time sqlValue = new java.sql.Time(43200 * 1000);
PlainTime time =
TemporalTypes.SQL_TIME.transform(sqlValue); // T12:00:00
System.out.println(
time.get(TemporalTypes.SQL_TIME).equals(sqlValue));
// output: true
Note: The conversion only occurs in millisecond
precision at best not in in nanosecond precision so there is possible
loss of data. Furthermore, the text output via the method
java.sql.Time.toString() can be misinterpreted by timezone
side effects. Concrete text output should be done by Time4J.
public static final TemporalTypes<Timestamp,PlainTimestamp> SQL_TIMESTAMP
Bridge between a JDBC-Timestamp and the class
PlainTimestamp.
If the system property "net.time4j.sql.utc.conversion" is set to the value "true" then the conversion will NOT take in account the system timezone anticipating that a SQL-DATE was created without any timezone calculation on the server side, too. That is more or less the case if UTC is the default timezone on the application server.
Example (UTC as default timezone):
java.sql.Timestamp sqlValue = new java.sql.Timestamp(86401 * 1000);
sqlValue.setNanos(1);
PlainTimestamp ts = // 1970-01-02T00:00:01,000000001
TemporalTypes.SQL_TIMESTAMP.transform(sqlValue);
System.out.println(
ts.get(TemporalTypes.SQL_TIMESTAMP).equals(sqlValue));
// output: true
public Class<S> getType()
ChronoElementYields the reified value type.
public T transform(S value)
Transforms the given temporal value of the JDK or external library to a Time4J-type.
The reverse conversion can simply be done by the expression
time4jType.get(TemporalTypes.XYZ). Example:
java.sql.Date sqlValue = new java.sql.Date(86400 * 1000); PlainDate date = TemporalTypes.SQL_DATE.transform(sqlValue); System.out.println(date); // output: 1970-01-02
value - datetime value to be transformedpublic int compare(ChronoEntity<?> o1, ChronoEntity<?> o2)
ChronoElementApplies an element-orientated sorting of any chronological entities.
The value type V is usually a subtype of the interface
Comparable so that this method will usually be based on
the expression o1.get(this).compareTo(o2.get(this)). In
other words, this method compares the element values of given
chronological entities. It is even permitted to compare entities
of different chronological types as long as the entities both
support this element.
It should be noted however that a element value comparison does often not induce any temporal (complete) order. Counter examples are the year of gregorian BC-era (reversed temporal order before Jesu birth) or the clock display of hours (12 is indeed the begin at midnight).
o1 - the first object to be comparedo2 - the second object to be comparedpublic S getDefaultMinimum()
ChronoElementReturns the default minimum of this element which is not dependent on the chronological context.
Note: This minimum does not necessarily define a minimum for all possible circumstances but only the default minimum under normal conditions such that the default minimum always exists and can be used as prototypical value. An example is the start of day which is usually midnight in ISO-8601 and can only deviate in specialized timezone context.
ChronoElement.getDefaultMaximum()public S getDefaultMaximum()
ChronoElementReturns the default maximum of this element which is not dependent on the chronological context.
Note: This maximum does not necessarily define a maximum for all
possible circumstances but only the default maximum under normal
conditions. An example is the second of minute whose default maximum
is 59 while the largest maximum can be 60 in context
of UTC-leapseconds.
ChronoElement.getDefaultMinimum()public boolean isDateElement()
ChronoElementQueries if this element represents a calendar date element.
ChronoElement.isTimeElement()public boolean isTimeElement()
ChronoElementQueries if this element represents a wall time element.
ChronoElement.isDateElement()Copyright © 2014. All rights reserved.