APIdia Launch Partner
Top Description Fields Constructors Methods
java.time.format

pack-priv final Class DateTimePrintContext

extends Object
Class Inheritance
Static Imports
java.time.temporal.ChronoField.EPOCH_DAY, .ChronoField.INSTANT_SECONDS, .ChronoField.OFFSET_SECONDS

Context object used during date and time printing.

This class provides a single wrapper to items used in the format.

Since
1.8

Field Summary

Modifier and TypeField and Description
private final DateTimeFormatter
formatter

The formatter, not null.

private final TemporalAccessor
temporal

The temporal being output.

Constructor Summary

AccessConstructor and Description
pack-priv
DateTimePrintContext(TemporalAccessor
the temporal object being output, not null
temporal
,
DateTimeFormatter
the formatter controlling the format, not null
formatter
)

Creates a new instance of the context.

Method Summary

Modifier and TypeMethod and Description
private static TemporalAccessor

Returns:

the adjusted temporal, or the original if no overrides are present in the formatter
adjust
(final TemporalAccessor
the temporal object to adjust, not null
temporal
,
DateTimeFormatter
the formatter providing potential chronology and time-zone overrides
formatter
)

Adjusts the given TemporalAccessor using chronology and time-zone from a formatter if present.

private static TemporalAccessor

Returns:

adjusted temporal accessor combining original fields with overrides
adjustSlow
(TemporalAccessor
the original temporal object to adjust, not null
temporal
,
ZoneId
override time-zone (nullable)
overrideZone
,
ZoneId
original time-zone from temporal (nullable)
temporalZone
,
Chronology
override chronology (nullable)
overrideChrono
,
Chronology
precomputed effective chronology (override if present, otherwise temporal's chronology)
effectiveChrono
,
Chronology
original chronology from temporal (nullable)
temporalChrono
)

Internal helper method to adjust temporal fields using override chronology and time-zone in complex cases.

private static TemporalAccessor

Returns:

the adjusted temporal, which may be the original object if no effective changes were made, or a new object with the applied overrides
adjustWithOverride
(TemporalAccessor
the temporal object to adjust, not null
temporal
,
Chronology
the chronology to override (null retains the original chronology)
overrideChrono
,
ZoneId
the time-zone to override (null retains the original time-zone)
overrideZone
)

Adjusts the given TemporalAccessor with optional overriding chronology and time-zone.

pack-priv DecimalStyle

Returns:

the DecimalStyle, not null
getDecimalStyle
()

Gets the DecimalStyle.

pack-priv Locale

Returns:

the locale, not null
getLocale
()

Gets the locale.

pack-priv TemporalAccessor

Returns:

the temporal object, not null
getTemporal
()

Gets the temporal object being output.

pack-priv <R> R

Returns:

the result, null if not found and optional is true
getValue
(TemporalQuery<R>
the query to use, not null
query
,
boolean
whether the query is optional, true if the query may be missing
optional
)

Gets a value using a query.

pack-priv Long

Returns:

the value, null if not found and optional is true
getValue
(TemporalField
the field to find, not null
field
,
boolean
whether the field is optional, true if the field may be missing
optional
)

Gets the value of the specified field.

public String

Returns:

a string representation of the context, not null
toString
()

Overrides java.lang.Object.toString.

Returns a string version of the context for debugging.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

formatterback to summary
private final DateTimeFormatter formatter

The formatter, not null.

temporalback to summary
private final TemporalAccessor temporal

The temporal being output.

Constructor Detail

DateTimePrintContextback to summary
pack-priv DateTimePrintContext(TemporalAccessor temporal, DateTimeFormatter formatter)

Creates a new instance of the context.

Parameters
temporal:TemporalAccessor

the temporal object being output, not null

formatter:DateTimeFormatter

the formatter controlling the format, not null

Method Detail

adjustback to summary
private static TemporalAccessor adjust(final TemporalAccessor temporal, DateTimeFormatter formatter)

Adjusts the given TemporalAccessor using chronology and time-zone from a formatter if present.

This method serves as an optimization front-end that checks for non-null overrides in the formatter. If neither chronology nor time-zone is specified in the formatter, returns the original temporal unchanged. Otherwise, delegates to the core adjustment method adjustWithOverride(TemporalAccessor, Chronology, ZoneId).

Implementation Note

Optimizes for the common case where formatters don't specify chronology/time-zone by avoiding unnecessary processing. Most formatters have null for these properties.

Parameters
temporal:TemporalAccessor

the temporal object to adjust, not null

formatter:DateTimeFormatter

the formatter providing potential chronology and time-zone overrides

Returns:TemporalAccessor

the adjusted temporal, or the original if no overrides are present in the formatter

adjustSlowback to summary
private static TemporalAccessor adjustSlow(TemporalAccessor temporal, ZoneId overrideZone, ZoneId temporalZone, Chronology overrideChrono, Chronology effectiveChrono, Chronology temporalChrono)

Internal helper method to adjust temporal fields using override chronology and time-zone in complex cases.

Handles non-instant temporal objects by creating a delegate TemporalAccessor that combines:

  • The original temporal's time-related fields
  • Date fields converted to the effective chronology (if available)
  • Override zone/chronology information for temporal queries
Performs critical validation before processing:
  • Rejects offset changes for non-instant temporal objects with existing offsets
  • Verifies date field integrity when applying chronology overrides to partial dates

Implementation Note

Creates an anonymous temporal accessor that:

  • Delegates time-based fields to original temporal
  • Uses converted date fields when chronology override is applied
  • Responds to chronology/zone queries with effective values
  • Preserves precision queries from original temporal
Parameters
temporal:TemporalAccessor

the original temporal object to adjust, not null

overrideZone:ZoneId

override time-zone (nullable)

temporalZone:ZoneId

original time-zone from temporal (nullable)

overrideChrono:Chronology

override chronology (nullable)

effectiveChrono:Chronology

precomputed effective chronology (override if present, otherwise temporal's chronology)

temporalChrono:Chronology

original chronology from temporal (nullable)

Returns:TemporalAccessor

adjusted temporal accessor combining original fields with overrides

Exceptions
DateTimeException:
if:
  • Applying a ZoneOffset override to a temporal with conflicting existing offset that doesn't represent an instant
  • Applying chronology override to temporal with partial date fields
adjustWithOverrideback to summary
private static TemporalAccessor adjustWithOverride(TemporalAccessor temporal, Chronology overrideChrono, ZoneId overrideZone)

Adjusts the given TemporalAccessor with optional overriding chronology and time-zone.

This method minimizes changes by returning the original temporal if the override parameters are either null or equivalent to those already present in the temporal. When overrides are applied:

  • If a time-zone override is provided and the temporal supports ChronoField#INSTANT_SECONDS, the result is a zoned date-time using the override time-zone and chronology (defaulting to ISO if not overridden).
  • Other cases (including partial date-times or mixed chronology/time-zone changes) are delegated to a secondary adjustment method.

Implementation Note

Optimizes for common cases where overrides are identical to existing values or where instant-based temporals can be directly converted with a time-zone.

Parameters
temporal:TemporalAccessor

the temporal object to adjust, not null

overrideChrono:Chronology

the chronology to override (null retains the original chronology)

overrideZone:ZoneId

the time-zone to override (null retains the original time-zone)

Returns:TemporalAccessor

the adjusted temporal, which may be the original object if no effective changes were made, or a new object with the applied overrides

getDecimalStyleback to summary
pack-priv DecimalStyle getDecimalStyle()

Gets the DecimalStyle.

The DecimalStyle controls the localization of numeric output.

Returns:DecimalStyle

the DecimalStyle, not null

getLocaleback to summary
pack-priv Locale getLocale()

Gets the locale.

This locale is used to control localization in the format output except where localization is controlled by the DecimalStyle.

Returns:Locale

the locale, not null

getTemporalback to summary
pack-priv TemporalAccessor getTemporal()

Gets the temporal object being output.

Returns:TemporalAccessor

the temporal object, not null

getValueback to summary
pack-priv <R> R getValue(TemporalQuery<R> query, boolean optional)

Gets a value using a query.

Parameters
query:TemporalQuery<R>

the query to use, not null

optional:boolean

whether the query is optional, true if the query may be missing

Returns:R

the result, null if not found and optional is true

Exceptions
DateTimeException:
if the type is not available and the section is not optional
getValueback to summary
pack-priv Long getValue(TemporalField field, boolean optional)

Gets the value of the specified field.

This will return the value for the specified field.

Parameters
field:TemporalField

the field to find, not null

optional:boolean

whether the field is optional, true if the field may be missing

Returns:Long

the value, null if not found and optional is true

Exceptions
DateTimeException:
if the field is not available and the section is not optional
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string version of the context for debugging.

Returns:String

a string representation of the context, not null

Annotations
@Override