@js-joda/core 1.12.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +58 -1
- package/dist/js-joda.d.ts +2377 -1635
- package/dist/js-joda.esm.js +1678 -653
- package/dist/js-joda.js +1681 -654
- package/dist/js-joda.js.map +1 -1
- package/dist/js-joda.min.js +2 -2
- package/package.json +24 -21
- package/src/DayOfWeek.js +3 -3
- package/src/Duration.js +4 -4
- package/src/Instant.js +12 -54
- package/src/LocalDate.js +26 -75
- package/src/LocalDateTime.js +10 -62
- package/src/LocalTime.js +8 -61
- package/src/Month.js +4 -4
- package/src/MonthDay.js +1 -2
- package/src/OffsetDateTime.js +757 -0
- package/src/OffsetTime.js +621 -0
- package/src/Period.js +1 -1
- package/src/Year.js +73 -57
- package/src/YearMonth.js +10 -68
- package/src/ZonedDateTime.js +11 -52
- package/src/_init.js +4 -0
- package/src/chrono/ChronoLocalDate.js +2 -2
- package/src/chrono/ChronoLocalDateTime.js +2 -2
- package/src/chrono/ChronoZonedDateTime.js +2 -2
- package/src/errors.js +6 -6
- package/src/format/DateTimeBuilder.js +2 -2
- package/src/format/DateTimeFormatter.js +3 -3
- package/src/js-joda.js +6 -0
- package/src/temporal/ChronoField.js +241 -133
- package/src/temporal/ChronoUnit.js +72 -229
- package/src/temporal/DefaultInterfaceTemporal.js +118 -0
- package/src/temporal/IsoFields.js +35 -32
- package/src/temporal/Temporal.js +284 -1
- package/src/temporal/TemporalField.js +225 -1
- package/src/temporal/TemporalUnit.js +18 -19
- package/src/temporal/ValueRange.js +1 -0
|
@@ -22,68 +22,189 @@ import {YearConstants} from '../YearConstants';
|
|
|
22
22
|
* just with slightly different rules.
|
|
23
23
|
* The documentation of each field explains how it operates.
|
|
24
24
|
*
|
|
25
|
-
* ### Static properties
|
|
26
|
-
*
|
|
27
|
-
* ChronoField.
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* ChronoField.
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* ChronoField.
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* ChronoField.
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* ChronoField.
|
|
44
|
-
*
|
|
45
|
-
* ChronoField.
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* ChronoField.
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
* ChronoField.
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
* ChronoField.
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
25
|
+
* ### Static properties:
|
|
26
|
+
*
|
|
27
|
+
* - `ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH`: This represents concept of the count of
|
|
28
|
+
* days within the period of a week where the weeks are aligned to the start of the month.
|
|
29
|
+
* This field is typically used with `ALIGNED_WEEK_OF_MONTH`.
|
|
30
|
+
*
|
|
31
|
+
* - `ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR`: This represents concept of the count of days
|
|
32
|
+
* within the period of a week where the weeks are aligned to the start of the year.
|
|
33
|
+
* This field is typically used with `ALIGNED_WEEK_OF_YEAR`.
|
|
34
|
+
*
|
|
35
|
+
* - `ChronoField.ALIGNED_WEEK_OF_MONTH`: This represents concept of the count of weeks within
|
|
36
|
+
* the period of a month where the weeks are aligned to the start of the month. This field
|
|
37
|
+
* is typically used with `ALIGNED_DAY_OF_WEEK_IN_MONTH`.
|
|
38
|
+
*
|
|
39
|
+
* - `ChronoField.ALIGNED_WEEK_OF_YEAR`: This represents concept of the count of weeks within
|
|
40
|
+
* the period of a year where the weeks are aligned to the start of the year. This field
|
|
41
|
+
* is typically used with `ALIGNED_DAY_OF_WEEK_IN_YEAR`.
|
|
42
|
+
*
|
|
43
|
+
* - `ChronoField.AMPM_OF_DAY`: This counts the AM/PM within the day, from 0 (AM) to 1 (PM).
|
|
44
|
+
*
|
|
45
|
+
* - `ChronoField.CLOCK_HOUR_OF_AMPM`: This counts the hour within the AM/PM, from 1 to 12.
|
|
46
|
+
* This is the hour that would be observed on a standard 12-hour analog wall clock.
|
|
47
|
+
*
|
|
48
|
+
* - `ChronoField.CLOCK_HOUR_OF_DAY`: This counts the hour within the AM/PM, from 1 to 24.
|
|
49
|
+
* This is the hour that would be observed on a 24-hour analog wall clock.
|
|
50
|
+
*
|
|
51
|
+
* - `ChronoField.DAY_OF_MONTH`: This represents the concept of the day within the month.
|
|
52
|
+
* In the default ISO calendar system, this has values from 1 to 31 in most months.
|
|
53
|
+
* April, June, September, November have days from 1 to 30, while February has days from
|
|
54
|
+
* 1 to 28, or 29 in a leap year.
|
|
55
|
+
*
|
|
56
|
+
* - `ChronoField.DAY_OF_WEEK`: This represents the standard concept of the day of the week.
|
|
57
|
+
* In the default ISO calendar system, this has values from Monday (1) to Sunday (7).
|
|
58
|
+
* The {@link DayOfWeek} class can be used to interpret the result.
|
|
59
|
+
*
|
|
60
|
+
* - `ChronoField.DAY_OF_YEAR`: This represents the concept of the day within the year.
|
|
61
|
+
* In the default ISO calendar system, this has values from 1 to 365 in standard years and
|
|
62
|
+
* 1 to 366 in leap years.
|
|
63
|
+
*
|
|
64
|
+
* - `ChronoField.EPOCH_DAY`: This field is the sequential count of days where
|
|
65
|
+
* 1970-01-01 (ISO) is zero. Note that this uses the local time-line, ignoring offset and
|
|
66
|
+
* time-zone.
|
|
67
|
+
*
|
|
68
|
+
* - `ChronoField.ERA`: This represents the concept of the era, which is the largest
|
|
69
|
+
* division of the time-line. This field is typically used with `YEAR_OF_ERA`.
|
|
70
|
+
*
|
|
71
|
+
* In the default ISO calendar system, there are two eras defined, 'BCE' and 'CE'. The era
|
|
72
|
+
* 'CE' is the one currently in use and year-of-era runs from 1 to the maximum value.
|
|
73
|
+
* The era 'BCE' is the previous era, and the year-of-era runs backwards.
|
|
74
|
+
*
|
|
75
|
+
* - `ChronoField.HOUR_OF_AMPM`: This counts the hour within the AM/PM, from 0 to 11.
|
|
76
|
+
* This is the hour that would be observed on a standard 12-hour digital clock.
|
|
77
|
+
*
|
|
78
|
+
* - `ChronoField.HOUR_OF_DAY`: This counts the hour within the day, from 0 to 23. This is
|
|
79
|
+
* the hour that would be observed on a standard 24-hour digital clock.
|
|
80
|
+
*
|
|
81
|
+
* - `ChronoField.INSTANT_SECONDS`: This represents the concept of the sequential count of
|
|
82
|
+
* seconds where 1970-01-01T00:00Z (ISO) is zero. This field may be used with `NANO_OF_DAY`
|
|
83
|
+
* to represent the fraction of the day.
|
|
84
|
+
*
|
|
85
|
+
* An Instant represents an instantaneous point on the time-line. On their own they have
|
|
86
|
+
* no elements which allow a local date-time to be obtained. Only when paired with an offset
|
|
87
|
+
* or time-zone can the local date or time be found. This field allows the seconds part of
|
|
88
|
+
* the instant to be queried.
|
|
89
|
+
*
|
|
90
|
+
* - `ChronoField.MICRO_OF_DAY`: This counts the microsecond within the day, from 0 to
|
|
91
|
+
* (24 * 60 * 60 * 1,000,000) - 1.
|
|
92
|
+
*
|
|
93
|
+
* This field is used to represent the micro-of-day handling any fraction of the second.
|
|
94
|
+
* Implementations of {@link TemporalAccessor} should provide a value for this field if they
|
|
95
|
+
* can return a value for `SECOND_OF_DAY` filling unknown precision with zero.
|
|
96
|
+
*
|
|
97
|
+
* When this field is used for setting a value, it should behave in the same way as
|
|
98
|
+
* setting `NANO_OF_DAY` with the value multiplied by 1,000.
|
|
99
|
+
*
|
|
100
|
+
* - `ChronoField.MICRO_OF_SECOND`: This counts the microsecond within the second, from 0
|
|
101
|
+
* to 999,999.
|
|
102
|
+
*
|
|
103
|
+
* This field is used to represent the micro-of-second handling any fraction of the second.
|
|
104
|
+
* Implementations of {@link TemporalAccessor} should provide a value for this field if they
|
|
105
|
+
* can return a value for `SECOND_OF_MINUTE`, `SECOND_OF_DAY` or `INSTANT_SECONDS` filling
|
|
106
|
+
* unknown precision with zero.
|
|
107
|
+
*
|
|
108
|
+
* - `ChronoField.MILLI_OF_DAY`: This counts the millisecond within the day, from 0 to
|
|
109
|
+
* (24 * 60 * 60 * 1,000) - 1.
|
|
110
|
+
*
|
|
111
|
+
* This field is used to represent the milli-of-day handling any fraction of the second.
|
|
112
|
+
* Implementations of {@link TemporalAccessor} should provide a value for this field if they
|
|
113
|
+
* can return a value for `SECOND_OF_DAY` filling unknown precision with zero.
|
|
114
|
+
*
|
|
115
|
+
* When this field is used for setting a value, it should behave in the same way as
|
|
116
|
+
* setting `NANO_OF_DAY` with the value multiplied by 1,000,000.
|
|
117
|
+
*
|
|
118
|
+
* - `ChronoField.MILLI_OF_SECOND`: This counts the millisecond within the second, from 0 to
|
|
119
|
+
* 999.
|
|
120
|
+
*
|
|
121
|
+
* This field is used to represent the milli-of-second handling any fraction of the second.
|
|
122
|
+
* Implementations of {@link TemporalAccessor} should provide a value for this field if they can
|
|
123
|
+
* return a value for `SECOND_OF_MINUTE`, `SECOND_OF_DAY` or `INSTANT_SECONDS` filling unknown
|
|
124
|
+
* precision with zero.
|
|
125
|
+
*
|
|
126
|
+
* When this field is used for setting a value, it should behave in the same way as
|
|
127
|
+
* setting `NANO_OF_SECOND` with the value multiplied by 1,000,000.
|
|
128
|
+
*
|
|
129
|
+
* - `ChronoField.MINUTE_OF_DAY`: This counts the minute within the day, from 0 to (24 * 60) - 1.
|
|
130
|
+
*
|
|
131
|
+
* - `ChronoField.MINUTE_OF_HOUR`: This counts the minute within the hour, from 0 to 59.
|
|
132
|
+
*
|
|
133
|
+
* - `ChronoField.MONTH_OF_YEAR`: The month-of-year, such as March. This represents the concept
|
|
134
|
+
* of the month within the year. In the default ISO calendar system, this has values from
|
|
135
|
+
* January (1) to December (12).
|
|
136
|
+
*
|
|
137
|
+
* - `ChronoField.NANO_OF_DAY`: This counts the nanosecond within the day, from 0 to
|
|
138
|
+
* (24 * 60 * 60 * 1,000,000,000) - 1.
|
|
139
|
+
*
|
|
140
|
+
* This field is used to represent the nano-of-day handling any fraction of the second.
|
|
141
|
+
* Implementations of {@link TemporalAccessor} should provide a value for this field if they
|
|
142
|
+
* can return a value for `SECOND_OF_DAY` filling unknown precision with zero.
|
|
143
|
+
*
|
|
144
|
+
* - `ChronoField.NANO_OF_SECOND`: This counts the nanosecond within the second, from 0
|
|
145
|
+
* to 999,999,999.
|
|
146
|
+
*
|
|
147
|
+
* This field is used to represent the nano-of-second handling any fraction of the second.
|
|
148
|
+
* Implementations of {@link TemporalAccessor} should provide a value for this field if they
|
|
149
|
+
* can return a value for `SECOND_OF_MINUTE`, `SECOND_OF_DAY` or `INSTANT_SECONDS` filling
|
|
150
|
+
* unknown precision with zero.
|
|
151
|
+
*
|
|
152
|
+
* When this field is used for setting a value, it should set as much precision as the
|
|
153
|
+
* object stores, using integer division to remove excess precision. For example, if the
|
|
154
|
+
* {@link TemporalAccessor} stores time to millisecond precision, then the nano-of-second must
|
|
155
|
+
* be divided by 1,000,000 before replacing the milli-of-second.
|
|
156
|
+
*
|
|
157
|
+
* - `ChronoField.OFFSET_SECONDS`: This represents the concept of the offset in seconds of
|
|
158
|
+
* local time from UTC/Greenwich.
|
|
159
|
+
*
|
|
160
|
+
* A {@link ZoneOffset} represents the period of time that local time differs from
|
|
161
|
+
* UTC/Greenwich. This is usually a fixed number of hours and minutes. It is equivalent to
|
|
162
|
+
* the total amount of the offset in seconds. For example, during the winter Paris has an
|
|
163
|
+
* offset of +01:00, which is 3600 seconds.
|
|
164
|
+
*
|
|
165
|
+
* - `ChronoField.PROLEPTIC_MONTH`: The proleptic-month, which counts months sequentially
|
|
166
|
+
* from year 0.
|
|
167
|
+
*
|
|
168
|
+
* The first month in year zero has the value zero. The value increase for later months
|
|
169
|
+
* and decrease for earlier ones. Note that this uses the local time-line, ignoring offset
|
|
170
|
+
* and time-zone.
|
|
171
|
+
*
|
|
172
|
+
* - `ChronoField.SECOND_OF_DAY`: This counts the second within the day, from 0 to
|
|
173
|
+
* (24 * 60 * 60) - 1.
|
|
174
|
+
*
|
|
175
|
+
* - `ChronoField.SECOND_OF_MINUTE`: This counts the second within the minute, from 0 to 59.
|
|
176
|
+
*
|
|
177
|
+
* - `ChronoField.YEAR`: The proleptic year, such as 2012. This represents the concept of
|
|
178
|
+
* the year, counting sequentially and using negative numbers. The proleptic year is not
|
|
179
|
+
* interpreted in terms of the era.
|
|
180
|
+
*
|
|
181
|
+
* The standard mental model for a date is based on three concepts - year, month and day.
|
|
182
|
+
* These map onto the `YEAR`, `MONTH_OF_YEAR` and `DAY_OF_MONTH` fields. Note that there is no
|
|
183
|
+
* reference to eras. The full model for a date requires four concepts - era, year, month and
|
|
184
|
+
* day. These map onto the `ERA`, `YEAR_OF_ERA`, `MONTH_OF_YEAR` and `DAY_OF_MONTH` fields.
|
|
185
|
+
* Whether this field or `YEAR_OF_ERA` is used depends on which mental model is being used.
|
|
186
|
+
*
|
|
187
|
+
* - `ChronoField.YEAR_OF_ERA`: This represents the concept of the year within the era. This
|
|
188
|
+
* field is typically used with `ERA`. The standard mental model for a date is based on three
|
|
189
|
+
* concepts - year, month and day. These map onto the `YEAR`, `MONTH_OF_YEAR` and
|
|
190
|
+
* `DAY_OF_MONTH` fields. Note that there is no reference to eras. The full model for a date
|
|
191
|
+
* requires four concepts - era, year, month and day. These map onto the `ERA`, `YEAR_OF_ERA`,
|
|
192
|
+
* `MONTH_OF_YEAR` and `DAY_OF_MONTH` fields. Whether this field or `YEAR` is used depends on
|
|
193
|
+
* which mental model is being used.
|
|
194
|
+
*
|
|
195
|
+
* In the default ISO calendar system, there are two eras defined, 'BCE' and 'CE'.
|
|
196
|
+
* The era 'CE' is the one currently in use and year-of-era runs from 1 to the maximum value.
|
|
197
|
+
* The era 'BCE' is the previous era, and the year-of-era runs backwards.
|
|
198
|
+
*
|
|
199
|
+
* For example, subtracting a year each time yield the following:
|
|
200
|
+
* - year-proleptic 2 = 'CE' year-of-era 2
|
|
201
|
+
* - year-proleptic 1 = 'CE' year-of-era 1
|
|
202
|
+
* - year-proleptic 0 = 'BCE' year-of-era 1
|
|
203
|
+
* - year-proleptic -1 = 'BCE' year-of-era 2
|
|
204
|
+
*
|
|
205
|
+
* Note that the ISO-8601 standard does not actually define eras. Note also that the
|
|
206
|
+
* ISO eras do not align with the well-known AD/BC eras due to the change between the Julian
|
|
207
|
+
* and Gregorian calendar systems.
|
|
87
208
|
*/
|
|
88
209
|
export class ChronoField extends TemporalField {
|
|
89
210
|
|
|
@@ -92,6 +213,7 @@ export class ChronoField extends TemporalField {
|
|
|
92
213
|
*
|
|
93
214
|
* @param {String} fieldName
|
|
94
215
|
* @return {ChronoField | null}
|
|
216
|
+
* @private
|
|
95
217
|
*/
|
|
96
218
|
static byName(fieldName) {
|
|
97
219
|
for (const prop in ChronoField) {
|
|
@@ -106,8 +228,8 @@ export class ChronoField extends TemporalField {
|
|
|
106
228
|
/**
|
|
107
229
|
*
|
|
108
230
|
* @param {!string} name
|
|
109
|
-
* @param {!
|
|
110
|
-
* @param {!
|
|
231
|
+
* @param {!TemporalUnit} baseUnit
|
|
232
|
+
* @param {!TemporalUnit} rangeUnit
|
|
111
233
|
* @param {!ValueRange} range
|
|
112
234
|
* @private
|
|
113
235
|
*/
|
|
@@ -120,39 +242,34 @@ export class ChronoField extends TemporalField {
|
|
|
120
242
|
}
|
|
121
243
|
|
|
122
244
|
/**
|
|
123
|
-
*
|
|
124
|
-
* @returns {string}
|
|
245
|
+
* @return {string}
|
|
125
246
|
*/
|
|
126
247
|
name(){
|
|
127
248
|
return this._name;
|
|
128
249
|
}
|
|
129
250
|
|
|
130
251
|
/**
|
|
131
|
-
*
|
|
132
|
-
* @returns {!number}
|
|
252
|
+
* @return {TemporalUnit} the period unit defining the base unit of the field.
|
|
133
253
|
*/
|
|
134
254
|
baseUnit(){
|
|
135
255
|
return this._baseUnit;
|
|
136
256
|
}
|
|
137
257
|
|
|
138
258
|
/**
|
|
139
|
-
*
|
|
140
|
-
* @returns {!number}
|
|
259
|
+
* @return {TemporalUnit} the period unit defining the range of the field.
|
|
141
260
|
*/
|
|
142
261
|
rangeUnit(){
|
|
143
262
|
return this._rangeUnit;
|
|
144
263
|
}
|
|
145
264
|
|
|
146
265
|
/**
|
|
147
|
-
*
|
|
148
|
-
* @returns {!ValueRange}
|
|
266
|
+
* @return {ValueRange} the range of valid values for the field.
|
|
149
267
|
*/
|
|
150
268
|
range(){
|
|
151
269
|
return this._range;
|
|
152
270
|
}
|
|
153
271
|
|
|
154
272
|
/**
|
|
155
|
-
*
|
|
156
273
|
* @returns {string}
|
|
157
274
|
*/
|
|
158
275
|
displayName(){
|
|
@@ -160,18 +277,38 @@ export class ChronoField extends TemporalField {
|
|
|
160
277
|
}
|
|
161
278
|
|
|
162
279
|
/**
|
|
280
|
+
* Checks that the specified value is valid for this field.
|
|
281
|
+
*
|
|
282
|
+
* This validates that the value is within the outer range of valid values
|
|
283
|
+
* returned by {@link range}.
|
|
284
|
+
*
|
|
285
|
+
* This method checks against the range of the field in the ISO-8601 calendar system.
|
|
163
286
|
*
|
|
164
|
-
* @param {number} value
|
|
165
|
-
* @returns {
|
|
287
|
+
* @param {!number} value the value to check.
|
|
288
|
+
* @returns {number} the value that was passed in.
|
|
166
289
|
*/
|
|
167
290
|
checkValidValue(value) {
|
|
168
|
-
return this.range().checkValidValue(value, this
|
|
291
|
+
return this.range().checkValidValue(value, this);
|
|
169
292
|
}
|
|
170
293
|
|
|
171
294
|
/**
|
|
172
|
-
* Checks
|
|
295
|
+
* Checks that the specified value is valid and fits in an `int`.
|
|
296
|
+
*
|
|
297
|
+
* This validates that the value is within the outer range of valid values
|
|
298
|
+
* returned by {@link range}.
|
|
299
|
+
* It also checks that all valid values are within the bounds of an `int`.
|
|
173
300
|
*
|
|
174
|
-
*
|
|
301
|
+
* This method checks against the range of the field in the ISO-8601 calendar system.
|
|
302
|
+
*
|
|
303
|
+
* @param {number} value the value to check.
|
|
304
|
+
* @return {number} the value that was passed in.
|
|
305
|
+
*/
|
|
306
|
+
checkValidIntValue(value) {
|
|
307
|
+
return this.range().checkValidIntValue(value, this);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* @return {boolean} `true` if it is a component of a date, `false` otherwise.
|
|
175
312
|
*/
|
|
176
313
|
isDateBased() {
|
|
177
314
|
const dateBased =
|
|
@@ -192,9 +329,7 @@ export class ChronoField extends TemporalField {
|
|
|
192
329
|
}
|
|
193
330
|
|
|
194
331
|
/**
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
* @return {boolean} true if it is a component of a time
|
|
332
|
+
* @return {boolean} `true` if it is a component of a time, `false` otherwise.
|
|
198
333
|
*/
|
|
199
334
|
isTimeBased() {
|
|
200
335
|
const timeBased =
|
|
@@ -217,69 +352,26 @@ export class ChronoField extends TemporalField {
|
|
|
217
352
|
}
|
|
218
353
|
|
|
219
354
|
/**
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
* This uses the temporal object to find the range of valid values for the field.
|
|
224
|
-
* This is similar to {@link range}, however this method refines the result
|
|
225
|
-
* using the temporal. For example, if the field is {@link DAY_OF_MONTH} the
|
|
226
|
-
* {@link range} method is not accurate as there are four possible month lengths,
|
|
227
|
-
* 28, 29, 30 and 31 days. Using this method with a date allows the range to be
|
|
228
|
-
* accurate, returning just one of those four options.
|
|
229
|
-
*
|
|
230
|
-
* There are two equivalent ways of using this method.
|
|
231
|
-
* The first is to invoke this method directly.
|
|
232
|
-
* The second is to use {@link TemporalAccessor#range}:
|
|
233
|
-
* <pre>
|
|
234
|
-
* // these two lines are equivalent, but the second approach is recommended
|
|
235
|
-
* temporal = thisField.rangeRefinedBy(temporal);
|
|
236
|
-
* temporal = temporal.range(thisField);
|
|
237
|
-
* </pre>
|
|
238
|
-
* It is recommended to use the second approach, {@link range},
|
|
239
|
-
* as it is a lot clearer to read in code.
|
|
240
|
-
*
|
|
241
|
-
* Implementations should perform any queries or calculations using the fields
|
|
242
|
-
* available in {@link ChronoField}.
|
|
243
|
-
* If the field is not supported a {@link DateTimeException} must be thrown.
|
|
244
|
-
*
|
|
245
|
-
* @param {!TemporalAccessor} temporal - the temporal object used to refine the result, not null
|
|
246
|
-
* @return {ValueRange} the range of valid values for this field, not null
|
|
247
|
-
* @throws DateTimeException if the range for the field cannot be obtained
|
|
355
|
+
* @param {!TemporalAccessor} temporal the temporal object used to refine the result.
|
|
356
|
+
* @return {ValueRange} the range of valid values for this field.
|
|
357
|
+
* @throws {DateTimeException} if the range for the field cannot be obtained.
|
|
248
358
|
*/
|
|
249
359
|
rangeRefinedBy(temporal) {
|
|
250
360
|
return temporal.range(this);
|
|
251
361
|
}
|
|
252
362
|
|
|
253
|
-
|
|
254
|
-
* Checks that the specified value is valid and fits in an `int`.
|
|
255
|
-
*
|
|
256
|
-
* This validates that the value is within the outer range of valid values
|
|
257
|
-
* returned by {@link range}.
|
|
258
|
-
* It also checks that all valid values are within the bounds of an `int`.
|
|
259
|
-
*
|
|
260
|
-
* This method checks against the range of the field in the ISO-8601 calendar system.
|
|
261
|
-
* This range may be incorrect for other calendar systems.
|
|
262
|
-
* Use {@link Chronology#range} to access the correct range
|
|
263
|
-
* for a different calendar system.
|
|
264
|
-
*
|
|
265
|
-
* @param {number} value - the value to check
|
|
266
|
-
* @return {number} the value that was passed in
|
|
267
|
-
*/
|
|
268
|
-
checkValidIntValue(value) {
|
|
269
|
-
return this.range().checkValidIntValue(value, this);
|
|
270
|
-
}
|
|
363
|
+
|
|
271
364
|
|
|
272
365
|
/**
|
|
273
|
-
*
|
|
274
|
-
* @
|
|
275
|
-
* @
|
|
366
|
+
* @param {!TemporalAccesor} temporal the temporal object to query.
|
|
367
|
+
* @return {number} the value of this field.
|
|
368
|
+
* @throws {DateTimeException} if a value for the field cannot be obtained.
|
|
276
369
|
*/
|
|
277
370
|
getFrom(temporal) {
|
|
278
371
|
return temporal.getLong(this);
|
|
279
372
|
}
|
|
280
373
|
|
|
281
374
|
/**
|
|
282
|
-
*
|
|
283
375
|
* @returns {string}
|
|
284
376
|
*/
|
|
285
377
|
toString(){
|
|
@@ -287,13 +379,30 @@ export class ChronoField extends TemporalField {
|
|
|
287
379
|
}
|
|
288
380
|
|
|
289
381
|
/**
|
|
290
|
-
*
|
|
291
382
|
* @param {*} other
|
|
292
383
|
* @returns {boolean}
|
|
293
384
|
*/
|
|
294
385
|
equals(other){
|
|
295
386
|
return this === other;
|
|
296
387
|
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* @param {!Temporal} temporal the temporal object to adjust.
|
|
391
|
+
* @param {!number} newValue the new value of the field.
|
|
392
|
+
* @return {Temporal} the adjusted temporal object.
|
|
393
|
+
* @throws {DateTimeException} if the field cannot be set.
|
|
394
|
+
*/
|
|
395
|
+
adjustInto(temporal, newValue) {
|
|
396
|
+
return temporal.with(this, newValue);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* @param {!TemporalAccesor} temporal the temporal object to query.
|
|
401
|
+
* @return {boolean} `true` if the date-time can be queried for this field, `false` if not.
|
|
402
|
+
*/
|
|
403
|
+
isSupportedBy(temporal) {
|
|
404
|
+
return temporal.isSupported(this);
|
|
405
|
+
}
|
|
297
406
|
}
|
|
298
407
|
|
|
299
408
|
export function _init() {
|
|
@@ -359,4 +468,3 @@ export function _init() {
|
|
|
359
468
|
ChronoField.OFFSET_SECONDS = new ChronoField('OffsetSeconds', ChronoUnit.SECONDS, ChronoUnit.FOREVER, ValueRange.of(-18 * 3600, 18 * 3600));
|
|
360
469
|
|
|
361
470
|
}
|
|
362
|
-
|