@js-joda/core 3.2.0 → 4.2.1
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 +32 -1
- package/README.md +43 -36
- package/dist/js-joda.d.ts +241 -179
- package/dist/js-joda.esm.js +11524 -10214
- package/dist/js-joda.js +11524 -10214
- package/dist/js-joda.js.map +1 -1
- package/dist/js-joda.min.js +2 -2
- package/package.json +10 -40
- package/src/Clock.js +8 -9
- package/src/DayOfWeek.js +14 -14
- package/src/Duration.js +15 -15
- package/src/Instant.js +40 -74
- package/src/LocalDate.js +71 -93
- package/src/LocalDateTime.js +25 -68
- package/src/LocalTime.js +27 -72
- package/src/MathUtil.js +3 -3
- package/src/Month.js +13 -13
- package/src/MonthDay.js +25 -25
- package/src/OffsetDateTime.js +29 -29
- package/src/OffsetTime.js +32 -32
- package/src/Period.js +12 -12
- package/src/StringUtil.js +1 -1
- package/src/Year.js +33 -115
- package/src/YearMonth.js +31 -113
- package/src/ZoneId.js +7 -7
- package/src/ZoneIdFactory.js +14 -14
- package/src/ZoneOffset.js +23 -23
- package/src/ZoneRegion.js +2 -2
- package/src/ZonedDateTime.js +31 -74
- package/src/_init.js +24 -24
- package/src/assert.js +31 -4
- package/src/chrono/ChronoLocalDate.js +8 -8
- package/src/chrono/ChronoLocalDateTime.js +10 -10
- package/src/chrono/ChronoZonedDateTime.js +8 -8
- package/src/chrono/IsoChronology.js +13 -13
- package/src/convert.js +12 -8
- package/src/errors.js +3 -3
- package/src/format/DateTimeBuilder.js +17 -17
- package/src/format/DateTimeFormatter.js +45 -24
- package/src/format/DateTimeFormatterBuilder.js +59 -59
- package/src/format/DateTimeParseContext.js +6 -6
- package/src/format/DateTimePrintContext.js +3 -3
- package/src/format/DecimalStyle.js +1 -1
- package/src/format/ResolverStyle.js +1 -1
- package/src/format/SignStyle.js +1 -1
- package/src/format/TextStyle.js +1 -1
- package/src/format/parser/CharLiteralPrinterParser.js +3 -3
- package/src/format/parser/FractionPrinterParser.js +10 -10
- package/src/format/parser/NumberPrinterParser.js +18 -18
- package/src/format/parser/OffsetIdPrinterParser.js +9 -9
- package/src/format/parser/PadPrinterParserDecorator.js +3 -3
- package/src/format/parser/StringLiteralPrinterParser.js +2 -2
- package/src/format/parser/ZoneIdPrinterParser.js +5 -5
- package/src/js-joda.js +5 -0
- package/src/temporal/ChronoField.js +5 -5
- package/src/temporal/ChronoUnit.js +6 -6
- package/src/temporal/IsoFields.js +12 -12
- package/src/temporal/NativeJsTemporal.js +11 -11
- package/src/temporal/Temporal.js +45 -38
- package/src/temporal/TemporalAccessor.js +14 -4
- package/src/temporal/TemporalAdjuster.js +1 -1
- package/src/temporal/TemporalAdjusters.js +6 -6
- package/src/temporal/TemporalAmount.js +1 -1
- package/src/temporal/TemporalQueriesFactory.js +6 -6
- package/src/temporal/TemporalQuery.js +4 -2
- package/src/temporal/TemporalUnit.js +1 -1
- package/src/temporal/ValueRange.js +15 -15
- package/src/use.js +6 -1
- package/src/zone/SystemDefaultZoneId.js +2 -2
- package/src/zone/SystemDefaultZoneRules.js +3 -3
- package/src/zone/ZoneOffsetTransition.js +7 -7
- package/src/zone/ZoneRules.js +4 -4
- package/src/zone/ZoneRulesProvider.js +2 -2
- package/src/temporal/DefaultInterfaceTemporal.js +0 -118
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
* @license BSD-3-Clause (see LICENSE in the root directory of this source tree)
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {ChronoField} from './ChronoField';
|
|
8
|
-
import {createTemporalQuery} from './TemporalQuery';
|
|
9
|
-
import {TemporalQueries} from './TemporalQueries';
|
|
7
|
+
import { ChronoField } from './ChronoField';
|
|
8
|
+
import { createTemporalQuery } from './TemporalQuery';
|
|
9
|
+
import { TemporalQueries } from './TemporalQueries';
|
|
10
10
|
|
|
11
|
-
import {LocalDate} from '../LocalDate';
|
|
12
|
-
import {LocalTime} from '../LocalTime';
|
|
13
|
-
import {ZoneOffset} from '../ZoneOffset';
|
|
11
|
+
import { LocalDate } from '../LocalDate';
|
|
12
|
+
import { LocalTime } from '../LocalTime';
|
|
13
|
+
import { ZoneOffset } from '../ZoneOffset';
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
export function _init() {
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* @license BSD-3-Clause (see LICENSE in the root directory of this source tree)
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {abstractMethodFail} from '../assert';
|
|
8
|
-
import {Enum} from '../Enum';
|
|
7
|
+
import { abstractMethodFail } from '../assert';
|
|
8
|
+
import { Enum } from '../Enum';
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -92,6 +92,8 @@ export class TemporalQuery extends Enum {
|
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
/**
|
|
95
|
+
* @private
|
|
96
|
+
*
|
|
95
97
|
* Factory to create something similar to the JSR-310 {TemporalQuery} interface, takes a function and returns a new TemporalQuery object that presents that function
|
|
96
98
|
* as the queryFrom() function.
|
|
97
99
|
* @param name for the underlying Enum
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
* @license BSD-3-Clause (see LICENSE in the root directory of this source tree)
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {assert} from '../assert';
|
|
8
|
-
import {DateTimeException, IllegalArgumentException} from '../errors';
|
|
9
|
-
import {MathUtil} from '../MathUtil';
|
|
7
|
+
import { assert } from '../assert';
|
|
8
|
+
import { DateTimeException, IllegalArgumentException } from '../errors';
|
|
9
|
+
import { MathUtil } from '../MathUtil';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* The range of valid values for a date-time field.
|
|
@@ -34,12 +34,12 @@ export class ValueRange {
|
|
|
34
34
|
* @private
|
|
35
35
|
*/
|
|
36
36
|
constructor(minSmallest, minLargest, maxSmallest, maxLargest) {
|
|
37
|
-
assert(!(minSmallest > minLargest),
|
|
38
|
-
|
|
39
|
-
assert(!(maxSmallest > maxLargest),
|
|
40
|
-
|
|
41
|
-
assert(!(minLargest > maxLargest),
|
|
42
|
-
|
|
37
|
+
assert(!(minSmallest > minLargest), `Smallest minimum value '${minSmallest
|
|
38
|
+
}' must be less than largest minimum value '${minLargest}'`, IllegalArgumentException);
|
|
39
|
+
assert(!(maxSmallest > maxLargest), `Smallest maximum value '${maxSmallest
|
|
40
|
+
}' must be less than largest maximum value '${maxLargest}'`, IllegalArgumentException);
|
|
41
|
+
assert(!(minLargest > maxLargest), `Minimum value '${minLargest
|
|
42
|
+
}' must be less than maximum value '${maxLargest}'`, IllegalArgumentException);
|
|
43
43
|
|
|
44
44
|
this._minSmallest = minSmallest;
|
|
45
45
|
this._minLargest = minLargest;
|
|
@@ -109,9 +109,9 @@ export class ValueRange {
|
|
|
109
109
|
let msg;
|
|
110
110
|
if (!this.isValidValue(value)) {
|
|
111
111
|
if (field != null) {
|
|
112
|
-
msg =
|
|
112
|
+
msg = `Invalid value for ${field} (valid values ${this.toString()}): ${value}`;
|
|
113
113
|
} else {
|
|
114
|
-
msg =
|
|
114
|
+
msg = `Invalid value (valid values ${this.toString()}): ${value}`;
|
|
115
115
|
}
|
|
116
116
|
return assert(false, msg, DateTimeException);
|
|
117
117
|
}
|
|
@@ -132,7 +132,7 @@ export class ValueRange {
|
|
|
132
132
|
*/
|
|
133
133
|
checkValidIntValue(value, field) {
|
|
134
134
|
if (this.isValidIntValue(value) === false) {
|
|
135
|
-
throw new DateTimeException(
|
|
135
|
+
throw new DateTimeException(`Invalid int value for ${field}: ${value}`);
|
|
136
136
|
}
|
|
137
137
|
return value;
|
|
138
138
|
}
|
|
@@ -206,9 +206,9 @@ export class ValueRange {
|
|
|
206
206
|
* @return {string} a string representation of this range, not null
|
|
207
207
|
*/
|
|
208
208
|
toString() {
|
|
209
|
-
let str = this.minimum() + (this.minimum() !== this.largestMinimum() ?
|
|
209
|
+
let str = this.minimum() + (this.minimum() !== this.largestMinimum() ? `/${this.largestMinimum()}` : '');
|
|
210
210
|
str += ' - ';
|
|
211
|
-
str += this.smallestMaximum() + (this.smallestMaximum() !== this.maximum() ?
|
|
211
|
+
str += this.smallestMaximum() + (this.smallestMaximum() !== this.maximum() ? `/${this.maximum()}` : '');
|
|
212
212
|
return str;
|
|
213
213
|
}
|
|
214
214
|
|
|
@@ -251,7 +251,7 @@ export class ValueRange {
|
|
|
251
251
|
} else if (arguments.length === 4) {
|
|
252
252
|
return new ValueRange(arguments[0], arguments[1], arguments[2], arguments[3]);
|
|
253
253
|
} else {
|
|
254
|
-
return assert(false,
|
|
254
|
+
return assert(false, `Invalid number of arguments ${arguments.length}`, IllegalArgumentException);
|
|
255
255
|
}
|
|
256
256
|
}
|
|
257
257
|
}
|
package/src/use.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* @license BSD-3-Clause (see LICENSE in the root directory of this source tree)
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {SystemDefaultZoneRules} from './SystemDefaultZoneRules';
|
|
7
|
-
import {ZoneId} from '../ZoneId';
|
|
6
|
+
import { SystemDefaultZoneRules } from './SystemDefaultZoneRules';
|
|
7
|
+
import { ZoneId } from '../ZoneId';
|
|
8
8
|
|
|
9
9
|
export class SystemDefaultZoneId extends ZoneId {
|
|
10
10
|
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
* @license BSD-3-Clause (see LICENSE in the root directory of this source tree)
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {ZoneRules} from './ZoneRules';
|
|
7
|
-
import {ZoneOffset} from '../ZoneOffset';
|
|
8
|
-
import {DateTimeException} from '../errors';
|
|
6
|
+
import { ZoneRules } from './ZoneRules';
|
|
7
|
+
import { ZoneOffset } from '../ZoneOffset';
|
|
8
|
+
import { DateTimeException } from '../errors';
|
|
9
9
|
|
|
10
10
|
export class SystemDefaultZoneRules extends ZoneRules {
|
|
11
11
|
|
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
* @license BSD-3-Clause (see LICENSE in the root directory of this source tree)
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {requireNonNull} from '../assert';
|
|
8
|
-
import {IllegalArgumentException} from '../errors';
|
|
7
|
+
import { requireNonNull } from '../assert';
|
|
8
|
+
import { IllegalArgumentException } from '../errors';
|
|
9
9
|
|
|
10
|
-
import {Duration} from '../Duration';
|
|
11
|
-
import {LocalDateTime} from '../LocalDateTime';
|
|
10
|
+
import { Duration } from '../Duration';
|
|
11
|
+
import { LocalDateTime } from '../LocalDateTime';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* A transition between two offsets caused by a discontinuity in the local time-line.
|
|
@@ -281,9 +281,9 @@ export class ZoneOffsetTransition {
|
|
|
281
281
|
* @return {string} a string for debugging, not null
|
|
282
282
|
*/
|
|
283
283
|
toString() {
|
|
284
|
-
return
|
|
285
|
-
|
|
286
|
-
|
|
284
|
+
return `Transition[${this.isGap() ? 'Gap' : 'Overlap'
|
|
285
|
+
} at ${this._transition.toString()}${this._offsetBefore.toString()
|
|
286
|
+
} to ${this._offsetAfter}]`;
|
|
287
287
|
}
|
|
288
288
|
|
|
289
289
|
}
|
package/src/zone/ZoneRules.js
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
* @license BSD-3-Clause (see LICENSE in the root directory of this source tree)
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {requireNonNull, abstractMethodFail} from '../assert';
|
|
7
|
+
import { requireNonNull, abstractMethodFail } from '../assert';
|
|
8
8
|
|
|
9
|
-
import {Duration} from '../Duration';
|
|
10
|
-
import {Instant} from '../Instant';
|
|
9
|
+
import { Duration } from '../Duration';
|
|
10
|
+
import { Instant } from '../Instant';
|
|
11
11
|
|
|
12
12
|
export class ZoneRules {
|
|
13
13
|
|
|
@@ -458,7 +458,7 @@ class Fixed extends ZoneRules{
|
|
|
458
458
|
* @returns {string}
|
|
459
459
|
*/
|
|
460
460
|
toString() {
|
|
461
|
-
return
|
|
461
|
+
return `FixedRules:${this._offset.toString()}`;
|
|
462
462
|
}
|
|
463
463
|
|
|
464
464
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @license BSD-3-Clause (see LICENSE in the root directory of this source tree)
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {DateTimeException} from '../errors';
|
|
7
|
+
import { DateTimeException } from '../errors';
|
|
8
8
|
|
|
9
9
|
export class ZoneRulesProvider {
|
|
10
10
|
/**
|
|
@@ -18,7 +18,7 @@ export class ZoneRulesProvider {
|
|
|
18
18
|
* @return {ZoneRules}
|
|
19
19
|
*/
|
|
20
20
|
static getRules(zoneId){
|
|
21
|
-
throw new DateTimeException(
|
|
21
|
+
throw new DateTimeException(`unsupported ZoneId:${zoneId}`);
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import {MAX_SAFE_INTEGER, MIN_SAFE_INTEGER} from '../MathUtil';
|
|
2
|
-
import {requireInstance, requireNonNull} from '../assert';
|
|
3
|
-
import {TemporalAdjuster} from './TemporalAdjuster';
|
|
4
|
-
import {TemporalAmount} from './TemporalAmount';
|
|
5
|
-
import {TemporalUnit} from './TemporalUnit';
|
|
6
|
-
import {Temporal} from './Temporal';
|
|
7
|
-
|
|
8
|
-
export class DefaultInterfaceTemporal extends Temporal {
|
|
9
|
-
/**
|
|
10
|
-
* Returns an adjusted object of the same type as this object with the adjustment made.
|
|
11
|
-
* This adjusts this date-time according to the rules of the specified adjuster. A simple adjuster might simply set the one of the fields, such as the year field. A more complex adjuster might set the date to the last day of the month. A selection of common adjustments is provided in {@link TemporalAdjusters}. These include finding the "last day of the month" and "next Wednesday". The adjuster is responsible for handling special cases, such as the varying lengths of month and leap years.
|
|
12
|
-
*
|
|
13
|
-
* Some example code indicating how and why this method is used:
|
|
14
|
-
*
|
|
15
|
-
* <pre>
|
|
16
|
-
* date = date.with(Month.JULY); // most key classes implement TemporalAdjuster
|
|
17
|
-
* date = date.with(lastDayOfMonth()); // static import from TemporalAdjusters
|
|
18
|
-
* date = date.with(next(WEDNESDAY)); // static import from TemporalAdjusters and DayOfWeek
|
|
19
|
-
* </pre>
|
|
20
|
-
*
|
|
21
|
-
* ### Specification for implementors
|
|
22
|
-
* Implementations must not alter either this object. Instead, an adjusted copy of the original must be returned. This provides equivalent, safe behavior for immutable and mutable implementations.
|
|
23
|
-
*
|
|
24
|
-
* @param {TemporalAdjuster} adjuster - the adjuster to use, not null
|
|
25
|
-
* @return {Temporal} an object of the same type with the specified adjustment made, not null
|
|
26
|
-
* @throws DateTimeException - if unable to make the adjustment
|
|
27
|
-
* @throws ArithmeticException - if numeric overflow occurs
|
|
28
|
-
*/
|
|
29
|
-
withAdjuster(adjuster) {
|
|
30
|
-
requireNonNull(adjuster, 'adjuster');
|
|
31
|
-
requireInstance(adjuster, TemporalAdjuster, 'adjuster');
|
|
32
|
-
return adjuster.adjustInto(this);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Returns an object of the same type as this object with an amount added.
|
|
37
|
-
* This adjusts this temporal, adding according to the rules of the specified amount. The amount is typically a {@link Period} but may be any other type implementing the {@link TemporalAmount} interface, such as {@link Duration}.
|
|
38
|
-
*
|
|
39
|
-
* Some example code indicating how and why this method is used:
|
|
40
|
-
*
|
|
41
|
-
* <pre>
|
|
42
|
-
* date = date.plus(period); // add a Period instance
|
|
43
|
-
* date = date.plus(duration); // add a Duration instance
|
|
44
|
-
* date = date.plus(workingDays(6)); // example user-written workingDays method
|
|
45
|
-
* </pre>
|
|
46
|
-
*
|
|
47
|
-
* Note that calling plus followed by minus is not guaranteed to return the same date-time.
|
|
48
|
-
*
|
|
49
|
-
* ### Specification for implementors
|
|
50
|
-
* Implementations must not alter either this object. Instead, an adjusted copy of the original must be returned. This provides equivalent, safe behavior for immutable and mutable implementations.
|
|
51
|
-
*
|
|
52
|
-
* @param {TemporalAmount} amount - the amount to add, not null
|
|
53
|
-
* @return {Temporal} an object of the same type with the specified adjustment made, not null
|
|
54
|
-
* @throws DateTimeException - if the addition cannot be made
|
|
55
|
-
* @throws ArithmeticException - if numeric overflow occurs
|
|
56
|
-
*/
|
|
57
|
-
plusAmount(amount) {
|
|
58
|
-
requireNonNull(amount, 'amount');
|
|
59
|
-
requireInstance(amount, TemporalAmount, 'amount');
|
|
60
|
-
return amount.addTo(this);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Returns an object of the same type as this object with an amount subtracted.
|
|
65
|
-
* This adjusts this temporal, subtracting according to the rules of the specified amount. The
|
|
66
|
-
* amount is typically a {@link Period} but may be any other type implementing the {@link TemporalAmount} interface, such as Duration.
|
|
67
|
-
*
|
|
68
|
-
* Some example code indicating how and why this method is used:
|
|
69
|
-
*
|
|
70
|
-
* <pre>
|
|
71
|
-
* date = date.minus(period); // subtract a Period instance
|
|
72
|
-
* date = date.minus(duration); // subtract a Duration instance
|
|
73
|
-
* date = date.minus(workingDays(6)); // example user-written workingDays method
|
|
74
|
-
* </pre>
|
|
75
|
-
*
|
|
76
|
-
* Note that calling plus followed by minus is not guaranteed to return the same date-time.
|
|
77
|
-
*
|
|
78
|
-
* ### Specification for implementors
|
|
79
|
-
* Implementations must not alter either this object. Instead, an adjusted copy of the original
|
|
80
|
-
* must be returned. This provides equivalent, safe behavior for immutable and mutable
|
|
81
|
-
* implementations.
|
|
82
|
-
*
|
|
83
|
-
* @param {TemporalAmount} amount - the amount to subtract, not null
|
|
84
|
-
* @return {Temporal} an object of the same type with the specified adjustment made, not null
|
|
85
|
-
* @throws DateTimeException - if the subtraction cannot be made
|
|
86
|
-
* @throws ArithmeticException - if numeric overflow occurs
|
|
87
|
-
*/
|
|
88
|
-
minusAmount(amount) {
|
|
89
|
-
requireNonNull(amount, 'amount');
|
|
90
|
-
requireInstance(amount, TemporalAmount, 'amount');
|
|
91
|
-
return amount.subtractFrom(this);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Returns an object of the same type as this object with the specified period subtracted.
|
|
96
|
-
* This method returns a new object based on this one with the specified period subtracted. For example, on a {@link LocalDate}, this could be used to subtract a number of years, months or days. The returned object will have the same observable type as this object.
|
|
97
|
-
*
|
|
98
|
-
* In some cases, changing a field is not fully defined. For example, if the target object is a date representing the 31st March, then subtracting one month would be unclear. In cases like this, the field is responsible for resolving the result. Typically it will choose the previous valid date, which would be the last valid day of February in this example.
|
|
99
|
-
*
|
|
100
|
-
* If the implementation represents a date-time that has boundaries, such {@link as} LocalTime, then the permitted units must include the boundary unit, but no multiples of the boundary unit. For example, {@link LocalTime} must accept `DAYS` but not `WEEKS` or `MONTHS`.
|
|
101
|
-
*
|
|
102
|
-
* ### Specification for implementors
|
|
103
|
-
* Implementations must behave in a manor equivalent to the default method behavior.
|
|
104
|
-
* Implementations must not alter either this object or the specified temporal object. Instead, an adjusted copy of the original must be returned. This provides equivalent, safe behavior for immutable and mutable implementations.
|
|
105
|
-
*
|
|
106
|
-
* @param {number} amountToSubtract - the amount of the specified unit to subtract, may be negative
|
|
107
|
-
* @param {TemporalUnit} unit - the unit of the period to subtract, not null
|
|
108
|
-
* @return {Temporal} an object of the same type with the specified period subtracted, not null
|
|
109
|
-
* @throws DateTimeException - if the unit cannot be subtracted
|
|
110
|
-
* @throws ArithmeticException - if numeric overflow occurs
|
|
111
|
-
*/
|
|
112
|
-
minusAmountUnit(amountToSubtract, unit) {
|
|
113
|
-
requireNonNull(amountToSubtract, 'amountToSubtract');
|
|
114
|
-
requireNonNull(unit, 'unit');
|
|
115
|
-
requireInstance(unit, TemporalUnit, 'unit');
|
|
116
|
-
return (amountToSubtract === MIN_SAFE_INTEGER ? this.plusAmountUnit(MAX_SAFE_INTEGER, unit).plusAmountUnit(1, unit) : this.plusAmount(-amountToSubtract, unit));
|
|
117
|
-
}
|
|
118
|
-
}
|