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

ChronoField

Extends:

TemporalField → ChronoField

A standard set of fields.

This set of fields provide field-based access to manipulate a date, time or date-time. The standard set of fields can be extended by implementing TemporalField.

These fields are intended to be applicable in multiple calendar systems. For example, most non-ISO calendar systems define dates as a year, month and day, just with slightly different rules. The documentation of each field explains how it operates.

Static properties of Class ChronoField

ChronoField.NANO_OF_SECOND

ChronoField.NANO_OF_DAY

ChronoField.MICRO_OF_SECOND

ChronoField.MICRO_OF_DAY

ChronoField.MILLI_OF_SECOND

ChronoField.MILLI_OF_DAY

ChronoField.SECOND_OF_MINUTE

ChronoField.SECOND_OF_DAY

ChronoField.MINUTE_OF_HOUR

ChronoField.MINUTE_OF_DAY

ChronoField.HOUR_OF_AMPM

ChronoField.CLOCK_HOUR_OF_AMPM

ChronoField.HOUR_OF_DAY

ChronoField.CLOCK_HOUR_OF_DAY

ChronoField.AMPM_OF_DAY

ChronoField.DAY_OF_WEEK

ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH

ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR

ChronoField.DAY_OF_MONTH

ChronoField.DAY_OF_YEAR

ChronoField.EPOCH_DAY

ChronoField.ALIGNED_WEEK_OF_MONTH

ChronoField.ALIGNED_WEEK_OF_YEAR

ChronoField.MONTH_OF_YEAR

ChronoField.PROLEPTIC_MONTH

ChronoField.YEAR_OF_ERA

ChronoField.YEAR

ChronoField.ERA

ChronoField.INSTANT_SECONDS

ChronoField.OFFSET_SECONDS

Static Method Summary

Static Public Methods
public static

byName(fieldName: String): ChronoField | null

helper function to get one of the static ChronoField defines by name, needed to resolve ChronoField from EnumMap

Method Summary

Public Methods
public
public

Checks that the specified value is valid and fits in an int.

public

checkValidValue(value: number): *

public
public

equals(other: *): boolean

public
public

Checks if this field represents a component of a date.

public

Checks if this field represents a component of a time.

public
public
public

Get the range of valid values for this field using the temporal object to refine the result.

public
public

Static Public Methods

public static byName(fieldName: String): ChronoField | null source

helper function to get one of the static ChronoField defines by name, needed to resolve ChronoField from EnumMap

Params:

NameTypeAttributeDescription
fieldName String

Return:

ChronoField | null

Public Methods

public baseUnit(): number source

Return:

number (nullable: false)

public checkValidIntValue(value: number): number source

Checks that the specified value is valid and fits in an int.

This validates that the value is within the outer range of valid values returned by range. It also checks that all valid values are within the bounds of an int.

This method checks against the range of the field in the ISO-8601 calendar system. This range may be incorrect for other calendar systems. Use Chronology#range to access the correct range for a different calendar system.

Params:

NameTypeAttributeDescription
value number

the value to check

Return:

number

the value that was passed in

public checkValidValue(value: number): * source

Params:

NameTypeAttributeDescription
value number

Return:

*

public displayName(): string source

Return:

string

public equals(other: *): boolean source

Params:

NameTypeAttributeDescription
other *

Return:

boolean

public getFrom(temporal: TemporalAccessor): number source

Params:

NameTypeAttributeDescription
temporal TemporalAccessor

Return:

number

public isDateBased(): boolean source

Checks if this field represents a component of a date.

Return:

boolean

true if it is a component of a date

public isTimeBased(): boolean source

Checks if this field represents a component of a time.

Return:

boolean

true if it is a component of a time

public name(): string source

Return:

string

public range(): ValueRange source

Return:

ValueRange (nullable: false)

public rangeRefinedBy(temporal: TemporalAccessor): ValueRange source

Get the range of valid values for this field using the temporal object to refine the result.

This uses the temporal object to find the range of valid values for the field. This is similar to range, however this method refines the result using the temporal. For example, if the field is DAY_OF_MONTH the range method is not accurate as there are four possible month lengths, 28, 29, 30 and 31 days. Using this method with a date allows the range to be accurate, returning just one of those four options.

There are two equivalent ways of using this method. The first is to invoke this method directly. The second is to use TemporalAccessor#range:

  // these two lines are equivalent, but the second approach is recommended
  temporal = thisField.rangeRefinedBy(temporal);
  temporal = temporal.range(thisField);
It is recommended to use the second approach, range, as it is a lot clearer to read in code.

Implementations should perform any queries or calculations using the fields available in ChronoField. If the field is not supported a DateTimeException must be thrown.

Params:

NameTypeAttributeDescription
temporal TemporalAccessor
  • nullable: false

the temporal object used to refine the result, not null

Return:

ValueRange

the range of valid values for this field, not null

Throw:

*

DateTimeException if the range for the field cannot be obtained

public rangeUnit(): number source

Return:

number (nullable: false)

public toString(): string source

Return:

string