Home Reference Source
import {TemporalAccessor} from 'js-joda/src/temporal/TemporalAccessor.js'
public class | source

TemporalAccessor

Direct Subclass:

src/temporal/NativeJsTemporal.js~NativeJsTemporal, Temporal

Indirect Subclass:

ChronoLocalDate, ChronoLocalDateTime, ChronoZonedDateTime, src/format/DateTimeBuilder.js~DateTimeBuilder, DayOfWeek, Instant, LocalDate, LocalDateTime, LocalTime, Month, MonthDay, src/format/DateTimeParseContext.js~Parsed, Year, YearMonth, ZonedDateTime

Method Summary

Public Methods
public

Gets the value of the specified field as an int.

public

query(query: TemporalQuery): *

Queries this date-time.

public

Gets the range of valid values for the specified field.

Public Methods

public get(field: TemporalField): number source

Gets the value of the specified field as an int.

This queries the date-time for the value for the specified field. The returned value will always be within the valid range of values for the field. If the date-time cannot return the value, because the field is unsupported or for some other reason, an exception will be thrown.

Specification for implementors

Implementations must check and handle all fields defined in ChronoField. If the field is supported and has an int range, then the value of the field must be returned. If unsupported, then a DateTimeException must be thrown.

If the field is not a ChronoField, then the result of this method is obtained by invoking TemporalField.getFrom passing this as the argument.

Implementations must not alter either this object.

Params:

NameTypeAttributeDescription
field TemporalField

the field to get, not null

Return:

number

the value for the field, within the valid range of values

Throw:

*

DateTimeException if a value for the field cannot be obtained

*

DateTimeException if the range of valid values for the field exceeds an int

*

DateTimeException if the value is outside the range of valid values for the field

*

ArithmeticException if numeric overflow occurs

public query(query: TemporalQuery): * source

Queries this date-time.

This queries this date-time using the specified query strategy object.

Queries are a key tool for extracting information from date-times. They exists to externalize the process of querying, permitting different approaches, as per the strategy design pattern. Examples might be a query that checks if the date is the day before February 29th in a leap year, or calculates the number of days to your next birthday.

The most common query implementations are method references, such as LocalDate::from and ZoneId::from. Further implementations are on TemporalQueries. Queries may also be defined by applications.

Params:

NameTypeAttributeDescription
query TemporalQuery

the query to invoke, not null

Return:

*

the query result, null may be returned (defined by the query)

Throw:

*

DateTimeException if unable to query

*

ArithmeticException if numeric overflow occurs

public range(field: TemporalField): ValueRange source

Gets the range of valid values for the specified field.

All fields can be expressed as a long integer. This method returns an object that describes the valid range for that value. The value of this temporal object is used to enhance the accuracy of the returned range. If the date-time cannot return the range, because the field is unsupported or for some other reason, an exception will be thrown.

Note that the result only describes the minimum and maximum valid values and it is important not to read too much into them. For example, there could be values within the range that are invalid for the field.

Specification for implementors

Implementations must check and handle all fields defined in ChronoField. If the field is supported, then the range of the field must be returned. If unsupported, then a DateTimeException must be thrown.

If the field is not a ChronoField, then the result of this method is obtained by invoking TemporalField.rangeRefinedBy passing this as the argument.

Implementations must not alter either this object.

Params:

NameTypeAttributeDescription
field TemporalField

the field to query the range for, not null

Return:

ValueRange

the range of valid values for the field, not null

Throw:

*

DateTimeException if the range for the field cannot be obtained