S - source type in other libraryT - target type in Time4Jpublic abstract class TemporalType<S,T> extends Object
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 TemporalType<Date,Moment> |
JAVA_UTIL_DATE
Bridge between a traditional Java timestamp of type
java.util.Date and the class Moment. |
static TemporalType<Long,Moment> |
MILLIS_SINCE_UNIX
Bridge between a traditional Java timestamp as count of milliseconds
since UNIX-epoch and the class
Moment. |
static TemporalType<Date,PlainDate> |
SQL_DATE
Bridge between a JDBC-Date and the class
PlainDate. |
static TemporalType<Time,PlainTime> |
SQL_TIME
Bridge between a JDBC-Time and the class
PlainTime. |
static TemporalType<Timestamp,PlainTimestamp> |
SQL_TIMESTAMP
Bridge between a JDBC-Timestamp and the class
PlainTimestamp. |
static TemporalType<XMLGregorianCalendar,PlainDate> |
XML_DATE
Bridge between a XML-date according to
xsd:date
and the type PlainDate. |
static TemporalType<XMLGregorianCalendar,PlainTimestamp> |
XML_DATE_TIME
Bridge between a XML-timestamp according to
xsd:dateTime
(without timezone-offset) and the type PlainTimestamp. |
static TemporalType<XMLGregorianCalendar,ZonalMoment> |
XML_DATE_TIME_OFFSET
Bridge between a XML-timestamp according to
xsd:dateTime
inclusive timezone-offset and the type ZonalMoment. |
static TemporalType<Duration,Duration<IsoUnit>> |
XML_DURATION
Bridge between a XML-duration according to
xsd:duration
and the Time4J-type Duration. |
static TemporalType<XMLGregorianCalendar,PlainTime> |
XML_TIME
Bridge between a XML-time according to
xsd:time
and the type PlainTime. |
public static final TemporalType<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 into 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 = TemporalType.JAVA_UTIL_DATE.translate(instant); System.out.println(ut); // output: 1970-01-02T00:00:01Z
public static final TemporalType<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 into account any UTC-leapseconds.
The supported value range is smaller than in the class Moment.
Example:
long instant = 86401 * 1000L; Moment ut = TemporalType.MILLIS_SINCE_UNIX.translate(instant); System.out.println(ut); // output: 1970-01-02T00:00:01Z
public static final TemporalType<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 into 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 = TemporalType.SQL_DATE.translate(sqlValue); System.out.println(date); // output: 1970-01-02
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 TemporalType<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 into 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 = TemporalType.SQL_TIME.translate(sqlValue); System.out.println(time); // output: T12:00:00
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 TemporalType<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 into 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 = TemporalType.SQL_TIMESTAMP.translate(sqlValue); System.out.println(ts); // output: 1970-01-02T00:00:01,000000001
public static final TemporalType<XMLGregorianCalendar,PlainDate> XML_DATE
Bridge between a XML-date according to xsd:date
and the type PlainDate.
Example:
XMLGregorianCalendar xmlGregCal =
DatatypeFactory.newInstance().newXMLGregorianCalendarDate(
2014, 2, 28, 60); // here with optional offset
PlainDate date = TemporalType.XML_DATE.translate(xmlGregCal);
System.out.println(date);
// output: 2014-02-28
public static final TemporalType<XMLGregorianCalendar,PlainTime> XML_TIME
Bridge between a XML-time according to xsd:time
and the type PlainTime.
Example:
XMLGregorianCalendar xmlGregCal =
DatatypeFactory.newInstance().newXMLGregorianCalendarTime(
21, 45, 30, 0, 60); // here with optional offset
PlainTime time = TemporalType.XML_TIME.translate(xmlGregCal);
System.out.println(time);
// output: T21:45:30
public static final TemporalType<XMLGregorianCalendar,PlainTimestamp> XML_DATE_TIME
Bridge between a XML-timestamp according to xsd:dateTime
(without timezone-offset) and the type PlainTimestamp.
Example:
XMLGregorianCalendar xmlGregCal =
DatatypeFactory.newInstance().newXMLGregorianCalendar(
2014, 2, 28, 14, 45, 30, 0, 60);
PlainTimestamp tsp = TemporalType.XML_DATE_TIME.translate(xmlGregCal);
System.out.println(tsp);
// output: 2014-02-28T14:45:30
public static final TemporalType<XMLGregorianCalendar,ZonalMoment> XML_DATE_TIME_OFFSET
Bridge between a XML-timestamp according to xsd:dateTime
inclusive timezone-offset and the type ZonalMoment.
Example:
XMLGregorianCalendar xmlGregCal =
DatatypeFactory.newInstance().newXMLGregorianCalendar(
2014, 2, 28, 14, 45, 30, 0, 60);
ZonalMoment zm = TemporalType.XML_DATE_TIME_OFFSET.translate(xmlGregCal);
System.out.println(zm.print(Iso8601Format.EXTENDED_DATE_TIME_OFFSET));
// output: 2014-02-28T14:45:30+01:00
public static final TemporalType<Duration,Duration<IsoUnit>> XML_DURATION
Bridge between a XML-duration according to xsd:duration
and the Time4J-type Duration.
public abstract T translate(S source)
Converts the external type to a type in Time4J.
source - external objectArithmeticException - in case of numerical overflowChronoException - if conversion failspublic abstract S from(T time4j)
Converts the Time4J-type to an external type.
time4j - Time4J-objectArithmeticException - in case of numerical overflowChronoException - if conversion failsCopyright © 2014. All rights reserved.