@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
package/src/ZoneOffset.js
CHANGED
|
@@ -4,17 +4,17 @@
|
|
|
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 {DateTimeException} from './errors';
|
|
9
|
-
import {MathUtil} from './MathUtil';
|
|
7
|
+
import { requireNonNull } from './assert';
|
|
8
|
+
import { DateTimeException } from './errors';
|
|
9
|
+
import { MathUtil } from './MathUtil';
|
|
10
10
|
|
|
11
|
-
import {LocalTime} from './LocalTime';
|
|
12
|
-
import {ZoneId} from './ZoneId';
|
|
11
|
+
import { LocalTime } from './LocalTime';
|
|
12
|
+
import { ZoneId } from './ZoneId';
|
|
13
13
|
|
|
14
|
-
import {ChronoField} from './temporal/ChronoField';
|
|
15
|
-
import {TemporalQueries} from './temporal/TemporalQueries';
|
|
14
|
+
import { ChronoField } from './temporal/ChronoField';
|
|
15
|
+
import { TemporalQueries } from './temporal/TemporalQueries';
|
|
16
16
|
|
|
17
|
-
import {ZoneRules} from './zone/ZoneRules';
|
|
17
|
+
import { ZoneRules } from './zone/ZoneRules';
|
|
18
18
|
|
|
19
19
|
const SECONDS_CACHE = {};
|
|
20
20
|
const ID_CACHE = {};
|
|
@@ -74,9 +74,9 @@ export class ZoneOffset extends ZoneId {
|
|
|
74
74
|
const absTotalSeconds = Math.abs(totalSeconds);
|
|
75
75
|
const absHours = MathUtil.intDiv(absTotalSeconds, LocalTime.SECONDS_PER_HOUR);
|
|
76
76
|
const absMinutes = MathUtil.intMod(MathUtil.intDiv(absTotalSeconds, LocalTime.SECONDS_PER_MINUTE), LocalTime.MINUTES_PER_HOUR);
|
|
77
|
-
let buf =
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
let buf = `${totalSeconds < 0 ? '-' : '+'
|
|
78
|
+
}${absHours < 10 ? '0' : ''}${absHours
|
|
79
|
+
}${absMinutes < 10 ? ':0' : ':'}${absMinutes}`;
|
|
80
80
|
const absSeconds = MathUtil.intMod(absTotalSeconds, LocalTime.SECONDS_PER_MINUTE);
|
|
81
81
|
if (absSeconds !== 0) {
|
|
82
82
|
buf += (absSeconds < 10 ? ':0' : ':') + (absSeconds);
|
|
@@ -106,8 +106,8 @@ export class ZoneOffset extends ZoneId {
|
|
|
106
106
|
*/
|
|
107
107
|
static _validate(hours, minutes, seconds) {
|
|
108
108
|
if (hours < -18 || hours > 18) {
|
|
109
|
-
throw new DateTimeException(
|
|
110
|
-
|
|
109
|
+
throw new DateTimeException(`Zone offset hours not in valid range: value ${hours
|
|
110
|
+
} is not in the range -18 to 18`);
|
|
111
111
|
}
|
|
112
112
|
if (hours > 0) {
|
|
113
113
|
if (minutes < 0 || seconds < 0) {
|
|
@@ -121,12 +121,12 @@ export class ZoneOffset extends ZoneId {
|
|
|
121
121
|
throw new DateTimeException('Zone offset minutes and seconds must have the same sign');
|
|
122
122
|
}
|
|
123
123
|
if (Math.abs(minutes) > 59) {
|
|
124
|
-
throw new DateTimeException(
|
|
125
|
-
|
|
124
|
+
throw new DateTimeException(`Zone offset minutes not in valid range: abs(value) ${
|
|
125
|
+
Math.abs(minutes)} is not in the range 0 to 59`);
|
|
126
126
|
}
|
|
127
127
|
if (Math.abs(seconds) > 59) {
|
|
128
|
-
throw new DateTimeException(
|
|
129
|
-
|
|
128
|
+
throw new DateTimeException(`Zone offset seconds not in valid range: abs(value) ${
|
|
129
|
+
Math.abs(seconds)} is not in the range 0 to 59`);
|
|
130
130
|
}
|
|
131
131
|
if (Math.abs(hours) === 18 && (Math.abs(minutes) > 0 || Math.abs(seconds) > 0)) {
|
|
132
132
|
throw new DateTimeException('Zone offset not in valid range: -18:00 to +18:00');
|
|
@@ -176,7 +176,7 @@ export class ZoneOffset extends ZoneId {
|
|
|
176
176
|
let hours, minutes, seconds;
|
|
177
177
|
switch (offsetId.length) {
|
|
178
178
|
case 2:
|
|
179
|
-
offsetId = offsetId[0]
|
|
179
|
+
offsetId = `${offsetId[0]}0${offsetId[1]}`; // fallthru
|
|
180
180
|
// eslint-disable-next-line no-fallthrough
|
|
181
181
|
case 3:
|
|
182
182
|
hours = ZoneOffset._parseNumber(offsetId, 1, false);
|
|
@@ -204,11 +204,11 @@ export class ZoneOffset extends ZoneId {
|
|
|
204
204
|
seconds = ZoneOffset._parseNumber(offsetId, 7, true);
|
|
205
205
|
break;
|
|
206
206
|
default:
|
|
207
|
-
throw new DateTimeException(
|
|
207
|
+
throw new DateTimeException(`Invalid ID for ZoneOffset, invalid format: ${offsetId}`);
|
|
208
208
|
}
|
|
209
209
|
const first = offsetId[0];
|
|
210
210
|
if (first !== '+' && first !== '-') {
|
|
211
|
-
throw new DateTimeException(
|
|
211
|
+
throw new DateTimeException(`Invalid ID for ZoneOffset, plus/minus not found when expected: ${offsetId}`);
|
|
212
212
|
}
|
|
213
213
|
if (first === '-') {
|
|
214
214
|
return ZoneOffset.ofHoursMinutesSeconds(-hours, -minutes, -seconds);
|
|
@@ -227,12 +227,12 @@ export class ZoneOffset extends ZoneId {
|
|
|
227
227
|
*/
|
|
228
228
|
static _parseNumber(offsetId, pos, precededByColon) {
|
|
229
229
|
if (precededByColon && offsetId[pos - 1] !== ':') {
|
|
230
|
-
throw new DateTimeException(
|
|
230
|
+
throw new DateTimeException(`Invalid ID for ZoneOffset, colon not found when expected: ${offsetId}`);
|
|
231
231
|
}
|
|
232
232
|
const ch1 = offsetId[pos];
|
|
233
233
|
const ch2 = offsetId[pos + 1];
|
|
234
234
|
if (ch1 < '0' || ch1 > '9' || ch2 < '0' || ch2 > '9') {
|
|
235
|
-
throw new DateTimeException(
|
|
235
|
+
throw new DateTimeException(`Invalid ID for ZoneOffset, non numeric characters found: ${offsetId}`);
|
|
236
236
|
}
|
|
237
237
|
return (ch1.charCodeAt(0) - 48) * 10 + (ch2.charCodeAt(0) - 48);
|
|
238
238
|
}
|
|
@@ -362,7 +362,7 @@ export class ZoneOffset extends ZoneId {
|
|
|
362
362
|
if (field === ChronoField.OFFSET_SECONDS) {
|
|
363
363
|
return this._totalSeconds;
|
|
364
364
|
} else if (field instanceof ChronoField) {
|
|
365
|
-
throw new DateTimeException(
|
|
365
|
+
throw new DateTimeException(`Unsupported field: ${field}`);
|
|
366
366
|
}
|
|
367
367
|
return field.getFrom(this);
|
|
368
368
|
}
|
package/src/ZoneRegion.js
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
import {ZoneId} from './ZoneId';
|
|
9
|
-
import {ZoneRulesProvider} from './zone/ZoneRulesProvider';
|
|
8
|
+
import { ZoneId } from './ZoneId';
|
|
9
|
+
import { ZoneRulesProvider } from './zone/ZoneRulesProvider';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* A geographical region where the same time-zone rules apply.
|
package/src/ZonedDateTime.js
CHANGED
|
@@ -4,25 +4,25 @@
|
|
|
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 {DateTimeException, IllegalArgumentException} from './errors';
|
|
9
|
-
import {MathUtil} from './MathUtil';
|
|
10
|
-
|
|
11
|
-
import {Clock} from './Clock';
|
|
12
|
-
import {Instant} from './Instant';
|
|
13
|
-
import {LocalDate} from './LocalDate';
|
|
14
|
-
import {LocalDateTime} from './LocalDateTime';
|
|
15
|
-
import {LocalTime} from './LocalTime';
|
|
16
|
-
import {OffsetDateTime} from './OffsetDateTime';
|
|
17
|
-
import {ZoneId} from './ZoneId';
|
|
18
|
-
import {ZoneOffset} from './ZoneOffset';
|
|
19
|
-
|
|
20
|
-
import {ChronoZonedDateTime} from './chrono/ChronoZonedDateTime';
|
|
21
|
-
import {DateTimeFormatter} from './format/DateTimeFormatter';
|
|
22
|
-
import {ChronoField} from './temporal/ChronoField';
|
|
23
|
-
import {ChronoUnit} from './temporal/ChronoUnit';
|
|
24
|
-
import {createTemporalQuery} from './temporal/TemporalQuery';
|
|
25
|
-
import {TemporalQueries} from './temporal/TemporalQueries';
|
|
7
|
+
import { requireNonNull } from './assert';
|
|
8
|
+
import { DateTimeException, IllegalArgumentException } from './errors';
|
|
9
|
+
import { MathUtil } from './MathUtil';
|
|
10
|
+
|
|
11
|
+
import { Clock } from './Clock';
|
|
12
|
+
import { Instant } from './Instant';
|
|
13
|
+
import { LocalDate } from './LocalDate';
|
|
14
|
+
import { LocalDateTime } from './LocalDateTime';
|
|
15
|
+
import { LocalTime } from './LocalTime';
|
|
16
|
+
import { OffsetDateTime } from './OffsetDateTime';
|
|
17
|
+
import { ZoneId } from './ZoneId';
|
|
18
|
+
import { ZoneOffset } from './ZoneOffset';
|
|
19
|
+
|
|
20
|
+
import { ChronoZonedDateTime } from './chrono/ChronoZonedDateTime';
|
|
21
|
+
import { DateTimeFormatter } from './format/DateTimeFormatter';
|
|
22
|
+
import { ChronoField } from './temporal/ChronoField';
|
|
23
|
+
import { ChronoUnit } from './temporal/ChronoUnit';
|
|
24
|
+
import { createTemporalQuery } from './temporal/TemporalQuery';
|
|
25
|
+
import { TemporalQueries } from './temporal/TemporalQueries';
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* A date-time with a time-zone in the ISO-8601 calendar system,
|
|
@@ -378,12 +378,12 @@ export class ZonedDateTime extends ChronoZonedDateTime {
|
|
|
378
378
|
if (trans != null && trans.isGap()) {
|
|
379
379
|
// error message says daylight savings for simplicity
|
|
380
380
|
// even though there are other kinds of gaps
|
|
381
|
-
throw new DateTimeException(
|
|
382
|
-
|
|
383
|
-
|
|
381
|
+
throw new DateTimeException(`LocalDateTime ${localDateTime
|
|
382
|
+
} does not exist in zone ${zone
|
|
383
|
+
} due to a gap in the local time-line, typically caused by daylight savings`);
|
|
384
384
|
}
|
|
385
|
-
throw new DateTimeException(
|
|
386
|
-
localDateTime
|
|
385
|
+
throw new DateTimeException(`ZoneOffset "${offset}" is not valid for LocalDateTime "${
|
|
386
|
+
localDateTime}" in zone "${zone}"`);
|
|
387
387
|
}
|
|
388
388
|
return new ZonedDateTime(localDateTime, offset, zone);
|
|
389
389
|
}
|
|
@@ -1029,7 +1029,7 @@ export class ZonedDateTime extends ChronoZonedDateTime {
|
|
|
1029
1029
|
* @throws DateTimeException if the adjustment cannot be made
|
|
1030
1030
|
* @throws ArithmeticException if numeric overflow occurs
|
|
1031
1031
|
*/
|
|
1032
|
-
|
|
1032
|
+
_withAdjuster(adjuster) {
|
|
1033
1033
|
// optimizations
|
|
1034
1034
|
if (adjuster instanceof LocalDate) {
|
|
1035
1035
|
return this._resolveLocal(LocalDateTime.of(adjuster, this._dateTime.toLocalTime()));
|
|
@@ -1043,8 +1043,7 @@ export class ZonedDateTime extends ChronoZonedDateTime {
|
|
|
1043
1043
|
} else if (adjuster instanceof ZoneOffset) {
|
|
1044
1044
|
return this._resolveOffset(adjuster);
|
|
1045
1045
|
}
|
|
1046
|
-
|
|
1047
|
-
return adjuster.adjustInto(this);
|
|
1046
|
+
return super._withAdjuster(adjuster);
|
|
1048
1047
|
}
|
|
1049
1048
|
|
|
1050
1049
|
/**
|
|
@@ -1098,7 +1097,7 @@ export class ZonedDateTime extends ChronoZonedDateTime {
|
|
|
1098
1097
|
* @throws UnsupportedTemporalTypeException if the field is not supported
|
|
1099
1098
|
* @throws ArithmeticException if numeric overflow occurs
|
|
1100
1099
|
*/
|
|
1101
|
-
|
|
1100
|
+
_withField(field, newValue) {
|
|
1102
1101
|
if (field instanceof ChronoField) {
|
|
1103
1102
|
switch (field) {
|
|
1104
1103
|
case ChronoField.INSTANT_SECONDS: return ZonedDateTime._create(newValue, this.nano(), this._zone);
|
|
@@ -1325,27 +1324,6 @@ export class ZonedDateTime extends ChronoZonedDateTime {
|
|
|
1325
1324
|
|
|
1326
1325
|
//-----------------------------------------------------------------------
|
|
1327
1326
|
|
|
1328
|
-
/**
|
|
1329
|
-
* Returns a copy of this date-time with the specified period added.
|
|
1330
|
-
*
|
|
1331
|
-
* This method returns a new date-time based on this time with the specified period added.
|
|
1332
|
-
* The amount is typically {@link Period} but may be any other type implementing
|
|
1333
|
-
* the {@link TemporalAmount} interface.
|
|
1334
|
-
* The calculation is delegated to the specified adjuster, which typically calls
|
|
1335
|
-
* back to {@link plus}.
|
|
1336
|
-
*
|
|
1337
|
-
* This instance is immutable and unaffected by this method call.
|
|
1338
|
-
*
|
|
1339
|
-
* @param {!TemporalAmount} amount - the amount to add, not null
|
|
1340
|
-
* @return {ZonedDateTime} a {@link ZonedDateTime} based on this date-time with the addition made, not null
|
|
1341
|
-
* @throws DateTimeException if the addition cannot be made
|
|
1342
|
-
* @throws ArithmeticException if numeric overflow occurs
|
|
1343
|
-
*/
|
|
1344
|
-
plusAmount(amount) {
|
|
1345
|
-
requireNonNull(amount);
|
|
1346
|
-
return amount.addTo(this);
|
|
1347
|
-
}
|
|
1348
|
-
|
|
1349
1327
|
/**
|
|
1350
1328
|
* Returns a copy of this date-time with the specified period added.
|
|
1351
1329
|
*
|
|
@@ -1375,7 +1353,7 @@ export class ZonedDateTime extends ChronoZonedDateTime {
|
|
|
1375
1353
|
* @return {ZonedDateTime} a {@link ZonedDateTime} based on this date-time with the specified period added, not null
|
|
1376
1354
|
* @throws DateTimeException if the unit cannot be added to this type
|
|
1377
1355
|
*/
|
|
1378
|
-
|
|
1356
|
+
_plusUnit(amountToAdd, unit) {
|
|
1379
1357
|
if (unit instanceof ChronoUnit) {
|
|
1380
1358
|
if (unit.isDateBased()) {
|
|
1381
1359
|
return this._resolveLocal(this._dateTime.plus(amountToAdd, unit));
|
|
@@ -1556,27 +1534,6 @@ export class ZonedDateTime extends ChronoZonedDateTime {
|
|
|
1556
1534
|
|
|
1557
1535
|
//-----------------------------------------------------------------------
|
|
1558
1536
|
|
|
1559
|
-
/**
|
|
1560
|
-
* Returns a copy of this date-time with the specified period subtracted.
|
|
1561
|
-
*
|
|
1562
|
-
* This method returns a new date-time based on this time with the specified period subtracted.
|
|
1563
|
-
* The amount is typically {@link Period} but may be any other type implementing
|
|
1564
|
-
* the {@link TemporalAmount} interface.
|
|
1565
|
-
* The calculation is delegated to the specified adjuster, which typically calls
|
|
1566
|
-
* back to {@link minus}.
|
|
1567
|
-
*
|
|
1568
|
-
* This instance is immutable and unaffected by this method call.
|
|
1569
|
-
*
|
|
1570
|
-
* @param {TemporalAmount} amount - the amount to subtract, not null
|
|
1571
|
-
* @return {ZonedDateTime} a {@link ZonedDateTime} based on this date-time with the subtraction made, not null
|
|
1572
|
-
* @throws DateTimeException if the subtraction cannot be made
|
|
1573
|
-
* @throws ArithmeticException if numeric overflow occurs
|
|
1574
|
-
*/
|
|
1575
|
-
minusAmount(amount) {
|
|
1576
|
-
requireNonNull(amount, 'amount');
|
|
1577
|
-
return amount.subtractFrom(this);
|
|
1578
|
-
}
|
|
1579
|
-
|
|
1580
1537
|
/**
|
|
1581
1538
|
* Returns a copy of this date-time with the specified period subtracted.
|
|
1582
1539
|
*
|
|
@@ -1606,8 +1563,8 @@ export class ZonedDateTime extends ChronoZonedDateTime {
|
|
|
1606
1563
|
* @return {ZonedDateTime} a {@link ZonedDateTime} based on this date-time with the specified period subtracted, not null
|
|
1607
1564
|
* @throws DateTimeException if the unit cannot be added to this type
|
|
1608
1565
|
*/
|
|
1609
|
-
|
|
1610
|
-
return this.
|
|
1566
|
+
_minusUnit(amountToSubtract, unit) {
|
|
1567
|
+
return this._plusUnit(-1 * amountToSubtract, unit);
|
|
1611
1568
|
}
|
|
1612
1569
|
|
|
1613
1570
|
//-----------------------------------------------------------------------
|
|
@@ -1974,7 +1931,7 @@ export class ZonedDateTime extends ChronoZonedDateTime {
|
|
|
1974
1931
|
toString() {
|
|
1975
1932
|
let str = this._dateTime.toString() + this._offset.toString();
|
|
1976
1933
|
if (this._offset !== this._zone) {
|
|
1977
|
-
str +=
|
|
1934
|
+
str += `[${this._zone.toString()}]`;
|
|
1978
1935
|
}
|
|
1979
1936
|
return str;
|
|
1980
1937
|
}
|
package/src/_init.js
CHANGED
|
@@ -3,31 +3,31 @@
|
|
|
3
3
|
* @license BSD-3-Clause (see LICENSE in the root directory of this source tree)
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {_init as ZoneOffsetInit} from './ZoneOffset';
|
|
7
|
-
import {_init as DayOfWeekInit} from './DayOfWeek';
|
|
8
|
-
import {_init as DurationInit} from './Duration';
|
|
9
|
-
import {_init as InstantInit} from './Instant';
|
|
10
|
-
import {_init as LocalDateInit} from './LocalDate';
|
|
11
|
-
import {_init as LocalTimeInit} from './LocalTime';
|
|
12
|
-
import {_init as LocalDateTimeInit} from './LocalDateTime';
|
|
13
|
-
import {_init as MonthInit} from './Month';
|
|
14
|
-
import {_init as MonthDayInit} from './MonthDay';
|
|
15
|
-
import {_init as OffsetDateTimeInit} from './OffsetDateTime';
|
|
16
|
-
import {_init as OffsetTimeInit} from './OffsetTime';
|
|
17
|
-
import {_init as PeriodInit} from './Period';
|
|
18
|
-
import {_init as YearInit} from './Year';
|
|
19
|
-
import {_init as YearConstantsInit} from './YearConstants';
|
|
20
|
-
import {_init as YearMonthInit} from './YearMonth';
|
|
21
|
-
import {_init as ZonedDateTimeInit} from './ZonedDateTime';
|
|
22
|
-
import {_init as IsoChronologyInit} from './chrono/IsoChronology';
|
|
23
|
-
import {_init as DateTimeFormatterInit} from './format/DateTimeFormatter';
|
|
24
|
-
import {_init as ChronoFieldInit} from './temporal/ChronoField';
|
|
25
|
-
import {_init as ChronoUnitInit} from './temporal/ChronoUnit';
|
|
26
|
-
import {_init as IsoFieldsInit} from './temporal/IsoFields';
|
|
27
|
-
import {_init as DateTimeFormatterBuilderInit} from './format/DateTimeFormatterBuilder';
|
|
6
|
+
import { _init as ZoneOffsetInit } from './ZoneOffset';
|
|
7
|
+
import { _init as DayOfWeekInit } from './DayOfWeek';
|
|
8
|
+
import { _init as DurationInit } from './Duration';
|
|
9
|
+
import { _init as InstantInit } from './Instant';
|
|
10
|
+
import { _init as LocalDateInit } from './LocalDate';
|
|
11
|
+
import { _init as LocalTimeInit } from './LocalTime';
|
|
12
|
+
import { _init as LocalDateTimeInit } from './LocalDateTime';
|
|
13
|
+
import { _init as MonthInit } from './Month';
|
|
14
|
+
import { _init as MonthDayInit } from './MonthDay';
|
|
15
|
+
import { _init as OffsetDateTimeInit } from './OffsetDateTime';
|
|
16
|
+
import { _init as OffsetTimeInit } from './OffsetTime';
|
|
17
|
+
import { _init as PeriodInit } from './Period';
|
|
18
|
+
import { _init as YearInit } from './Year';
|
|
19
|
+
import { _init as YearConstantsInit } from './YearConstants';
|
|
20
|
+
import { _init as YearMonthInit } from './YearMonth';
|
|
21
|
+
import { _init as ZonedDateTimeInit } from './ZonedDateTime';
|
|
22
|
+
import { _init as IsoChronologyInit } from './chrono/IsoChronology';
|
|
23
|
+
import { _init as DateTimeFormatterInit } from './format/DateTimeFormatter';
|
|
24
|
+
import { _init as ChronoFieldInit } from './temporal/ChronoField';
|
|
25
|
+
import { _init as ChronoUnitInit } from './temporal/ChronoUnit';
|
|
26
|
+
import { _init as IsoFieldsInit } from './temporal/IsoFields';
|
|
27
|
+
import { _init as DateTimeFormatterBuilderInit } from './format/DateTimeFormatterBuilder';
|
|
28
28
|
|
|
29
|
-
import {_init as TemporalQueriesInit} from './temporal/TemporalQueriesFactory';
|
|
30
|
-
import {_init as ZoneIdInit} from './ZoneIdFactory';
|
|
29
|
+
import { _init as TemporalQueriesInit } from './temporal/TemporalQueriesFactory';
|
|
30
|
+
import { _init as ZoneIdInit } from './ZoneIdFactory';
|
|
31
31
|
|
|
32
32
|
let isInit = false;
|
|
33
33
|
|
package/src/assert.js
CHANGED
|
@@ -2,8 +2,15 @@
|
|
|
2
2
|
* @copyright (c) 2016, Philipp Thürwächter & Pattrick Hüper
|
|
3
3
|
* @license BSD-3-Clause (see LICENSE in the root directory of this source tree)
|
|
4
4
|
*/
|
|
5
|
-
import {NullPointerException, IllegalArgumentException} from './errors';
|
|
5
|
+
import { NullPointerException, IllegalArgumentException } from './errors';
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* @private
|
|
9
|
+
*
|
|
10
|
+
* @param assertion
|
|
11
|
+
* @param msg
|
|
12
|
+
* @param error
|
|
13
|
+
*/
|
|
7
14
|
export function assert(assertion, msg, error) {
|
|
8
15
|
if(!assertion){
|
|
9
16
|
if (error) {
|
|
@@ -14,20 +21,40 @@ export function assert(assertion, msg, error) {
|
|
|
14
21
|
}
|
|
15
22
|
}
|
|
16
23
|
|
|
24
|
+
/**
|
|
25
|
+
* @private
|
|
26
|
+
*
|
|
27
|
+
* @param value
|
|
28
|
+
* @param parameterName
|
|
29
|
+
* @returns {*}
|
|
30
|
+
*/
|
|
17
31
|
export function requireNonNull(value, parameterName) {
|
|
18
32
|
if (value == null) {
|
|
19
|
-
throw new NullPointerException(parameterName
|
|
33
|
+
throw new NullPointerException(`${parameterName} must not be null`);
|
|
20
34
|
}
|
|
21
35
|
return value;
|
|
22
36
|
}
|
|
23
37
|
|
|
38
|
+
/**
|
|
39
|
+
* @private
|
|
40
|
+
*
|
|
41
|
+
* @param value
|
|
42
|
+
* @param _class
|
|
43
|
+
* @param parameterName
|
|
44
|
+
* @returns {_class}
|
|
45
|
+
*/
|
|
24
46
|
export function requireInstance(value, _class, parameterName) {
|
|
25
47
|
if (!(value instanceof _class)) {
|
|
26
|
-
throw new IllegalArgumentException(parameterName
|
|
48
|
+
throw new IllegalArgumentException(`${parameterName} must be an instance of ${_class.name ? _class.name : _class}${value && value.constructor && value.constructor.name ? `, but is ${value.constructor.name}` : ''}`);
|
|
27
49
|
}
|
|
28
50
|
return value;
|
|
29
51
|
}
|
|
30
52
|
|
|
53
|
+
/**
|
|
54
|
+
* @private
|
|
55
|
+
*
|
|
56
|
+
* @param methodName
|
|
57
|
+
*/
|
|
31
58
|
export function abstractMethodFail(methodName){
|
|
32
|
-
throw new TypeError(
|
|
59
|
+
throw new TypeError(`abstract method "${methodName}" is not implemented`);
|
|
33
60
|
}
|
|
@@ -4,15 +4,15 @@
|
|
|
4
4
|
* @license BSD-3-Clause (see LICENSE in the root directory of this source tree)
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {requireNonNull, requireInstance} from '../assert';
|
|
7
|
+
import { requireNonNull, requireInstance } from '../assert';
|
|
8
8
|
|
|
9
|
-
import {ChronoField} from '../temporal/ChronoField';
|
|
10
|
-
import {ChronoUnit} from '../temporal/ChronoUnit';
|
|
11
|
-
import {DateTimeFormatter} from '../format/DateTimeFormatter';
|
|
12
|
-
import {TemporalQueries} from '../temporal/TemporalQueries';
|
|
13
|
-
import {
|
|
9
|
+
import { ChronoField } from '../temporal/ChronoField';
|
|
10
|
+
import { ChronoUnit } from '../temporal/ChronoUnit';
|
|
11
|
+
import { DateTimeFormatter } from '../format/DateTimeFormatter';
|
|
12
|
+
import { TemporalQueries } from '../temporal/TemporalQueries';
|
|
13
|
+
import { Temporal } from '../temporal/Temporal';
|
|
14
14
|
|
|
15
|
-
import {LocalDate} from '../LocalDate';
|
|
15
|
+
import { LocalDate } from '../LocalDate';
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* A date without time-of-day or time-zone in an arbitrary chronology, intended
|
|
@@ -180,7 +180,7 @@ import {LocalDate} from '../LocalDate';
|
|
|
180
180
|
* In JDK 8, this is an interface with default methods.
|
|
181
181
|
* Since there are no default methods in JDK 7, an abstract class is used.
|
|
182
182
|
*/
|
|
183
|
-
export class ChronoLocalDate extends
|
|
183
|
+
export class ChronoLocalDate extends Temporal {
|
|
184
184
|
|
|
185
185
|
isSupported(fieldOrUnit) {
|
|
186
186
|
if (fieldOrUnit instanceof ChronoField) {
|
|
@@ -4,16 +4,16 @@
|
|
|
4
4
|
* @license BSD-3-Clause (see LICENSE in the root directory of this source tree)
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {requireNonNull, requireInstance} from '../assert';
|
|
8
|
-
import {MathUtil} from '../MathUtil';
|
|
7
|
+
import { requireNonNull, requireInstance } from '../assert';
|
|
8
|
+
import { MathUtil } from '../MathUtil';
|
|
9
9
|
|
|
10
|
-
import {LocalDate} from '../LocalDate';
|
|
11
|
-
import {Instant} from '../Instant';
|
|
12
|
-
import {ZoneOffset} from '../ZoneOffset';
|
|
13
|
-
import {ChronoUnit} from '../temporal/ChronoUnit';
|
|
14
|
-
import {ChronoField} from '../temporal/ChronoField';
|
|
15
|
-
import {
|
|
16
|
-
import {TemporalQueries} from '../temporal/TemporalQueries';
|
|
10
|
+
import { LocalDate } from '../LocalDate';
|
|
11
|
+
import { Instant } from '../Instant';
|
|
12
|
+
import { ZoneOffset } from '../ZoneOffset';
|
|
13
|
+
import { ChronoUnit } from '../temporal/ChronoUnit';
|
|
14
|
+
import { ChronoField } from '../temporal/ChronoField';
|
|
15
|
+
import { Temporal } from '../temporal/Temporal';
|
|
16
|
+
import { TemporalQueries } from '../temporal/TemporalQueries';
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* A date-time without a time-zone in an arbitrary chronology, intended
|
|
@@ -49,7 +49,7 @@ import {TemporalQueries} from '../temporal/TemporalQueries';
|
|
|
49
49
|
*
|
|
50
50
|
* @param D the date type
|
|
51
51
|
*/
|
|
52
|
-
export class ChronoLocalDateTime extends
|
|
52
|
+
export class ChronoLocalDateTime extends Temporal {
|
|
53
53
|
/* <D extends ChronoLocalDate>
|
|
54
54
|
extends DefaultInterfaceTemporal
|
|
55
55
|
implements Temporal, TemporalAdjuster, Comparable<ChronoLocalDateTime<?>> */
|
|
@@ -4,16 +4,16 @@
|
|
|
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 {Instant} from '../Instant';
|
|
9
|
-
import {LocalDate} from '../LocalDate';
|
|
10
|
-
import {MathUtil} from '../MathUtil';
|
|
7
|
+
import { requireNonNull } from '../assert';
|
|
8
|
+
import { Instant } from '../Instant';
|
|
9
|
+
import { LocalDate } from '../LocalDate';
|
|
10
|
+
import { MathUtil } from '../MathUtil';
|
|
11
11
|
|
|
12
|
-
import {ChronoUnit} from '../temporal/ChronoUnit';
|
|
13
|
-
import {
|
|
14
|
-
import {TemporalQueries} from '../temporal/TemporalQueries';
|
|
12
|
+
import { ChronoUnit } from '../temporal/ChronoUnit';
|
|
13
|
+
import { Temporal } from '../temporal/Temporal';
|
|
14
|
+
import { TemporalQueries } from '../temporal/TemporalQueries';
|
|
15
15
|
|
|
16
|
-
export class ChronoZonedDateTime
|
|
16
|
+
export class ChronoZonedDateTime extends Temporal {
|
|
17
17
|
query(query) {
|
|
18
18
|
if (query === TemporalQueries.zoneId() || query === TemporalQueries.zone()) {
|
|
19
19
|
return this.zone();
|
|
@@ -4,19 +4,19 @@
|
|
|
4
4
|
* @license BSD-3-Clause (see LICENSE in the root directory of this source tree)
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {Enum} from '../Enum';
|
|
8
|
-
import {requireNonNull} from '../assert';
|
|
9
|
-
import {DateTimeException} from '../errors';
|
|
10
|
-
import {MathUtil} from '../MathUtil';
|
|
7
|
+
import { Enum } from '../Enum';
|
|
8
|
+
import { requireNonNull } from '../assert';
|
|
9
|
+
import { DateTimeException } from '../errors';
|
|
10
|
+
import { MathUtil } from '../MathUtil';
|
|
11
11
|
|
|
12
|
-
import {DayOfWeek} from '../DayOfWeek';
|
|
13
|
-
import {LocalDate} from '../LocalDate';
|
|
14
|
-
import {Month} from '../Month';
|
|
15
|
-
import {Year} from '../Year';
|
|
12
|
+
import { DayOfWeek } from '../DayOfWeek';
|
|
13
|
+
import { LocalDate } from '../LocalDate';
|
|
14
|
+
import { Month } from '../Month';
|
|
15
|
+
import { Year } from '../Year';
|
|
16
16
|
|
|
17
|
-
import {ChronoField} from '../temporal/ChronoField';
|
|
18
|
-
import {ResolverStyle} from '../format/ResolverStyle';
|
|
19
|
-
import {TemporalAdjusters} from '../temporal/TemporalAdjusters';
|
|
17
|
+
import { ChronoField } from '../temporal/ChronoField';
|
|
18
|
+
import { ResolverStyle } from '../format/ResolverStyle';
|
|
19
|
+
import { TemporalAdjusters } from '../temporal/TemporalAdjusters';
|
|
20
20
|
|
|
21
21
|
export class IsoChronology extends Enum{
|
|
22
22
|
/**
|
|
@@ -56,7 +56,7 @@ export class IsoChronology extends Enum{
|
|
|
56
56
|
requireNonNull(field, 'field');
|
|
57
57
|
const current = fieldValues.get(field);
|
|
58
58
|
if (current != null && current !== value) {
|
|
59
|
-
throw new DateTimeException(
|
|
59
|
+
throw new DateTimeException(`Invalid state, field: ${field} ${current} conflicts with ${field} ${value}`);
|
|
60
60
|
}
|
|
61
61
|
fieldValues.put(field, value);
|
|
62
62
|
}
|
|
@@ -102,7 +102,7 @@ export class IsoChronology extends Enum{
|
|
|
102
102
|
} else if (era === 0) {
|
|
103
103
|
this._updateResolveMap(fieldValues, ChronoField.YEAR, MathUtil.safeSubtract(1, yoeLong));
|
|
104
104
|
} else {
|
|
105
|
-
throw new DateTimeException(
|
|
105
|
+
throw new DateTimeException(`Invalid value for era: ${era}`);
|
|
106
106
|
}
|
|
107
107
|
} else if (fieldValues.containsKey(ChronoField.ERA)) {
|
|
108
108
|
ChronoField.ERA.checkValidValue(fieldValues.get(ChronoField.ERA)); // always validated
|
package/src/convert.js
CHANGED
|
@@ -3,23 +3,27 @@
|
|
|
3
3
|
* @license BSD-3-Clause (see LICENSE in the root directory of this source tree)
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {IllegalArgumentException} from './errors';
|
|
6
|
+
import { IllegalArgumentException } from './errors';
|
|
7
7
|
|
|
8
|
-
import {LocalDate} from './LocalDate';
|
|
9
|
-
import {LocalDateTime} from './LocalDateTime';
|
|
10
|
-
import {ZonedDateTime} from './ZonedDateTime';
|
|
11
|
-
import {ZoneId} from './ZoneId';
|
|
8
|
+
import { LocalDate } from './LocalDate';
|
|
9
|
+
import { LocalDateTime } from './LocalDateTime';
|
|
10
|
+
import { ZonedDateTime } from './ZonedDateTime';
|
|
11
|
+
import { ZoneId } from './ZoneId';
|
|
12
|
+
import { Instant } from './Instant';
|
|
12
13
|
|
|
13
14
|
class ToNativeJsConverter {
|
|
14
15
|
/**
|
|
15
|
-
* @param {!(LocalDate|LocalDateTime|ZonedDateTime)} temporal - a joda temporal instance
|
|
16
|
+
* @param {!(LocalDate|LocalDateTime|ZonedDateTime|Instant)} temporal - a joda temporal instance
|
|
16
17
|
* @param {ZoneId} [zone] - the zone of the temporal,
|
|
17
18
|
* the default value for LocalDate and LocalDateTime is ZoneId.systemDefault().
|
|
18
19
|
*/
|
|
19
20
|
constructor(temporal, zone){
|
|
20
21
|
let zonedDateTime;
|
|
21
22
|
|
|
22
|
-
if(temporal instanceof
|
|
23
|
+
if(temporal instanceof Instant) {
|
|
24
|
+
this.instant = temporal;
|
|
25
|
+
return;
|
|
26
|
+
} else if(temporal instanceof LocalDate) {
|
|
23
27
|
zone = zone == null ? ZoneId.systemDefault() : zone;
|
|
24
28
|
zonedDateTime = temporal.atStartOfDay(zone);
|
|
25
29
|
} else if (temporal instanceof LocalDateTime) {
|
|
@@ -32,7 +36,7 @@ class ToNativeJsConverter {
|
|
|
32
36
|
zonedDateTime = temporal.withZoneSameInstant(zone);
|
|
33
37
|
}
|
|
34
38
|
} else {
|
|
35
|
-
throw new IllegalArgumentException(
|
|
39
|
+
throw new IllegalArgumentException(`unsupported instance for convert operation:${temporal}`);
|
|
36
40
|
}
|
|
37
41
|
|
|
38
42
|
this.instant = zonedDateTime.toInstant();
|
package/src/errors.js
CHANGED
|
@@ -33,16 +33,16 @@ export const NullPointerException = createErrorType('NullPointerException');
|
|
|
33
33
|
function messageWithCause(message, cause = null) {
|
|
34
34
|
let msg = message || this.name;
|
|
35
35
|
if (cause !== null && cause instanceof Error) {
|
|
36
|
-
msg +=
|
|
36
|
+
msg += `\n-------\nCaused by: ${cause.stack}\n-------\n`;
|
|
37
37
|
}
|
|
38
38
|
this.message = msg;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
function messageForDateTimeParseException(message, text = '', index = 0, cause = null) {
|
|
42
42
|
let msg = message || this.name;
|
|
43
|
-
msg +=
|
|
43
|
+
msg += `: ${text}, at index: ${index}`;
|
|
44
44
|
if (cause !== null && cause instanceof Error) {
|
|
45
|
-
msg +=
|
|
45
|
+
msg += `\n-------\nCaused by: ${cause.stack}\n-------\n`;
|
|
46
46
|
}
|
|
47
47
|
this.message = msg;
|
|
48
48
|
this.parsedString = () => {
|