@js-joda/extra 0.9.1 → 0.10.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/dist/js-joda-extra.esm.js +1991 -22
- package/dist/js-joda-extra.esm.js.map +1 -1
- package/dist/js-joda-extra.js +1994 -20
- package/dist/js-joda-extra.js.map +1 -1
- package/dist/js-joda-extra.min.js +2 -2
- package/package.json +3 -3
- package/src/DayOfMonth.js +54 -54
- package/src/DayOfYear.js +48 -49
- package/src/Interval.js +93 -99
- package/src/LocalDateRange.js +750 -0
- package/src/OffsetDate.js +1279 -0
- package/src/Quarter.js +587 -0
- package/src/YearQuarter.js +1177 -0
- package/src/YearWeek.js +1026 -0
- package/src/_init.js +10 -0
- package/src/assert.js +2 -2
- package/src/js-joda-extra.js +10 -0
- package/src/plug.js +10 -0
- package/typings/js-joda-extra.d.ts +234 -2
package/src/DayOfYear.js
CHANGED
|
@@ -26,25 +26,25 @@ const MathUtil = jodaInternal.MathUtil;
|
|
|
26
26
|
export class DayOfYear extends TemporalAccessor {
|
|
27
27
|
/**
|
|
28
28
|
* Function overloading for {@link DayOfYear.now}:
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
29
|
+
* - if called with no arguments, {@link DayOfYear._now0} is executed;
|
|
30
|
+
* - if called with an instance of {@link ZoneId}, then {@link DayOfYear._nowZoneId} is executed;
|
|
31
|
+
* - if called with an instance of {@link Clock}, then {@link DayOfYear._nowClock} is executed;
|
|
32
|
+
* - otherwise {@link IllegalArgumentException} is thrown.
|
|
33
33
|
*
|
|
34
34
|
* @param {?(ZoneId|Clock)} zoneIdOrClock
|
|
35
|
-
* @
|
|
35
|
+
* @return {DayOfYear}
|
|
36
36
|
*/
|
|
37
37
|
static now(zoneIdOrClock) {
|
|
38
38
|
switch (arguments.length) {
|
|
39
39
|
case 0:
|
|
40
|
-
return DayOfYear.
|
|
40
|
+
return DayOfYear._now0();
|
|
41
41
|
case 1:
|
|
42
42
|
requireNonNull(zoneIdOrClock, 'clockOrZone');
|
|
43
43
|
if (zoneIdOrClock instanceof ZoneId) {
|
|
44
|
-
return DayOfYear.
|
|
44
|
+
return DayOfYear._nowZoneId(zoneIdOrClock);
|
|
45
45
|
}
|
|
46
46
|
if (zoneIdOrClock instanceof Clock) {
|
|
47
|
-
return DayOfYear.
|
|
47
|
+
return DayOfYear._nowClock(zoneIdOrClock);
|
|
48
48
|
}
|
|
49
49
|
throw new IllegalArgumentException(`zoneIdOrClock must be an instance of ZoneId or Clock, but is ${zoneIdOrClock.constructor.name}`);
|
|
50
50
|
default:
|
|
@@ -63,10 +63,10 @@ export class DayOfYear extends TemporalAccessor {
|
|
|
63
63
|
* Using this method will prevent the ability to use an alternate clock for testing
|
|
64
64
|
* because the clock is hard-coded.
|
|
65
65
|
*
|
|
66
|
-
* @return the current day-of-year using the system clock and default time-zone, not null
|
|
67
|
-
* @
|
|
66
|
+
* @return {DayOfYear} the current day-of-year using the system clock and default time-zone, not null
|
|
67
|
+
* @protected
|
|
68
68
|
*/
|
|
69
|
-
static
|
|
69
|
+
static _now0() {
|
|
70
70
|
return DayOfYear.now(Clock.systemDefaultZone());
|
|
71
71
|
}
|
|
72
72
|
|
|
@@ -79,11 +79,11 @@ export class DayOfYear extends TemporalAccessor {
|
|
|
79
79
|
* Using this method will prevent the ability to use an alternate clock for testing
|
|
80
80
|
* because the clock is hard-coded.
|
|
81
81
|
*
|
|
82
|
-
* @param zone
|
|
83
|
-
* @return the current day-of-year using the system clock, not null
|
|
84
|
-
* @
|
|
82
|
+
* @param {ZoneId} zone - the zone ID to use, not null
|
|
83
|
+
* @return {DayOfYear} the current day-of-year using the system clock, not null
|
|
84
|
+
* @protected
|
|
85
85
|
*/
|
|
86
|
-
static
|
|
86
|
+
static _nowZoneId(zone) {
|
|
87
87
|
return DayOfYear.now(Clock.system(zone));
|
|
88
88
|
}
|
|
89
89
|
|
|
@@ -94,11 +94,11 @@ export class DayOfYear extends TemporalAccessor {
|
|
|
94
94
|
* Using this method allows the use of an alternate clock for testing.
|
|
95
95
|
* The alternate clock may be introduced using {@link Clock} dependency injection.
|
|
96
96
|
*
|
|
97
|
-
* @param clock
|
|
98
|
-
* @return the current day-of-year, not null
|
|
99
|
-
* @
|
|
97
|
+
* @param {Clock} clock - the clock to use, not null
|
|
98
|
+
* @return {DayOfYear} the current day-of-year, not null
|
|
99
|
+
* @protected
|
|
100
100
|
*/
|
|
101
|
-
static
|
|
101
|
+
static _nowClock(clock) {
|
|
102
102
|
const now = LocalDate.now(clock); // called once
|
|
103
103
|
return DayOfYear.of(now.dayOfYear());
|
|
104
104
|
}
|
|
@@ -109,8 +109,8 @@ export class DayOfYear extends TemporalAccessor {
|
|
|
109
109
|
*
|
|
110
110
|
* A day-of-year object represents one of the 366 days of the year, from 1 to 366.
|
|
111
111
|
*
|
|
112
|
-
* @param dayOfYear
|
|
113
|
-
* @return the day-of-year, not null
|
|
112
|
+
* @param {number} dayOfYear - the day-of-year to represent, from 1 to 366
|
|
113
|
+
* @return {DayOfYear} the day-of-year, not null
|
|
114
114
|
* @throws {DateTimeException} if the day-of-year is invalid
|
|
115
115
|
*/
|
|
116
116
|
static of(dayOfYear) {
|
|
@@ -136,8 +136,8 @@ export class DayOfYear extends TemporalAccessor {
|
|
|
136
136
|
* This method matches the signature of the functional interface {@link TemporalQuery}
|
|
137
137
|
* allowing it to be used in queries via method reference, {@link DayOfYear.from}.
|
|
138
138
|
*
|
|
139
|
-
* @param temporal
|
|
140
|
-
* @return the day-of-year, not null
|
|
139
|
+
* @param {Temporal} temporal - the temporal object to convert, not null
|
|
140
|
+
* @return {DayOfYear} the day-of-year, not null
|
|
141
141
|
* @throws {DateTimeException} if unable to convert to a {@link DayOfYear}
|
|
142
142
|
*/
|
|
143
143
|
static from(temporal) {
|
|
@@ -162,7 +162,7 @@ export class DayOfYear extends TemporalAccessor {
|
|
|
162
162
|
/**
|
|
163
163
|
* Constructor, previously validated.
|
|
164
164
|
*
|
|
165
|
-
* @param {number} dayOfYear
|
|
165
|
+
* @param {number} dayOfYear - the day-of-year being represented, from 1 to 366.
|
|
166
166
|
* @private
|
|
167
167
|
*/
|
|
168
168
|
constructor(dayOfYear) {
|
|
@@ -174,7 +174,7 @@ export class DayOfYear extends TemporalAccessor {
|
|
|
174
174
|
/**
|
|
175
175
|
* Gets the day-of-year value.
|
|
176
176
|
*
|
|
177
|
-
* @return the day-of-year, from 1 to 366
|
|
177
|
+
* @return {number} the day-of-year, from 1 to 366
|
|
178
178
|
*/
|
|
179
179
|
value() {
|
|
180
180
|
return this._day;
|
|
@@ -191,8 +191,7 @@ export class DayOfYear extends TemporalAccessor {
|
|
|
191
191
|
*
|
|
192
192
|
* If the field is a {@link ChronoField} then the query is implemented here.
|
|
193
193
|
* The supported fields are:
|
|
194
|
-
*
|
|
195
|
-
* * {@link ChronoField.DAY_OF_YEAR}
|
|
194
|
+
* - {@link ChronoField.DAY_OF_YEAR}
|
|
196
195
|
*
|
|
197
196
|
* All other {@link ChronoField} instances will return false.
|
|
198
197
|
*
|
|
@@ -201,8 +200,8 @@ export class DayOfYear extends TemporalAccessor {
|
|
|
201
200
|
* passing this as the argument.
|
|
202
201
|
* Whether the field is supported is determined by the field.
|
|
203
202
|
*
|
|
204
|
-
* @param field
|
|
205
|
-
* @return true if the field is supported on this day-of-year, false if not
|
|
203
|
+
* @param {TemporalField} field - the field to check, null returns false
|
|
204
|
+
* @return {boolean} true if the field is supported on this day-of-year, false if not
|
|
206
205
|
*/
|
|
207
206
|
isSupported(field) {
|
|
208
207
|
if (field instanceof ChronoField) {
|
|
@@ -230,8 +229,8 @@ export class DayOfYear extends TemporalAccessor {
|
|
|
230
229
|
* passing this as the argument.
|
|
231
230
|
* Whether the range can be obtained is determined by the field.
|
|
232
231
|
*
|
|
233
|
-
* @param field
|
|
234
|
-
* @return the range of valid values for the field, not null
|
|
232
|
+
* @param {TemporalField} field - the field to query the range for, not null
|
|
233
|
+
* @return {ValueRange} the range of valid values for the field, not null
|
|
235
234
|
* @throws {DateTimeException} if the range for the field cannot be obtained
|
|
236
235
|
* @throws {UnsupportedTemporalTypeException} if the field is not supported
|
|
237
236
|
*/
|
|
@@ -261,8 +260,8 @@ export class DayOfYear extends TemporalAccessor {
|
|
|
261
260
|
* passing this as the argument. Whether the value can be obtained,
|
|
262
261
|
* and what the value represents, is determined by the field.
|
|
263
262
|
*
|
|
264
|
-
* @param field
|
|
265
|
-
* @return the value for the field
|
|
263
|
+
* @param {TemporalField} field - the field to get, not null
|
|
264
|
+
* @return {number} the value for the field
|
|
266
265
|
* @throws {DateTimeException} if a value for the field cannot be obtained or
|
|
267
266
|
* the value is outside the range of valid values for the field
|
|
268
267
|
* @throws {UnsupportedTemporalTypeException} if the field is not supported or
|
|
@@ -290,8 +289,8 @@ export class DayOfYear extends TemporalAccessor {
|
|
|
290
289
|
* passing this as the argument. Whether the value can be obtained,
|
|
291
290
|
* and what the value represents, is determined by the field.
|
|
292
291
|
*
|
|
293
|
-
* @param field
|
|
294
|
-
* @return the value for the field
|
|
292
|
+
* @param {TemporalField} field - the field to get, not null
|
|
293
|
+
* @return {number} the value for the field
|
|
295
294
|
* @throws {DateTimeException} if a value for the field cannot be obtained
|
|
296
295
|
* @throws {UnsupportedTemporalTypeException} if the field is not supported
|
|
297
296
|
* @throws {ArithmeticException} if numeric overflow occurs
|
|
@@ -313,8 +312,8 @@ export class DayOfYear extends TemporalAccessor {
|
|
|
313
312
|
* This method checks whether this day-of-yearand the input year form
|
|
314
313
|
* a valid date. This can only return false for day-of-year 366.
|
|
315
314
|
*
|
|
316
|
-
* @param year
|
|
317
|
-
* @return true if the year is valid for this day-of-year
|
|
315
|
+
* @param {number} year - the year to validate
|
|
316
|
+
* @return {boolean} true if the year is valid for this day-of-year
|
|
318
317
|
*/
|
|
319
318
|
isValidYear(year) {
|
|
320
319
|
return (this._day < 366 || Year.isLeap(year));
|
|
@@ -333,8 +332,8 @@ export class DayOfYear extends TemporalAccessor {
|
|
|
333
332
|
* {@link TemporalQuery.queryFrom} method on the
|
|
334
333
|
* specified query passing this as the argument.
|
|
335
334
|
*
|
|
336
|
-
* @param query
|
|
337
|
-
* @return the query result, null may be returned (defined by the query)
|
|
335
|
+
* @param {TemporalQuery} query - the query to invoke, not null
|
|
336
|
+
* @return {*} the query result, null may be returned (defined by the query)
|
|
338
337
|
* @throws {DateTimeException} if unable to query (defined by the query)
|
|
339
338
|
* @throws {ArithmeticException} if numeric overflow occurs (defined by the query)
|
|
340
339
|
*/
|
|
@@ -368,8 +367,8 @@ export class DayOfYear extends TemporalAccessor {
|
|
|
368
367
|
*
|
|
369
368
|
* This instance is immutable and unaffected by this method call.
|
|
370
369
|
*
|
|
371
|
-
* @param temporal
|
|
372
|
-
* @return the adjusted object, not null
|
|
370
|
+
* @param {Temporal} temporal - the target object to be adjusted, not null
|
|
371
|
+
* @return {Temporal} the adjusted object, not null
|
|
373
372
|
* @throws {DateTimeException} if unable to make the adjustment
|
|
374
373
|
* @throws {ArithmeticException} if numeric overflow occurs
|
|
375
374
|
*/
|
|
@@ -395,8 +394,8 @@ export class DayOfYear extends TemporalAccessor {
|
|
|
395
394
|
*
|
|
396
395
|
* The day-of-year value 366 is only valid in a leap year.
|
|
397
396
|
*
|
|
398
|
-
* @param year
|
|
399
|
-
* @return the local date formed from this day and the specified year, not null
|
|
397
|
+
* @param {Year|number} year - the year to use ({@link Year} or `int`), not null
|
|
398
|
+
* @return {LocalDate} the local date formed from this day and the specified year, not null
|
|
400
399
|
* @throws {DateTimeException} if the year is invalid or this is day 366 and the year is not a leap year
|
|
401
400
|
*/
|
|
402
401
|
atYear(year) {
|
|
@@ -415,8 +414,8 @@ export class DayOfYear extends TemporalAccessor {
|
|
|
415
414
|
* The comparison is based on the value of the day.
|
|
416
415
|
* It is "consistent with equals", as defined by {@link Comparable}.
|
|
417
416
|
*
|
|
418
|
-
* @param other
|
|
419
|
-
* @return the comparator value, negative if less, positive if greater
|
|
417
|
+
* @param {DayOfYear} other - the other day-of-year instance, not null
|
|
418
|
+
* @return {number} the comparator value, negative if less, positive if greater
|
|
420
419
|
*/
|
|
421
420
|
compareTo(other) {
|
|
422
421
|
requireNonNull(other, 'other');
|
|
@@ -428,8 +427,8 @@ export class DayOfYear extends TemporalAccessor {
|
|
|
428
427
|
/**
|
|
429
428
|
* Checks if this day-of-year is equal to another day-of-year.
|
|
430
429
|
*
|
|
431
|
-
* @param obj
|
|
432
|
-
* @return true if the day-of-year is the same
|
|
430
|
+
* @param {*} obj - the other day-of-year instance, null returns false
|
|
431
|
+
* @return {boolean} true if the day-of-year is the same
|
|
433
432
|
*/
|
|
434
433
|
equals(obj) {
|
|
435
434
|
if (this === obj) {
|
|
@@ -444,7 +443,7 @@ export class DayOfYear extends TemporalAccessor {
|
|
|
444
443
|
/**
|
|
445
444
|
* A hash code for this day-of-year.
|
|
446
445
|
*
|
|
447
|
-
* @return a suitable hash code
|
|
446
|
+
* @return {number} a suitable hash code
|
|
448
447
|
*/
|
|
449
448
|
hashCode() {
|
|
450
449
|
return this._day;
|
|
@@ -454,7 +453,7 @@ export class DayOfYear extends TemporalAccessor {
|
|
|
454
453
|
/**
|
|
455
454
|
* Outputs this day-of-year as a {@link String}.
|
|
456
455
|
*
|
|
457
|
-
* @return a string representation of this day-of-year, not null
|
|
456
|
+
* @return {string} a string representation of this day-of-year, not null
|
|
458
457
|
*/
|
|
459
458
|
toString() {
|
|
460
459
|
return `DayOfYear:${this._day}`;
|