Enum Class TemporalFormat
- All Implemented Interfaces:
Serializable,Comparable<TemporalFormat>,Constable
TemporalAccessor values.
Used by MarshallingContext.Builder.temporalFormat(TemporalFormat),
Marshalled.temporalFormat(),
MarshalledProp.temporalFormat(), and
MarshalledConfig.temporalFormat() to control how
TemporalAccessor values (Instant, LocalDate, LocalDateTime,
LocalTime, OffsetDateTime, OffsetTime, ZonedDateTime, Year,
YearMonth, MonthDay, …) are written to and read from the wire.
The default is DEFAULT which uses the per-subtype default formatter
(e.g. DateTimeFormatter.ISO_INSTANT for Instant, DateTimeFormatter.ISO_LOCAL_DATE
for LocalDate, etc.) — preserving the historical wire output produced before this enum existed.
Numeric formats (MILLIS) emit native numeric wire types on binary serializers
(BSON / CBOR / MsgPack) and bare numbers on text formats. Text formats emit a quoted ISO 8601 string for
every other constant.
Most subtypes implement Temporal, but MonthDay only implements TemporalAccessor.
Format/parse methods accept any TemporalAccessor so that MonthDay round-trips through the
same dispatch path as the Temporal subtypes.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionDateTimeFormatter.BASIC_ISO_DATE:"20111203" .Per-subtype default formatter (the historical wire output).DateTimeFormatter.ISO_DATE_TIME:"2011-12-03T10:15:30+01:00[Europe/Paris]" .DateTimeFormatter.ISO_INSTANT:"2011-12-03T10:15:30Z" .DateTimeFormatter.ISO_LOCAL_DATE:"2011-12-03" .DateTimeFormatter.ISO_LOCAL_DATE_TIME:"2011-12-03T10:15:30" .DateTimeFormatter.ISO_LOCAL_TIME:"10:15:30" .DateTimeFormatter.ISO_OFFSET_DATE:"2011-12-03+01:00" .DateTimeFormatter.ISO_OFFSET_DATE_TIME:"2011-12-03T10:15:30+01:00" .DateTimeFormatter.ISO_OFFSET_TIME:"10:15:30+01:00" .DateTimeFormatter.ISO_ORDINAL_DATE:"2012-337" .DateTimeFormatter.ISO_WEEK_DATE:"2012-W48-6" .Year only — pattern"uuuu":"2012" .Year and month — pattern"uuuu-MM":"2012-12" .DateTimeFormatter.ISO_ZONED_DATE_TIME:"2011-12-03T10:15:30+01:00[Europe/Paris]" .Epoch milliseconds as a numeric value.Sentinel meaning "no value configured" — falls through to the next-higher precedence level.DateTimeFormatter.RFC_1123_DATE_TIME:"Tue, 3 Jun 2008 11:05:30 GMT" . -
Method Summary
Modifier and TypeMethodDescriptionformat(TemporalAccessor value, ZoneId zoneId) Formats the specified value using this format.static booleanisMillisNumeric(Class<? extends TemporalAccessor> c) Returnstrue whenMILLISproduces a numeric wire string for the specified subtype.booleanReturnstrue if this format is numeric on the wire.<T extends TemporalAccessor>
TParses the specified wire value using this format.static TemporalFormatReturns the enum constant of this class with the specified name.static TemporalFormat[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
NOT_SET
Sentinel meaning "no value configured" — falls through to the next-higher precedence level. -
DEFAULT
Per-subtype default formatter (the historical wire output).Uses the ISO formatter most appropriate for each
Temporalsubtype:DateTimeFormatter.ISO_INSTANTforInstant,DateTimeFormatter.ISO_LOCAL_DATEforLocalDate,DateTimeFormatter.ISO_OFFSET_DATE_TIMEforZonedDateTime/OffsetDateTime, etc. -
BASIC_ISO_DATE
DateTimeFormatter.BASIC_ISO_DATE:"20111203" . -
ISO_DATE
-
ISO_DATE_TIME
DateTimeFormatter.ISO_DATE_TIME:"2011-12-03T10:15:30+01:00[Europe/Paris]" . -
ISO_INSTANT
DateTimeFormatter.ISO_INSTANT:"2011-12-03T10:15:30Z" . -
ISO_LOCAL_DATE
DateTimeFormatter.ISO_LOCAL_DATE:"2011-12-03" . -
ISO_LOCAL_DATE_TIME
DateTimeFormatter.ISO_LOCAL_DATE_TIME:"2011-12-03T10:15:30" . -
ISO_LOCAL_TIME
DateTimeFormatter.ISO_LOCAL_TIME:"10:15:30" . -
ISO_OFFSET_DATE
DateTimeFormatter.ISO_OFFSET_DATE:"2011-12-03+01:00" . -
ISO_OFFSET_DATE_TIME
DateTimeFormatter.ISO_OFFSET_DATE_TIME:"2011-12-03T10:15:30+01:00" . -
ISO_OFFSET_TIME
DateTimeFormatter.ISO_OFFSET_TIME:"10:15:30+01:00" . -
ISO_ORDINAL_DATE
DateTimeFormatter.ISO_ORDINAL_DATE:"2012-337" . -
ISO_TIME
-
ISO_WEEK_DATE
DateTimeFormatter.ISO_WEEK_DATE:"2012-W48-6" . -
ISO_YEAR
Year only — pattern"uuuu":"2012" . -
ISO_YEAR_MONTH
Year and month — pattern"uuuu-MM":"2012-12" . -
ISO_ZONED_DATE_TIME
DateTimeFormatter.ISO_ZONED_DATE_TIME:"2011-12-03T10:15:30+01:00[Europe/Paris]" . -
RFC_1123_DATE_TIME
DateTimeFormatter.RFC_1123_DATE_TIME:"Tue, 3 Jun 2008 11:05:30 GMT" . -
MILLIS
Epoch milliseconds as a numeric value.Emitted as a native int64 by binary serializers (BSON / CBOR / MsgPack) and as a bare integer literal by text serializers.
Per-subtype semantics (midnight UTC for non-instant subtypes):
Instant—instant.toEpochMilli().OffsetDateTime,ZonedDateTime—value.toInstant().toEpochMilli().LocalDateTime—ldt.toInstant(ZoneOffset.UTC).toEpochMilli().LocalDate—ld.atStartOfDay(ZoneOffset.UTC).toInstant().toEpochMilli()(midnight UTC).YearMonth— first day of the month at midnight UTC.Year— January 1 at midnight UTC.LocalTime,OffsetTime,MonthDay— fall back to the type'sDEFAULT(ISO string form) because no defensible epoch-millis interpretation exists without an associated date/year. SeeisMillisNumeric(Class)for the canonical decision predicate.
The asymmetry is intentional: a configured
MILLISsetting silently produces a string forLocalTime/OffsetTime/MonthDayand a number for every other subtype.
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-
isMillisNumeric
Returnstrue whenMILLISproduces a numeric wire string for the specified subtype.Single source of truth for the
MILLISwire-type decision shared byformat(java.time.temporal.TemporalAccessor, java.time.ZoneId)and the marshalling-sidetemporalSwap/temporalAccessorSwapfactories. The helper exists so the swap-sideLong.valueOf(s)coercion only fires whenformat(java.time.temporal.TemporalAccessor, java.time.ZoneId)actually emitted a numeric string — a mismatch on either side is aNumberFormatExceptionwaiting to happen.Returns
false forLocalTime,OffsetTime, andMonthDay— these subtypes have no defensible epoch-millis interpretation, soformat(java.time.temporal.TemporalAccessor, java.time.ZoneId)'sMILLISbranch falls back toDEFAULT(an ISO string) for them and the swap must keep the value as a string.- Parameters:
c- TheTemporalAccessorsubtype to query.- Returns:
true ifformat(java.time.temporal.TemporalAccessor, java.time.ZoneId)emits aLong-parseable numeric string forcunderMILLIS;false if theMILLISbranch falls back to ISO string.
-
format
Formats the specified value using this format.- Parameters:
value- The value to format. Can benull (returnsnull ).zoneId- The default zone id used for time-only / unzoned values.- Returns:
- The formatted string, or
null ifvalueisnull . ForMILLISthis is a numeric string for every subtype exceptLocalTime,OffsetTime, andMonthDay(which fall back to theirDEFAULTISO string form).
-
parse
Parses the specified wire value using this format.- Type Parameters:
T- The temporal subtype.- Parameters:
value- The wire value. Can benull or blank (returnsnull ).targetType- The target temporal subtype. Must be either aTemporalsubtype orMonthDay(the only non-TemporalTemporalAccessorthe JDK currently exposes).zoneId- The default zone id used for time-only / unzoned values.- Returns:
- The parsed value, or
null ifvalueisnull or blank.
-
isNumeric
Returnstrue if this format is numeric on the wire.- Returns:
true if this format emits a numeric wire value.
-