Class TemporalType<S,T>
- Type Parameters:
S- source type in other libraryT- target type in Time4J
- All Implemented Interfaces:
Converter<S,T>
- Direct Known Subclasses:
JDBCAdapter,XMLAdapter
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.
- Since:
- 2.0
- Author:
- Meno Hochschild
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic TemporalType<Clock,TimeSource<?>>Bridge between the JSR-310-classjava.time.Clockand the interfacenet.time4j.base.TimeSource.static TemporalType<Instant,Moment>Bridge between the JSR-310-classjava.time.Instantand the classMoment.static TemporalType<Calendar,ZonalDateTime>Bridge between a traditional Java calendar of typejava.util.Calendarand the classZonalDateTime.static TemporalType<Date,Moment>Bridge between a traditional Java timestamp of typejava.util.Dateand the classMoment.static TemporalType<TimeZone,Timezone>Bridge between a traditional Java timezone of typejava.util.TimeZoneand the classnet.time4j.tz.Timezone.static TemporalType<LocalDate,PlainDate>Bridge between the JSR-310-classjava.time.LocalDateand the classPlainDate.static TemporalType<LocalDateTime,PlainTimestamp>Bridge between the JSR-310-classjava.time.LocalDateTimeand the classPlainTimestamp.static TemporalType<LocalTime,PlainTime>Bridge between the JSR-310-classjava.time.LocalTimeand the classPlainTime.static TemporalType<Long,Moment>Bridge between a traditional Java timestamp as count of milliseconds since UNIX-epoch and the classMoment.static TemporalType<Duration,Duration<ClockUnit>>Bridge between the JSR-310-classjava.time.Durationand the classnet.time4j.Duration.static TemporalType<Period,Duration<CalendarUnit>>Bridge between the JSR-310-classjava.time.Periodand the classnet.time4j.Duration.static TemporalType<ZonedDateTime,ZonalDateTime>Bridge between the JSR-310-classjava.time.ZonedDateTimeand the classZonalDateTime. -
Method Summary
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.time4j.engine.Converter
getSourceType
-
Field Details
-
JAVA_UTIL_DATE
Bridge between a traditional Java timestamp of type
java.util.Dateand the classMoment.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
- Since:
- 2.0
-
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
- Since:
- 2.0
-
JAVA_UTIL_CALENDAR
Bridge between a traditional Java calendar of type
java.util.Calendarand the classZonalDateTime.The conversion tries to keep the instant and zone data involved. A change of the local timestamp part of
Calendaris possible, however. This concerns the conversion of any non-gregorian calendar.- Since:
- 3.37/4.32
-
JAVA_UTIL_TIMEZONE
Bridge between a traditional Java timezone of type
java.util.TimeZoneand the classnet.time4j.tz.Timezone.The conversion tries to keep the data and rules of the zone to be converted.
- Since:
- 3.37/4.32
-
LOCAL_DATE
Bridge between the JSR-310-class
java.time.LocalDateand the classPlainDate.The conversion is always exact. Example:
PlainDate date = TemporalType.LOCAL_DATE.translate(LocalDate.of(2015, 4, 30)); System.out.println(date); // output: 2015-04-30
- Since:
- 4.0
-
LOCAL_TIME
Bridge between the JSR-310-class
java.time.LocalTimeand the classPlainTime.The conversion is exact with the exception of midnight at end of day (T24:00). The special time T24:00 will be mapped to 00:00 in class
LocalTime. Example:PlainTime time = TemporalType.LOCAL_TIME.translate(LocalTime.of(17, 45)); System.out.println(time); // output: T17:45
- Since:
- 4.0
-
LOCAL_DATE_TIME
Bridge between the JSR-310-class
java.time.LocalDateTimeand the classPlainTimestamp.The conversion is always exact. Example:
PlainTimestamp tsp = TemporalType.LOCAL_DATE_TIME.translate(LocalDateTime.of(2015, 4, 30, 17, 45)); System.out.println(tsp); // output: 2015-04-30T17:45
- Since:
- 4.0
-
INSTANT
Bridge between the JSR-310-class
java.time.Instantand the classMoment.The conversion is usually exact. However, leap seconds will always be ignored. The outer value range limits of the class
Momentare a tiny bit smaller. Example:Moment moment = TemporalType.INSTANT.translate(Instant.ofEpochSecond(86401, 450_000_000)); System.out.println(moment); // output: 1970-01-02T00:00:01,450000000Z
- Since:
- 4.0
-
ZONED_DATE_TIME
Bridge between the JSR-310-class
java.time.ZonedDateTimeand the classZonalDateTime.The conversion is usually exact. However, leap seconds will always be ignored. The outer value range limits of the class
ZonalDateTimeare a tiny bit different. Example:Moment moment = TemporalType.ZONED_DATE_TIME.translate(Instant.ofEpochSecond(86401, 450_000_000)); System.out.println(moment); // Ausgabe: 1970-01-02T00:00:01,450000000Z
- Since:
- 4.0
-
THREETEN_DURATION
Bridge between the JSR-310-class
java.time.Durationand the classnet.time4j.Duration.The conversion is usually exact but will always perform a normalization on the side of Time4J. Example:
Duration<ClockUnit> duration = TemporalType.THREETEN_DURATION.translate(java.time.Duration.ofSeconds(65)); System.out.println(duration); // output: PT1M5S
- Since:
- 4.0
-
THREETEN_PERIOD
Bridge between the JSR-310-class
java.time.Periodand the classnet.time4j.Duration.Note that mixed signs in original period like "P1M-30D" will be rejected by Time4J. This is a normalizing conversion. Example for a correct input:
Duration<CalendarUnit> duration = TemporalType.THREETEN_PERIOD.translate(Period.of(3, 13, 45)); System.out.println(duration); // output: P4Y1M45D
Note: The algorithm to apply a negative duration is slightly different. Example:
System.out.println( LocalDate.of(2015, 7, 1).minus(Period.of(0, 1, 1))); // 2015-05-31 System.out.println( PlainDate.of(2015, 7, 1).minus(Duration.ofCalendarUnits(0, 1, 1))); // 2015-05-30- Since:
- 4.0
-
CLOCK
Bridge between the JSR-310-class
java.time.Clockand the interfacenet.time4j.base.TimeSource.The conversion will always ignore leap seconds and initially use
ZoneId.systemDefault().- Since:
- 4.0
-
-
Method Details
-
translate
Converts the external type to a type in Time4J.
- Specified by:
translatein interfaceConverter<S,T>- Parameters:
source- external object- Returns:
- translated Time4J-object
- Throws:
ArithmeticException- in case of numerical overflowChronoException- if conversion fails- Since:
- 2.0
-
from
Converts the Time4J-type to an external type.
- Specified by:
fromin interfaceConverter<S,T>- Parameters:
time4j- Time4J-object- Returns:
- translated object of external type
- Throws:
ArithmeticException- in case of numerical overflowChronoException- if conversion fails- Since:
- 2.0
-