@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/LocalDate.js
CHANGED
|
@@ -4,33 +4,33 @@
|
|
|
4
4
|
* @license BSD-3-Clause (see LICENSE in the root directory of this source tree)
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {assert, requireNonNull, requireInstance} from './assert';
|
|
8
|
-
|
|
9
|
-
import {MathUtil} from './MathUtil';
|
|
10
|
-
import {DateTimeException, UnsupportedTemporalTypeException, NullPointerException, IllegalArgumentException} from './errors';
|
|
11
|
-
|
|
12
|
-
import {IsoChronology} from './chrono/IsoChronology';
|
|
13
|
-
import {ChronoField} from './temporal/ChronoField';
|
|
14
|
-
import {ChronoUnit} from './temporal/ChronoUnit';
|
|
15
|
-
import {ChronoLocalDate} from './chrono/ChronoLocalDate';
|
|
16
|
-
import {TemporalQueries} from './temporal/TemporalQueries';
|
|
17
|
-
import {createTemporalQuery} from './temporal/TemporalQuery';
|
|
18
|
-
import {ValueRange} from './temporal/ValueRange';
|
|
19
|
-
import {DateTimeFormatter} from './format/DateTimeFormatter';
|
|
20
|
-
|
|
21
|
-
import {Clock} from './Clock';
|
|
22
|
-
import {DayOfWeek} from './DayOfWeek';
|
|
23
|
-
import {OffsetDateTime} from './OffsetDateTime';
|
|
24
|
-
import {OffsetTime} from './OffsetTime';
|
|
25
|
-
import {Month} from './Month';
|
|
26
|
-
import {Period} from './Period';
|
|
27
|
-
import {YearConstants} from './YearConstants';
|
|
28
|
-
import {LocalTime} from './LocalTime';
|
|
29
|
-
import {LocalDateTime} from './LocalDateTime';
|
|
30
|
-
import {Year} from './Year';
|
|
31
|
-
import {ZoneId} from './ZoneId';
|
|
32
|
-
import {ZoneOffset} from './ZoneOffset';
|
|
33
|
-
import {ZonedDateTime} from './ZonedDateTime';
|
|
7
|
+
import { assert, requireNonNull, requireInstance } from './assert';
|
|
8
|
+
|
|
9
|
+
import { MathUtil } from './MathUtil';
|
|
10
|
+
import { DateTimeException, UnsupportedTemporalTypeException, NullPointerException, IllegalArgumentException } from './errors';
|
|
11
|
+
|
|
12
|
+
import { IsoChronology } from './chrono/IsoChronology';
|
|
13
|
+
import { ChronoField } from './temporal/ChronoField';
|
|
14
|
+
import { ChronoUnit } from './temporal/ChronoUnit';
|
|
15
|
+
import { ChronoLocalDate } from './chrono/ChronoLocalDate';
|
|
16
|
+
import { TemporalQueries } from './temporal/TemporalQueries';
|
|
17
|
+
import { createTemporalQuery } from './temporal/TemporalQuery';
|
|
18
|
+
import { ValueRange } from './temporal/ValueRange';
|
|
19
|
+
import { DateTimeFormatter } from './format/DateTimeFormatter';
|
|
20
|
+
|
|
21
|
+
import { Clock } from './Clock';
|
|
22
|
+
import { DayOfWeek } from './DayOfWeek';
|
|
23
|
+
import { OffsetDateTime } from './OffsetDateTime';
|
|
24
|
+
import { OffsetTime } from './OffsetTime';
|
|
25
|
+
import { Month } from './Month';
|
|
26
|
+
import { Period } from './Period';
|
|
27
|
+
import { YearConstants } from './YearConstants';
|
|
28
|
+
import { LocalTime } from './LocalTime';
|
|
29
|
+
import { LocalDateTime } from './LocalDateTime';
|
|
30
|
+
import { Year } from './Year';
|
|
31
|
+
import { ZoneId } from './ZoneId';
|
|
32
|
+
import { ZoneOffset } from './ZoneOffset';
|
|
33
|
+
import { ZonedDateTime } from './ZonedDateTime';
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
36
|
* The number of days in a 400 year cycle.
|
|
@@ -158,7 +158,7 @@ export class LocalDate extends ChronoLocalDate{
|
|
|
158
158
|
//TODO: ChronoField.DAY_OF_YEAR.checkValidValue(dayOfYear);
|
|
159
159
|
const leap = IsoChronology.isLeapYear(year);
|
|
160
160
|
if (dayOfYear === 366 && leap === false) {
|
|
161
|
-
assert(false,
|
|
161
|
+
assert(false, `Invalid date 'DayOfYear 366' as '${year}' is not a leap year`, DateTimeException);
|
|
162
162
|
}
|
|
163
163
|
let moy = Month.of(Math.floor((dayOfYear - 1) / 31 + 1));
|
|
164
164
|
const monthEnd = moy.firstDayOfYear(leap) + moy.length(leap) - 1;
|
|
@@ -323,9 +323,9 @@ export class LocalDate extends ChronoLocalDate{
|
|
|
323
323
|
}
|
|
324
324
|
if (dayOfMonth > dom) {
|
|
325
325
|
if (dayOfMonth === 29) {
|
|
326
|
-
assert(false,
|
|
326
|
+
assert(false, `Invalid date 'February 29' as '${year}' is not a leap year`, DateTimeException);
|
|
327
327
|
} else {
|
|
328
|
-
assert(false,
|
|
328
|
+
assert(false, `Invalid date '${year}' '${month}' '${dayOfMonth}'`, DateTimeException);
|
|
329
329
|
}
|
|
330
330
|
}
|
|
331
331
|
}
|
|
@@ -405,7 +405,7 @@ export class LocalDate extends ChronoLocalDate{
|
|
|
405
405
|
}
|
|
406
406
|
return field.range();
|
|
407
407
|
}
|
|
408
|
-
throw new UnsupportedTemporalTypeException(
|
|
408
|
+
throw new UnsupportedTemporalTypeException(`Unsupported field: ${field}`);
|
|
409
409
|
}
|
|
410
410
|
return field.rangeRefinedBy(this);
|
|
411
411
|
}
|
|
@@ -476,7 +476,7 @@ export class LocalDate extends ChronoLocalDate{
|
|
|
476
476
|
case ChronoField.YEAR: return this._year;
|
|
477
477
|
case ChronoField.ERA: return (this._year >= 1 ? 1 : 0);
|
|
478
478
|
}
|
|
479
|
-
throw new UnsupportedTemporalTypeException(
|
|
479
|
+
throw new UnsupportedTemporalTypeException(`Unsupported field: ${field}`);
|
|
480
480
|
}
|
|
481
481
|
|
|
482
482
|
/**
|
|
@@ -651,14 +651,13 @@ export class LocalDate extends ChronoLocalDate{
|
|
|
651
651
|
* @throws {DateTimeException} if the adjustment cannot be made
|
|
652
652
|
* @throws {ArithmeticException} if numeric overflow occurs
|
|
653
653
|
*/
|
|
654
|
-
|
|
654
|
+
_withAdjuster(adjuster) {
|
|
655
655
|
requireNonNull(adjuster, 'adjuster');
|
|
656
656
|
// optimizations
|
|
657
657
|
if (adjuster instanceof LocalDate) {
|
|
658
658
|
return adjuster;
|
|
659
659
|
}
|
|
660
|
-
|
|
661
|
-
return adjuster.adjustInto(this);
|
|
660
|
+
return super._withAdjuster(adjuster);
|
|
662
661
|
}
|
|
663
662
|
|
|
664
663
|
/**
|
|
@@ -761,7 +760,7 @@ export class LocalDate extends ChronoLocalDate{
|
|
|
761
760
|
* @throws {DateTimeException} if the field cannot be set
|
|
762
761
|
* @throws {ArithmeticException} if numeric overflow occurs
|
|
763
762
|
*/
|
|
764
|
-
|
|
763
|
+
_withField(field, newValue) {
|
|
765
764
|
assert(field != null, 'field', NullPointerException);
|
|
766
765
|
if (field instanceof ChronoField) {
|
|
767
766
|
const f = field;
|
|
@@ -781,7 +780,7 @@ export class LocalDate extends ChronoLocalDate{
|
|
|
781
780
|
case ChronoField.YEAR: return this.withYear(newValue);
|
|
782
781
|
case ChronoField.ERA: return (this.getLong(ChronoField.ERA) === newValue ? this : this.withYear(1 - this._year));
|
|
783
782
|
}
|
|
784
|
-
throw new UnsupportedTemporalTypeException(
|
|
783
|
+
throw new UnsupportedTemporalTypeException(`Unsupported field: ${field}`);
|
|
785
784
|
}
|
|
786
785
|
return field.adjustInto(this, newValue);
|
|
787
786
|
}
|
|
@@ -852,25 +851,6 @@ export class LocalDate extends ChronoLocalDate{
|
|
|
852
851
|
return LocalDate.ofYearDay(this._year, dayOfYear);
|
|
853
852
|
}
|
|
854
853
|
|
|
855
|
-
/**
|
|
856
|
-
* Returns a copy of this date with the specified period added.
|
|
857
|
-
*
|
|
858
|
-
* This method returns a new date based on this date with the specified period added.
|
|
859
|
-
* The amount is typically {@link Period} but may be any other type implementing
|
|
860
|
-
* the {@link TemporalAmount} interface.
|
|
861
|
-
* The calculation is delegated to the specified adjuster, which typically calls
|
|
862
|
-
* back to {@link LocalDate.plusAmountUnit}.
|
|
863
|
-
*
|
|
864
|
-
* @param {!TemporalAmount} amount - the amount to add, not null
|
|
865
|
-
* @return {LocalDate} a {@link LocalDate} based on this date with the addition made, not null
|
|
866
|
-
* @throws {DateTimeException} if the addition cannot be made
|
|
867
|
-
* @throws {ArithmeticException} if numeric overflow occurs
|
|
868
|
-
*/
|
|
869
|
-
plusAmount(amount) {
|
|
870
|
-
requireNonNull(amount, 'amount');
|
|
871
|
-
return amount.addTo(this);
|
|
872
|
-
}
|
|
873
|
-
|
|
874
854
|
/**
|
|
875
855
|
* Returns a copy of this date with the specified period added.
|
|
876
856
|
*
|
|
@@ -884,7 +864,7 @@ export class LocalDate extends ChronoLocalDate{
|
|
|
884
864
|
* @return {LocalDate} a {@link LocalDate} based on this date with the specified period added, not null
|
|
885
865
|
* @throws {DateTimeException} if the unit cannot be added to this type
|
|
886
866
|
*/
|
|
887
|
-
|
|
867
|
+
_plusUnit(amountToAdd, unit) {
|
|
888
868
|
requireNonNull(amountToAdd, 'amountToAdd');
|
|
889
869
|
requireNonNull(unit, 'unit');
|
|
890
870
|
if (unit instanceof ChronoUnit) {
|
|
@@ -898,7 +878,7 @@ export class LocalDate extends ChronoLocalDate{
|
|
|
898
878
|
case ChronoUnit.MILLENNIA: return this.plusYears(MathUtil.safeMultiply(amountToAdd, 1000));
|
|
899
879
|
case ChronoUnit.ERAS: return this.with(ChronoField.ERA, MathUtil.safeAdd(this.getLong(ChronoField.ERA), amountToAdd));
|
|
900
880
|
}
|
|
901
|
-
throw new UnsupportedTemporalTypeException(
|
|
881
|
+
throw new UnsupportedTemporalTypeException(`Unsupported unit: ${unit}`);
|
|
902
882
|
}
|
|
903
883
|
return unit.addTo(this, amountToAdd);
|
|
904
884
|
}
|
|
@@ -995,25 +975,6 @@ export class LocalDate extends ChronoLocalDate{
|
|
|
995
975
|
return LocalDate.ofEpochDay(mjDay);
|
|
996
976
|
}
|
|
997
977
|
|
|
998
|
-
/**
|
|
999
|
-
* Returns a copy of this date with the specified period subtracted.
|
|
1000
|
-
*
|
|
1001
|
-
* This method returns a new date based on this date with the specified period subtracted.
|
|
1002
|
-
* The amount is typically {@link Period} but may be any other type implementing
|
|
1003
|
-
* the {@link TemporalAmount} interface.
|
|
1004
|
-
* The calculation is delegated to the specified adjuster, which typically calls
|
|
1005
|
-
* back to {@link minus}.
|
|
1006
|
-
*
|
|
1007
|
-
* @param {!TemporalAmount} amount - the amount to subtract, not null
|
|
1008
|
-
* @return {LocalDate} a {@link LocalDate} based on this date with the subtraction made, not null
|
|
1009
|
-
* @throws {DateTimeException} if the subtraction cannot be made
|
|
1010
|
-
* @throws {ArithmeticException} if numeric overflow occurs
|
|
1011
|
-
*/
|
|
1012
|
-
minusAmount(amount) {
|
|
1013
|
-
requireNonNull(amount, 'amount');
|
|
1014
|
-
return amount.subtractFrom(this);
|
|
1015
|
-
}
|
|
1016
|
-
|
|
1017
978
|
/**
|
|
1018
979
|
* Returns a copy of this date with the specified period subtracted.
|
|
1019
980
|
*
|
|
@@ -1027,10 +988,10 @@ export class LocalDate extends ChronoLocalDate{
|
|
|
1027
988
|
* @return {LocalDate} a {@link LocalDate} based on this date with the specified period subtracted, not null
|
|
1028
989
|
* @throws {DateTimeException} if the unit cannot be added to this type
|
|
1029
990
|
*/
|
|
1030
|
-
|
|
991
|
+
_minusUnit(amountToSubtract, unit) {
|
|
1031
992
|
requireNonNull(amountToSubtract, 'amountToSubtract');
|
|
1032
993
|
requireNonNull(unit, 'unit');
|
|
1033
|
-
return this.
|
|
994
|
+
return this._plusUnit(-1 * amountToSubtract, unit);
|
|
1034
995
|
}
|
|
1035
996
|
|
|
1036
997
|
/**
|
|
@@ -1232,7 +1193,7 @@ export class LocalDate extends ChronoLocalDate{
|
|
|
1232
1193
|
case ChronoUnit.MILLENNIA: return MathUtil.intDiv(this._monthsUntil(end), 12000);
|
|
1233
1194
|
case ChronoUnit.ERAS: return end.getLong(ChronoField.ERA) - this.getLong(ChronoField.ERA);
|
|
1234
1195
|
}
|
|
1235
|
-
throw new UnsupportedTemporalTypeException(
|
|
1196
|
+
throw new UnsupportedTemporalTypeException(`Unsupported unit: ${unit}`);
|
|
1236
1197
|
}
|
|
1237
1198
|
return unit.between(this, end);
|
|
1238
1199
|
}
|
|
@@ -1344,8 +1305,8 @@ export class LocalDate extends ChronoLocalDate{
|
|
|
1344
1305
|
} else if (time instanceof OffsetTime) {
|
|
1345
1306
|
return this._atTimeOffsetTime(time);
|
|
1346
1307
|
} else {
|
|
1347
|
-
throw new IllegalArgumentException(
|
|
1348
|
-
|
|
1308
|
+
throw new IllegalArgumentException(`time must be an instance of LocalTime or OffsetTime${
|
|
1309
|
+
time && time.constructor && time.constructor.name ? `, but is ${time.constructor.name}` : ''}`);
|
|
1349
1310
|
}
|
|
1350
1311
|
}
|
|
1351
1312
|
|
|
@@ -1388,12 +1349,29 @@ export class LocalDate extends ChronoLocalDate{
|
|
|
1388
1349
|
* This returns a {@link LocalDateTime} formed from this date at the time of
|
|
1389
1350
|
* midnight, 00:00, at the start of this date.
|
|
1390
1351
|
*
|
|
1391
|
-
*
|
|
1352
|
+
* If zone is not null, this returns a {@link ZonedDateTime} formed from this date at the
|
|
1353
|
+
* specified zone, with the time set to be the earliest valid time according
|
|
1354
|
+
* to the rules in the time-zone.
|
|
1355
|
+
*
|
|
1356
|
+
* Time-zone rules, such as daylight savings, mean that not every local date-time
|
|
1357
|
+
* is valid for the specified zone, thus the local date-time may not be midnight.
|
|
1358
|
+
*
|
|
1359
|
+
* In most cases, there is only one valid offset for a local date-time.
|
|
1360
|
+
* In the case of an overlap, there are two valid offsets, and the earlier one is used,
|
|
1361
|
+
* corresponding to the first occurrence of midnight on the date.
|
|
1362
|
+
* In the case of a gap, the zoned date-time will represent the instant just after the gap.
|
|
1363
|
+
*
|
|
1364
|
+
* If the zone ID is a {@link ZoneOffset}, then the result always has a time of midnight.
|
|
1365
|
+
*
|
|
1366
|
+
* To convert to a specific time in a given time-zone call {@link atTime}
|
|
1367
|
+
* followed by {@link LocalDateTime#atZone}.
|
|
1368
|
+
*
|
|
1369
|
+
* @param {ZoneId} zone - optional ZoneId or ZoneOffset
|
|
1392
1370
|
* @return {LocalDateTime|ZonedDateTime} the local date-time of midnight at the start of this date, not null
|
|
1393
1371
|
*/
|
|
1394
1372
|
atStartOfDay(zone) {
|
|
1395
1373
|
if(zone != null){
|
|
1396
|
-
return this.
|
|
1374
|
+
return this._atStartOfDayWithZone(zone);
|
|
1397
1375
|
} else {
|
|
1398
1376
|
return LocalDateTime.of(this, LocalTime.MIDNIGHT);
|
|
1399
1377
|
}
|
|
@@ -1423,7 +1401,7 @@ export class LocalDate extends ChronoLocalDate{
|
|
|
1423
1401
|
* @param {!ZoneId} zone - the zone ID to use, not null
|
|
1424
1402
|
* @return {ZonedDateTime} the zoned date-time formed from this date and the earliest valid time for the zone, not null
|
|
1425
1403
|
*/
|
|
1426
|
-
|
|
1404
|
+
_atStartOfDayWithZone(zone) {
|
|
1427
1405
|
requireNonNull(zone, 'zone');
|
|
1428
1406
|
let ldt = this.atTime(LocalTime.MIDNIGHT);
|
|
1429
1407
|
// need to handle case where there is a gap from 11:30 to 00:30
|
|
@@ -1632,28 +1610,28 @@ export class LocalDate extends ChronoLocalDate{
|
|
|
1632
1610
|
|
|
1633
1611
|
if (absYear < 1000) {
|
|
1634
1612
|
if (yearValue < 0) {
|
|
1635
|
-
yearString =
|
|
1613
|
+
yearString = `-${(`${yearValue - 10000}`).slice(-4)}`;
|
|
1636
1614
|
} else {
|
|
1637
|
-
yearString = (
|
|
1615
|
+
yearString = (`${yearValue + 10000}`).slice(-4);
|
|
1638
1616
|
}
|
|
1639
1617
|
} else {
|
|
1640
1618
|
if (yearValue > 9999) {
|
|
1641
|
-
yearString =
|
|
1619
|
+
yearString = `+${yearValue}`;
|
|
1642
1620
|
} else {
|
|
1643
|
-
yearString =
|
|
1621
|
+
yearString = `${yearValue}`;
|
|
1644
1622
|
}
|
|
1645
1623
|
}
|
|
1646
1624
|
|
|
1647
1625
|
if (monthValue < 10) {
|
|
1648
|
-
monthString =
|
|
1626
|
+
monthString = `-0${monthValue}`;
|
|
1649
1627
|
} else {
|
|
1650
|
-
monthString =
|
|
1628
|
+
monthString = `-${monthValue}`;
|
|
1651
1629
|
}
|
|
1652
1630
|
|
|
1653
1631
|
if (dayValue < 10) {
|
|
1654
|
-
dayString =
|
|
1632
|
+
dayString = `-0${dayValue}`;
|
|
1655
1633
|
} else {
|
|
1656
|
-
dayString =
|
|
1634
|
+
dayString = `-${dayValue}`;
|
|
1657
1635
|
}
|
|
1658
1636
|
|
|
1659
1637
|
return yearString + monthString + dayString;
|
package/src/LocalDateTime.js
CHANGED
|
@@ -4,27 +4,27 @@
|
|
|
4
4
|
* @license BSD-3-Clause (see LICENSE in the root directory of this source tree)
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {MathUtil} from './MathUtil';
|
|
8
|
-
import {
|
|
9
|
-
import {DateTimeException, UnsupportedTemporalTypeException
|
|
7
|
+
import { MathUtil } from './MathUtil';
|
|
8
|
+
import { requireNonNull, requireInstance } from './assert';
|
|
9
|
+
import { DateTimeException, UnsupportedTemporalTypeException } from './errors';
|
|
10
10
|
|
|
11
|
-
import {Clock} from './Clock';
|
|
12
|
-
import {Instant} from './Instant';
|
|
13
|
-
import {LocalDate} from './LocalDate';
|
|
14
|
-
import {LocalTime} from './LocalTime';
|
|
15
|
-
import {OffsetDateTime} from './OffsetDateTime';
|
|
16
|
-
import {ZonedDateTime} from './ZonedDateTime';
|
|
17
|
-
import {ZoneId} from './ZoneId';
|
|
18
|
-
import {ZoneOffset} from './ZoneOffset';
|
|
11
|
+
import { Clock } from './Clock';
|
|
12
|
+
import { Instant } from './Instant';
|
|
13
|
+
import { LocalDate } from './LocalDate';
|
|
14
|
+
import { LocalTime } from './LocalTime';
|
|
15
|
+
import { OffsetDateTime } from './OffsetDateTime';
|
|
16
|
+
import { ZonedDateTime } from './ZonedDateTime';
|
|
17
|
+
import { ZoneId } from './ZoneId';
|
|
18
|
+
import { ZoneOffset } from './ZoneOffset';
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
import {DateTimeFormatter} from './format/DateTimeFormatter';
|
|
22
|
-
import {ChronoField} from './temporal/ChronoField';
|
|
23
|
-
import {ChronoUnit} from './temporal/ChronoUnit';
|
|
24
|
-
import {TemporalQueries} from './temporal/TemporalQueries';
|
|
25
|
-
import {createTemporalQuery} from './temporal/TemporalQuery';
|
|
21
|
+
import { DateTimeFormatter } from './format/DateTimeFormatter';
|
|
22
|
+
import { ChronoField } from './temporal/ChronoField';
|
|
23
|
+
import { ChronoUnit } from './temporal/ChronoUnit';
|
|
24
|
+
import { TemporalQueries } from './temporal/TemporalQueries';
|
|
25
|
+
import { createTemporalQuery } from './temporal/TemporalQuery';
|
|
26
26
|
|
|
27
|
-
import {ChronoLocalDateTime} from './chrono/ChronoLocalDateTime';
|
|
27
|
+
import { ChronoLocalDateTime } from './chrono/ChronoLocalDateTime';
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* A date-time without a time-zone in the ISO-8601 calendar system,
|
|
@@ -637,7 +637,7 @@ implements Temporal, TemporalAdjuster, Serializable */ {
|
|
|
637
637
|
* @throws {DateTimeException} if the adjustment cannot be made
|
|
638
638
|
* @throws {ArithmeticException} if numeric overflow occurs
|
|
639
639
|
*/
|
|
640
|
-
|
|
640
|
+
_withAdjuster(adjuster) {
|
|
641
641
|
requireNonNull(adjuster, 'adjuster');
|
|
642
642
|
// optimizations
|
|
643
643
|
if (adjuster instanceof LocalDate) {
|
|
@@ -647,8 +647,7 @@ implements Temporal, TemporalAdjuster, Serializable */ {
|
|
|
647
647
|
} else if (adjuster instanceof LocalDateTime) {
|
|
648
648
|
return adjuster;
|
|
649
649
|
}
|
|
650
|
-
|
|
651
|
-
return adjuster.adjustInto(this);
|
|
650
|
+
return super._withAdjuster(adjuster);
|
|
652
651
|
}
|
|
653
652
|
|
|
654
653
|
/**
|
|
@@ -683,7 +682,7 @@ implements Temporal, TemporalAdjuster, Serializable */ {
|
|
|
683
682
|
* @throws {DateTimeException} if the field cannot be set
|
|
684
683
|
* @throws {ArithmeticException} if numeric overflow occurs
|
|
685
684
|
*/
|
|
686
|
-
|
|
685
|
+
_withField(field, newValue) {
|
|
687
686
|
requireNonNull(field, 'field');
|
|
688
687
|
if (field instanceof ChronoField) {
|
|
689
688
|
if (field.isTimeBased()) {
|
|
@@ -840,27 +839,6 @@ implements Temporal, TemporalAdjuster, Serializable */ {
|
|
|
840
839
|
|
|
841
840
|
//-----------------------------------------------------------------------
|
|
842
841
|
|
|
843
|
-
/**
|
|
844
|
-
* Returns a copy of this date-time with the specified period added.
|
|
845
|
-
*
|
|
846
|
-
* This method returns a new date-time based on this time with the specified period added.
|
|
847
|
-
* The amount is typically {@link Period} but may be any other type implementing
|
|
848
|
-
* the {@link TemporalAmount} interface.
|
|
849
|
-
* The calculation is delegated to the specified adjuster, which typically calls
|
|
850
|
-
* back to {@link plus}.
|
|
851
|
-
*
|
|
852
|
-
* This instance is immutable and unaffected by this method call.
|
|
853
|
-
*
|
|
854
|
-
* @param {TemporalAmount} amount - the amount to add, not null
|
|
855
|
-
* @return {LocalDateTime} based on this date-time with the addition made, not null
|
|
856
|
-
* @throws {DateTimeException} if the addition cannot be made
|
|
857
|
-
* @throws {ArithmeticException} if numeric overflow occurs
|
|
858
|
-
*/
|
|
859
|
-
plusAmount(amount) {
|
|
860
|
-
requireNonNull(amount, 'amount');
|
|
861
|
-
return amount.addTo(this);
|
|
862
|
-
}
|
|
863
|
-
|
|
864
842
|
/**
|
|
865
843
|
* Returns a copy of this date-time with the specified period added.
|
|
866
844
|
*
|
|
@@ -876,7 +854,7 @@ implements Temporal, TemporalAdjuster, Serializable */ {
|
|
|
876
854
|
* @return {LocalDateTime} a {@link LocalDateTime} based on this date-time with the specified period added, not null
|
|
877
855
|
* @throws {DateTimeException} if the unit cannot be added to this type
|
|
878
856
|
*/
|
|
879
|
-
|
|
857
|
+
_plusUnit(amountToAdd, unit) {
|
|
880
858
|
requireNonNull(unit, 'unit');
|
|
881
859
|
if (unit instanceof ChronoUnit) {
|
|
882
860
|
switch (unit) {
|
|
@@ -1037,27 +1015,6 @@ implements Temporal, TemporalAdjuster, Serializable */ {
|
|
|
1037
1015
|
|
|
1038
1016
|
//-----------------------------------------------------------------------
|
|
1039
1017
|
|
|
1040
|
-
/**
|
|
1041
|
-
* Returns a copy of this date-time with the specified period subtracted.
|
|
1042
|
-
*
|
|
1043
|
-
* This method returns a new date-time based on this time with the specified period subtracted.
|
|
1044
|
-
* The amount is typically {@link Period} but may be any other type implementing
|
|
1045
|
-
* the {@link TemporalAmount} interface.
|
|
1046
|
-
* The calculation is delegated to the specified adjuster, which typically calls
|
|
1047
|
-
* back to {@link minus}.
|
|
1048
|
-
*
|
|
1049
|
-
* This instance is immutable and unaffected by this method call.
|
|
1050
|
-
*
|
|
1051
|
-
* @param {TemporalAmount} amount - the amount to subtract, not null
|
|
1052
|
-
* @return {LocalDateTime} based on this date-time with the subtraction made, not null
|
|
1053
|
-
* @throws {DateTimeException} if the subtraction cannot be made
|
|
1054
|
-
* @throws {ArithmeticException} if numeric overflow occurs
|
|
1055
|
-
*/
|
|
1056
|
-
minusAmount(amount) {
|
|
1057
|
-
requireNonNull(amount, 'amount');
|
|
1058
|
-
return amount.subtractFrom(this);
|
|
1059
|
-
}
|
|
1060
|
-
|
|
1061
1018
|
/**
|
|
1062
1019
|
* Returns a copy of this date-time with the specified period subtracted.
|
|
1063
1020
|
*
|
|
@@ -1073,9 +1030,9 @@ implements Temporal, TemporalAdjuster, Serializable */ {
|
|
|
1073
1030
|
* @return {LocalDateTime} a {@link LocalDateTime} based on this date-time with the specified period subtracted, not null
|
|
1074
1031
|
* @throws {DateTimeException} if the unit cannot be added to this type
|
|
1075
1032
|
*/
|
|
1076
|
-
|
|
1033
|
+
_minusUnit(amountToSubtract, unit) {
|
|
1077
1034
|
requireNonNull(unit, 'unit');
|
|
1078
|
-
return this.
|
|
1035
|
+
return this._plusUnit(-1 * amountToSubtract, unit);
|
|
1079
1036
|
}
|
|
1080
1037
|
|
|
1081
1038
|
//-----------------------------------------------------------------------
|
|
@@ -1391,7 +1348,7 @@ implements Temporal, TemporalAdjuster, Serializable */ {
|
|
|
1391
1348
|
amount = MathUtil.safeMultiply(amount, 2);
|
|
1392
1349
|
return MathUtil.safeAdd(amount, MathUtil.intDiv(timeUntil, (LocalTime.NANOS_PER_HOUR * 12)));
|
|
1393
1350
|
}
|
|
1394
|
-
throw new UnsupportedTemporalTypeException(
|
|
1351
|
+
throw new UnsupportedTemporalTypeException(`Unsupported unit: ${unit}`);
|
|
1395
1352
|
}
|
|
1396
1353
|
let endDate = end._date;
|
|
1397
1354
|
const endTime = end._time;
|
|
@@ -1638,7 +1595,7 @@ implements Temporal, TemporalAdjuster, Serializable */ {
|
|
|
1638
1595
|
* @return {string} a string representation of this date-time, not null
|
|
1639
1596
|
*/
|
|
1640
1597
|
toString() {
|
|
1641
|
-
return this._date.toString()
|
|
1598
|
+
return `${this._date.toString()}T${this._time.toString()}`;
|
|
1642
1599
|
}
|
|
1643
1600
|
|
|
1644
1601
|
/**
|