ChronoField
Extends:
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 |
helper function to get one of the static ChronoField defines by name, needed to resolve ChronoField from EnumMap |
Constructor Summary
Public Constructor | ||
public |
constructor(name: string, baseUnit: number, rangeUnit: number, range: ValueRange) |
Method Summary
Public Methods | ||
public |
|
|
public |
checkValidIntValue(value: number): number Checks that the specified value is valid and fits in an |
|
public |
checkValidValue(value: number): * |
|
public |
|
|
public |
|
|
public |
getFrom(temporal: TemporalAccessor): number |
|
public |
Checks if this field represents a component of a date. |
|
public |
Checks if this field represents a component of a time. |
|
public |
|
|
public |
range(): ValueRange |
|
public |
rangeRefinedBy(temporal: TemporalAccessor): ValueRange Get the range of valid values for this field using the temporal object to refine the result. |
|
public |
|
|
public |
|
Static Public Methods
Public Constructors
public constructor(name: string, baseUnit: number, rangeUnit: number, range: ValueRange) source
Params:
Name | Type | Attribute | Description |
name | string |
|
|
baseUnit | number |
|
|
rangeUnit | number |
|
|
range | ValueRange |
|
Public Methods
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:
Name | Type | Attribute | Description |
value | number | the value to check |
public checkValidValue(value: number): * source
Params:
Name | Type | Attribute | Description |
value | number |
Return:
* |
public getFrom(temporal: TemporalAccessor): number source
Params:
Name | Type | Attribute | Description |
temporal | TemporalAccessor |
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:
Name | Type | Attribute | Description |
temporal | TemporalAccessor |
|
the temporal object used to refine the result, not null |
Throw:
* |
DateTimeException if the range for the field cannot be obtained |