S - source type in other libraryT - target type in Time4Jpublic abstract class TemporalType<S,T> extends Object implements Converter<S,T>
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<Clock,TimeSource<?>> |
CLOCK
Bridge between the JSR-310-class
java.time.Clock and
the interface net.time4j.base.TimeSource. |
static TemporalType<Instant,Moment> |
INSTANT
Bridge between the JSR-310-class
java.time.Instant and
the class Moment. |
static TemporalType<Calendar,ZonalDateTime> |
JAVA_UTIL_CALENDAR
Bridge between a traditional Java calendar of type
java.util.Calendar and the class ZonalDateTime. |
static TemporalType<Date,Moment> |
JAVA_UTIL_DATE
Bridge between a traditional Java timestamp of type
java.util.Date and the class Moment. |
static TemporalType<TimeZone,Timezone> |
JAVA_UTIL_TIMEZONE
Bridge between a traditional Java timezone of type
java.util.TimeZone and the class net.time4j.tz.Timezone. |
static TemporalType<LocalDate,PlainDate> |
LOCAL_DATE
Bridge between the JSR-310-class
java.time.LocalDate and
the class PlainDate. |
static TemporalType<LocalDateTime,PlainTimestamp> |
LOCAL_DATE_TIME
Bridge between the JSR-310-class
java.time.LocalDateTime and
the class PlainTimestamp. |
static TemporalType<LocalTime,PlainTime> |
LOCAL_TIME
Bridge between the JSR-310-class
java.time.LocalTime and
the class PlainTime. |
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<Duration,Duration<ClockUnit>> |
THREETEN_DURATION
Bridge between the JSR-310-class
java.time.Duration and
the class net.time4j.Duration. |
static TemporalType<Period,Duration<CalendarUnit>> |
THREETEN_PERIOD
Bridge between the JSR-310-class
java.time.Period and
the class net.time4j.Duration. |
static TemporalType<ZonedDateTime,ZonalDateTime> |
ZONED_DATE_TIME
Bridge between the JSR-310-class
java.time.ZonedDateTime and
the class ZonalDateTime. |
| Modifier and Type | Method and Description |
|---|---|
abstract S |
from(T time4j)
Converts the Time4J-type to an external type.
|
abstract T |
translate(S source)
Converts the external type to a type in Time4J.
|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetSourceTypepublic 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<Calendar,ZonalDateTime> JAVA_UTIL_CALENDAR
Bridge between a traditional Java calendar of type
java.util.Calendar and the class ZonalDateTime.
The conversion tries to keep the instant and zone data involved. A change
of the local timestamp part of Calendar is possible, however. This
concerns the conversion of any non-gregorian calendar.
public static final TemporalType<TimeZone,Timezone> JAVA_UTIL_TIMEZONE
Bridge between a traditional Java timezone of type
java.util.TimeZone and the class net.time4j.tz.Timezone.
The conversion tries to keep the data and rules of the zone to be converted.
public static final TemporalType<LocalDate,PlainDate> LOCAL_DATE
Bridge between the JSR-310-class java.time.LocalDate and
the class PlainDate.
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
public static final TemporalType<LocalTime,PlainTime> LOCAL_TIME
Bridge between the JSR-310-class java.time.LocalTime and
the class PlainTime.
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
public static final TemporalType<LocalDateTime,PlainTimestamp> LOCAL_DATE_TIME
Bridge between the JSR-310-class java.time.LocalDateTime and
the class PlainTimestamp.
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
public static final TemporalType<Instant,Moment> INSTANT
Bridge between the JSR-310-class java.time.Instant and
the class Moment.
The conversion is usually exact. However, leap seconds will always be ignored. The
outer value range limits of the class Moment are 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
public static final TemporalType<ZonedDateTime,ZonalDateTime> ZONED_DATE_TIME
Bridge between the JSR-310-class java.time.ZonedDateTime and
the class ZonalDateTime.
The conversion is usually exact. However, leap seconds will always be ignored. The
outer value range limits of the class ZonalDateTime are 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
public static final TemporalType<Duration,Duration<ClockUnit>> THREETEN_DURATION
Bridge between the JSR-310-class java.time.Duration and
the class net.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
public static final TemporalType<Period,Duration<CalendarUnit>> THREETEN_PERIOD
Bridge between the JSR-310-class java.time.Period and
the class net.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
public static final TemporalType<Clock,TimeSource<?>> CLOCK
Bridge between the JSR-310-class java.time.Clock and
the interface net.time4j.base.TimeSource.
The conversion will always ignore leap seconds and initially use ZoneId.systemDefault().
public abstract T translate(S source)
Converts the external type to a type in Time4J.
translate in interface Converter<S,T>source - external objectArithmeticException - in case of numerical overflowChronoException - if conversion failspublic abstract S from(T time4j)
Converts the Time4J-type to an external type.
from in interface Converter<S,T>time4j - Time4J-objectArithmeticException - in case of numerical overflowChronoException - if conversion failsCopyright © 2014–2017. All rights reserved.