@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/Period.js
CHANGED
|
@@ -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 {MathUtil} from './MathUtil';
|
|
8
|
-
import {requireNonNull, requireInstance} from './assert';
|
|
9
|
-
import {DateTimeException, UnsupportedTemporalTypeException, ArithmeticException, DateTimeParseException} from './errors';
|
|
7
|
+
import { MathUtil } from './MathUtil';
|
|
8
|
+
import { requireNonNull, requireInstance } from './assert';
|
|
9
|
+
import { DateTimeException, UnsupportedTemporalTypeException, ArithmeticException, DateTimeParseException } from './errors';
|
|
10
10
|
|
|
11
|
-
import {IsoChronology} from './chrono/IsoChronology';
|
|
11
|
+
import { IsoChronology } from './chrono/IsoChronology';
|
|
12
12
|
|
|
13
|
-
import {ChronoUnit} from './temporal/ChronoUnit';
|
|
14
|
-
import {TemporalAmount} from './temporal/TemporalAmount';
|
|
13
|
+
import { ChronoUnit } from './temporal/ChronoUnit';
|
|
14
|
+
import { TemporalAmount } from './temporal/TemporalAmount';
|
|
15
15
|
|
|
16
|
-
import {LocalDate} from './LocalDate';
|
|
16
|
+
import { LocalDate } from './LocalDate';
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* The pattern for parsing.
|
|
@@ -214,7 +214,7 @@ export class Period extends TemporalAmount /* extends ChronoPeriod */ {
|
|
|
214
214
|
} else if (unit === ChronoUnit.DAYS) {
|
|
215
215
|
days = MathUtil.safeToInt(unitAmount);
|
|
216
216
|
} else {
|
|
217
|
-
throw new DateTimeException(
|
|
217
|
+
throw new DateTimeException(`Unit must be Years, Months or Days, but was ${unit}`);
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
220
|
return Period.create(years, months, days);
|
|
@@ -393,7 +393,7 @@ export class Period extends TemporalAmount /* extends ChronoPeriod */ {
|
|
|
393
393
|
if (unit === ChronoUnit.DAYS) {
|
|
394
394
|
return this._days;
|
|
395
395
|
}
|
|
396
|
-
throw new UnsupportedTemporalTypeException(
|
|
396
|
+
throw new UnsupportedTemporalTypeException(`Unsupported unit: ${unit}`);
|
|
397
397
|
}
|
|
398
398
|
|
|
399
399
|
//-----------------------------------------------------------------------
|
|
@@ -904,13 +904,13 @@ export class Period extends TemporalAmount /* extends ChronoPeriod */ {
|
|
|
904
904
|
} else {
|
|
905
905
|
let buf = 'P';
|
|
906
906
|
if (this._years !== 0) {
|
|
907
|
-
buf +=
|
|
907
|
+
buf += `${this._years}Y`;
|
|
908
908
|
}
|
|
909
909
|
if (this._months !== 0) {
|
|
910
|
-
buf +=
|
|
910
|
+
buf += `${this._months}M`;
|
|
911
911
|
}
|
|
912
912
|
if (this._days !== 0) {
|
|
913
|
-
buf +=
|
|
913
|
+
buf += `${this._days}D`;
|
|
914
914
|
}
|
|
915
915
|
return buf;
|
|
916
916
|
}
|
package/src/StringUtil.js
CHANGED
package/src/Year.js
CHANGED
|
@@ -4,30 +4,29 @@
|
|
|
4
4
|
* @license BSD-3-Clause (see LICENSE in the root directory of this source tree)
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {DateTimeException, UnsupportedTemporalTypeException} from './errors';
|
|
8
|
-
import {requireNonNull, requireInstance} from './assert';
|
|
9
|
-
import {MathUtil} from './MathUtil';
|
|
10
|
-
|
|
11
|
-
import {ChronoField} from './temporal/ChronoField';
|
|
12
|
-
import {ChronoUnit} from './temporal/ChronoUnit';
|
|
13
|
-
import {Clock} from './Clock';
|
|
14
|
-
import {DateTimeFormatter} from './format/DateTimeFormatter';
|
|
15
|
-
import {DateTimeFormatterBuilder} from './format/DateTimeFormatterBuilder';
|
|
16
|
-
import {IsoChronology} from './chrono/IsoChronology';
|
|
17
|
-
import {LocalDate} from './LocalDate';
|
|
18
|
-
import {Month} from './Month';
|
|
19
|
-
import {MonthDay} from './MonthDay';
|
|
20
|
-
import {SignStyle} from './format/SignStyle';
|
|
21
|
-
import {Temporal} from './temporal/Temporal';
|
|
22
|
-
import {TemporalAccessor} from './temporal/TemporalAccessor';
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
import {ZoneId} from './ZoneId';
|
|
7
|
+
import { DateTimeException, UnsupportedTemporalTypeException } from './errors';
|
|
8
|
+
import { requireNonNull, requireInstance } from './assert';
|
|
9
|
+
import { MathUtil } from './MathUtil';
|
|
10
|
+
|
|
11
|
+
import { ChronoField } from './temporal/ChronoField';
|
|
12
|
+
import { ChronoUnit } from './temporal/ChronoUnit';
|
|
13
|
+
import { Clock } from './Clock';
|
|
14
|
+
import { DateTimeFormatter } from './format/DateTimeFormatter';
|
|
15
|
+
import { DateTimeFormatterBuilder } from './format/DateTimeFormatterBuilder';
|
|
16
|
+
import { IsoChronology } from './chrono/IsoChronology';
|
|
17
|
+
import { LocalDate } from './LocalDate';
|
|
18
|
+
import { Month } from './Month';
|
|
19
|
+
import { MonthDay } from './MonthDay';
|
|
20
|
+
import { SignStyle } from './format/SignStyle';
|
|
21
|
+
import { Temporal } from './temporal/Temporal';
|
|
22
|
+
import { TemporalAccessor } from './temporal/TemporalAccessor';
|
|
23
|
+
import { TemporalField } from './temporal/TemporalField';
|
|
24
|
+
import { TemporalQueries } from './temporal/TemporalQueries';
|
|
25
|
+
import { TemporalQuery, createTemporalQuery } from './temporal/TemporalQuery';
|
|
26
|
+
import { TemporalUnit } from './temporal/TemporalUnit';
|
|
27
|
+
import { YearConstants } from './YearConstants';
|
|
28
|
+
import { YearMonth } from './YearMonth';
|
|
29
|
+
import { ZoneId } from './ZoneId';
|
|
31
30
|
|
|
32
31
|
|
|
33
32
|
/**
|
|
@@ -209,8 +208,8 @@ export class Year extends Temporal {
|
|
|
209
208
|
}*/
|
|
210
209
|
return Year.of(temporal.get(ChronoField.YEAR));
|
|
211
210
|
} catch (ex) {
|
|
212
|
-
throw new DateTimeException(
|
|
213
|
-
|
|
211
|
+
throw new DateTimeException(`Unable to obtain Year from TemporalAccessor: ${
|
|
212
|
+
temporal}, type ${temporal && temporal.constructor != null ? temporal.constructor.name : ''}`);
|
|
214
213
|
}
|
|
215
214
|
}
|
|
216
215
|
//-----------------------------------------------------------------------
|
|
@@ -372,7 +371,7 @@ export class Year extends Temporal {
|
|
|
372
371
|
if (this.isSupported(field)) {
|
|
373
372
|
return field.range();
|
|
374
373
|
} else if (field instanceof ChronoField) {
|
|
375
|
-
throw new UnsupportedTemporalTypeException(
|
|
374
|
+
throw new UnsupportedTemporalTypeException(`Unsupported field: ${field}`);
|
|
376
375
|
}
|
|
377
376
|
return super.range(field);
|
|
378
377
|
}
|
|
@@ -434,7 +433,7 @@ export class Year extends Temporal {
|
|
|
434
433
|
case ChronoField.YEAR: return this._year;
|
|
435
434
|
case ChronoField.ERA: return (this._year < 1 ? 0 : 1);
|
|
436
435
|
}
|
|
437
|
-
throw new UnsupportedTemporalTypeException(
|
|
436
|
+
throw new UnsupportedTemporalTypeException(`Unsupported field: ${field}`);
|
|
438
437
|
}
|
|
439
438
|
return field.getFrom(this);
|
|
440
439
|
}
|
|
@@ -464,29 +463,6 @@ export class Year extends Temporal {
|
|
|
464
463
|
|
|
465
464
|
//-----------------------------------------------------------------------
|
|
466
465
|
|
|
467
|
-
/**
|
|
468
|
-
* Returns an adjusted copy of this year.
|
|
469
|
-
*
|
|
470
|
-
* This returns a new {@link Year}, based on this one, with the year adjusted.
|
|
471
|
-
* The adjustment takes place using the specified adjuster strategy object.
|
|
472
|
-
* Read the documentation of the adjuster to understand what adjustment will be made.
|
|
473
|
-
*
|
|
474
|
-
* The result of this method is obtained by invoking the
|
|
475
|
-
* {@link TemporalAdjuster#adjustInto} method on the
|
|
476
|
-
* specified adjuster passing `this` as the argument.
|
|
477
|
-
*
|
|
478
|
-
* This instance is immutable and unaffected by this method call.
|
|
479
|
-
*
|
|
480
|
-
* @param {TemporalAdjuster} adjuster the adjuster to use, not null
|
|
481
|
-
* @returns {Year} based on `this` with the adjustment made, not null
|
|
482
|
-
* @throws DateTimeException if the adjustment cannot be made
|
|
483
|
-
* @throws ArithmeticException if numeric overflow occurs
|
|
484
|
-
*/
|
|
485
|
-
withAdjuster(adjuster) {
|
|
486
|
-
requireNonNull(adjuster, 'adjuster');
|
|
487
|
-
return adjuster.adjustInto(this);
|
|
488
|
-
}
|
|
489
|
-
|
|
490
466
|
/**
|
|
491
467
|
* Returns a copy of this year with the specified field set to a new value.
|
|
492
468
|
*
|
|
@@ -526,7 +502,7 @@ export class Year extends Temporal {
|
|
|
526
502
|
* @throws DateTimeException if the field cannot be set
|
|
527
503
|
* @throws ArithmeticException if numeric overflow occurs
|
|
528
504
|
*/
|
|
529
|
-
|
|
505
|
+
_withField(field, newValue) {
|
|
530
506
|
requireNonNull(field, 'field');
|
|
531
507
|
requireInstance(field, TemporalField, 'field');
|
|
532
508
|
if (field instanceof ChronoField) {
|
|
@@ -539,33 +515,11 @@ export class Year extends Temporal {
|
|
|
539
515
|
case ChronoField.ERA:
|
|
540
516
|
return (this.getLong(ChronoField.ERA) === newValue ? this : Year.of(1 - this._year));
|
|
541
517
|
}
|
|
542
|
-
throw new UnsupportedTemporalTypeException(
|
|
518
|
+
throw new UnsupportedTemporalTypeException(`Unsupported field: ${field}`);
|
|
543
519
|
}
|
|
544
520
|
return field.adjustInto(this, newValue);
|
|
545
521
|
}
|
|
546
522
|
|
|
547
|
-
/**
|
|
548
|
-
* Returns a copy of this year with the specified period added.
|
|
549
|
-
*
|
|
550
|
-
* This method returns a new year based on this year with the specified period added.
|
|
551
|
-
* The adder is typically {@link Period} but may be any other type implementing
|
|
552
|
-
* the {@link TemporalAmount} interface.
|
|
553
|
-
* The calculation is delegated to the specified adjuster, which typically calls
|
|
554
|
-
* back to {@link plus}.
|
|
555
|
-
*
|
|
556
|
-
* This instance is immutable and unaffected by this method call.
|
|
557
|
-
*
|
|
558
|
-
* @param {TemporalAmount} amount the amount to add, not null
|
|
559
|
-
* @return {Year} based on this year with the addition made, not null
|
|
560
|
-
* @throws DateTimeException if the addition cannot be made
|
|
561
|
-
* @throws ArithmeticException if numeric overflow occurs
|
|
562
|
-
*/
|
|
563
|
-
plusAmount(amount) {
|
|
564
|
-
requireNonNull(amount, 'amount');
|
|
565
|
-
requireInstance(amount, TemporalAmount, 'amount');
|
|
566
|
-
return amount.addTo(this);
|
|
567
|
-
}
|
|
568
|
-
|
|
569
523
|
/**
|
|
570
524
|
* @param {number} amountToAdd
|
|
571
525
|
* @param {TemporalUnit} unit
|
|
@@ -573,7 +527,7 @@ export class Year extends Temporal {
|
|
|
573
527
|
* @throws DateTimeException if the addition cannot be made
|
|
574
528
|
* @throws ArithmeticException if numeric overflow occurs
|
|
575
529
|
*/
|
|
576
|
-
|
|
530
|
+
_plusUnit(amountToAdd, unit) {
|
|
577
531
|
requireNonNull(amountToAdd, 'amountToAdd');
|
|
578
532
|
requireNonNull(unit, 'unit');
|
|
579
533
|
requireInstance(unit, TemporalUnit, 'unit');
|
|
@@ -585,7 +539,7 @@ export class Year extends Temporal {
|
|
|
585
539
|
case ChronoUnit.MILLENNIA: return this.plusYears(MathUtil.safeMultiply(amountToAdd, 1000));
|
|
586
540
|
case ChronoUnit.ERAS: return this.with(ChronoField.ERA, MathUtil.safeAdd(this.getLong(ChronoField.ERA), amountToAdd));
|
|
587
541
|
}
|
|
588
|
-
throw new UnsupportedTemporalTypeException(
|
|
542
|
+
throw new UnsupportedTemporalTypeException(`Unsupported unit: ${unit}`);
|
|
589
543
|
}
|
|
590
544
|
return unit.addTo(this, amountToAdd);
|
|
591
545
|
}
|
|
@@ -608,42 +562,6 @@ export class Year extends Temporal {
|
|
|
608
562
|
|
|
609
563
|
//-----------------------------------------------------------------------
|
|
610
564
|
|
|
611
|
-
/**
|
|
612
|
-
* Returns a copy of this year with the specified period subtracted.
|
|
613
|
-
*
|
|
614
|
-
* This method returns a new year based on this year with the specified period subtracted.
|
|
615
|
-
* The subtractor is typically {@link Period} but may be any other type implementing
|
|
616
|
-
* the {@link TemporalAmount} interface.
|
|
617
|
-
* The calculation is delegated to the specified adjuster, which typically calls
|
|
618
|
-
* back to {@link minus}.
|
|
619
|
-
*
|
|
620
|
-
* This instance is immutable and unaffected by this method call.
|
|
621
|
-
*
|
|
622
|
-
* @param {TemporalAmount} amount the amount to subtract, not null
|
|
623
|
-
* @return {Year} based on this year with the subtraction made, not null
|
|
624
|
-
* @throws DateTimeException if the subtraction cannot be made
|
|
625
|
-
* @throws ArithmeticException if numeric overflow occurs
|
|
626
|
-
*/
|
|
627
|
-
minusAmount(amount) {
|
|
628
|
-
requireNonNull(amount, 'amount');
|
|
629
|
-
requireInstance(amount, TemporalAmount, 'amount');
|
|
630
|
-
return amount.subtractFrom(this);
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
/**
|
|
634
|
-
* @param {number} amountToSubtract the amount to subtract, not null
|
|
635
|
-
* @param {TemporalUnit} unit
|
|
636
|
-
* @return {Year} based on this year with the subtraction made, not null
|
|
637
|
-
* @throws DateTimeException if the subtraction cannot be made
|
|
638
|
-
* @throws ArithmeticException if numeric overflow occurs
|
|
639
|
-
*/
|
|
640
|
-
minusAmountUnit(amountToSubtract, unit) {
|
|
641
|
-
requireNonNull(amountToSubtract, 'amountToSubtract');
|
|
642
|
-
requireNonNull(unit, 'unit');
|
|
643
|
-
requireInstance(unit, TemporalUnit, 'unit');
|
|
644
|
-
return (amountToSubtract === MathUtil.MIN_SAFE_INTEGER ? this.plus(MathUtil.MAX_SAFE_INTEGER, unit).plus(1, unit) : this.plus(-amountToSubtract, unit));
|
|
645
|
-
}
|
|
646
|
-
|
|
647
565
|
/**
|
|
648
566
|
* Returns a copy of this year with the specified number of years subtracted.
|
|
649
567
|
*
|
|
@@ -913,7 +831,7 @@ export class Year extends Temporal {
|
|
|
913
831
|
* @return {String} a string representation of this year, not null
|
|
914
832
|
*/
|
|
915
833
|
toString() {
|
|
916
|
-
return
|
|
834
|
+
return `${this._year}`;
|
|
917
835
|
}
|
|
918
836
|
|
|
919
837
|
/**
|
|
@@ -992,7 +910,7 @@ export class Year extends Temporal {
|
|
|
992
910
|
case ChronoUnit.ERAS:
|
|
993
911
|
return end.getLong(ChronoField.ERA) - this.getLong(ChronoField.ERA);
|
|
994
912
|
}
|
|
995
|
-
throw new UnsupportedTemporalTypeException(
|
|
913
|
+
throw new UnsupportedTemporalTypeException(`Unsupported unit: ${unit}`);
|
|
996
914
|
}
|
|
997
915
|
return unit.between(this, end);
|
|
998
916
|
}
|
package/src/YearMonth.js
CHANGED
|
@@ -3,28 +3,27 @@
|
|
|
3
3
|
* @license BSD-3-Clause (see LICENSE.md in the root directory of this source tree)
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {requireNonNull, requireInstance} from './assert';
|
|
7
|
-
import {DateTimeException, UnsupportedTemporalTypeException} from './errors';
|
|
8
|
-
import {MathUtil} from './MathUtil';
|
|
9
|
-
|
|
10
|
-
import {ChronoField} from './temporal/ChronoField';
|
|
11
|
-
import {ChronoUnit} from './temporal/ChronoUnit';
|
|
12
|
-
import {Clock} from './Clock';
|
|
13
|
-
import {DateTimeFormatterBuilder} from './format/DateTimeFormatterBuilder';
|
|
14
|
-
import {IsoChronology} from './chrono/IsoChronology';
|
|
15
|
-
import {LocalDate} from './LocalDate';
|
|
16
|
-
import {Month} from './Month';
|
|
17
|
-
import {SignStyle} from './format/SignStyle';
|
|
18
|
-
import {Temporal} from './temporal/Temporal';
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import {ZoneId} from './ZoneId';
|
|
6
|
+
import { requireNonNull, requireInstance } from './assert';
|
|
7
|
+
import { DateTimeException, UnsupportedTemporalTypeException } from './errors';
|
|
8
|
+
import { MathUtil } from './MathUtil';
|
|
9
|
+
|
|
10
|
+
import { ChronoField } from './temporal/ChronoField';
|
|
11
|
+
import { ChronoUnit } from './temporal/ChronoUnit';
|
|
12
|
+
import { Clock } from './Clock';
|
|
13
|
+
import { DateTimeFormatterBuilder } from './format/DateTimeFormatterBuilder';
|
|
14
|
+
import { IsoChronology } from './chrono/IsoChronology';
|
|
15
|
+
import { LocalDate } from './LocalDate';
|
|
16
|
+
import { Month } from './Month';
|
|
17
|
+
import { SignStyle } from './format/SignStyle';
|
|
18
|
+
import { Temporal } from './temporal/Temporal';
|
|
19
|
+
import { TemporalField } from './temporal/TemporalField';
|
|
20
|
+
import { TemporalQueries } from './temporal/TemporalQueries';
|
|
21
|
+
import { TemporalQuery } from './temporal/TemporalQuery';
|
|
22
|
+
import { TemporalUnit } from './temporal/TemporalUnit';
|
|
23
|
+
import { createTemporalQuery } from './temporal/TemporalQuery';
|
|
24
|
+
import { ValueRange } from './temporal/ValueRange';
|
|
25
|
+
import { Year } from './Year';
|
|
26
|
+
import { ZoneId } from './ZoneId';
|
|
28
27
|
|
|
29
28
|
/**
|
|
30
29
|
* A year-month in the ISO-8601 calendar system, such as `2007-12`.
|
|
@@ -199,8 +198,8 @@ export class YearMonth extends Temporal {
|
|
|
199
198
|
}*/
|
|
200
199
|
return YearMonth.of(temporal.get(ChronoField.YEAR), temporal.get(ChronoField.MONTH_OF_YEAR));
|
|
201
200
|
} catch (ex) {
|
|
202
|
-
throw new DateTimeException(
|
|
203
|
-
|
|
201
|
+
throw new DateTimeException(`Unable to obtain YearMonth from TemporalAccessor: ${
|
|
202
|
+
temporal}, type ${temporal && temporal.constructor != null ? temporal.constructor.name : ''}`);
|
|
204
203
|
}
|
|
205
204
|
}
|
|
206
205
|
//-----------------------------------------------------------------------
|
|
@@ -419,7 +418,7 @@ export class YearMonth extends Temporal {
|
|
|
419
418
|
case ChronoField.YEAR: return this._year;
|
|
420
419
|
case ChronoField.ERA: return (this._year < 1 ? 0 : 1);
|
|
421
420
|
}
|
|
422
|
-
throw new UnsupportedTemporalTypeException(
|
|
421
|
+
throw new UnsupportedTemporalTypeException(`Unsupported field: ${field}`);
|
|
423
422
|
}
|
|
424
423
|
return field.getFrom(this);
|
|
425
424
|
}
|
|
@@ -540,39 +539,12 @@ export class YearMonth extends Temporal {
|
|
|
540
539
|
*/
|
|
541
540
|
with(adjusterOrField, value) {
|
|
542
541
|
if (arguments.length === 1) {
|
|
543
|
-
return this.
|
|
542
|
+
return this._withAdjuster(adjusterOrField);
|
|
544
543
|
} else {
|
|
545
|
-
return this.
|
|
544
|
+
return this._withField(adjusterOrField, value);
|
|
546
545
|
}
|
|
547
546
|
}
|
|
548
547
|
|
|
549
|
-
/**
|
|
550
|
-
* Returns an adjusted copy of this year-month.
|
|
551
|
-
*
|
|
552
|
-
* This returns a new {@link YearMonth}, based on this one, with the year-month adjusted.
|
|
553
|
-
* The adjustment takes place using the specified adjuster strategy object.
|
|
554
|
-
* Read the documentation of the adjuster to understand what adjustment will be made.
|
|
555
|
-
*
|
|
556
|
-
* A simple adjuster might simply set the one of the fields, such as the year field.
|
|
557
|
-
* A more complex adjuster might set the year-month to the next month that
|
|
558
|
-
* Halley's comet will pass the Earth.
|
|
559
|
-
*
|
|
560
|
-
* The result of this method is obtained by invoking the
|
|
561
|
-
* {@link TemporalAdjuster#adjustInto} method on the
|
|
562
|
-
* specified adjuster passing `this` as the argument.
|
|
563
|
-
*
|
|
564
|
-
* This instance is immutable and unaffected by this method call.
|
|
565
|
-
*
|
|
566
|
-
* @param {TemporalAdjuster} adjuster the adjuster to use, not null
|
|
567
|
-
* @return {YearMonth} based on `this` with the adjustment made, not null
|
|
568
|
-
* @throws DateTimeException if the adjustment cannot be made
|
|
569
|
-
* @throws ArithmeticException if numeric overflow occurs
|
|
570
|
-
*/
|
|
571
|
-
withAdjuster(adjuster) {
|
|
572
|
-
requireNonNull(adjuster, 'adjuster');
|
|
573
|
-
return adjuster.adjustInto(this);
|
|
574
|
-
}
|
|
575
|
-
|
|
576
548
|
/**
|
|
577
549
|
* Returns a copy of this year-month with the specified field set to a new value.
|
|
578
550
|
*
|
|
@@ -619,7 +591,7 @@ export class YearMonth extends Temporal {
|
|
|
619
591
|
* @throws DateTimeException if the field cannot be set
|
|
620
592
|
* @throws ArithmeticException if numeric overflow occurs
|
|
621
593
|
*/
|
|
622
|
-
|
|
594
|
+
_withField(field, newValue) {
|
|
623
595
|
requireNonNull(field, 'field');
|
|
624
596
|
requireInstance(field, TemporalField, 'field');
|
|
625
597
|
if (field instanceof ChronoField) {
|
|
@@ -632,7 +604,7 @@ export class YearMonth extends Temporal {
|
|
|
632
604
|
case ChronoField.YEAR: return this.withYear(newValue);
|
|
633
605
|
case ChronoField.ERA: return (this.getLong(ChronoField.ERA) === newValue ? this : this.withYear(1 - this._year));
|
|
634
606
|
}
|
|
635
|
-
throw new UnsupportedTemporalTypeException(
|
|
607
|
+
throw new UnsupportedTemporalTypeException(`Unsupported field: ${field}`);
|
|
636
608
|
}
|
|
637
609
|
return field.adjustInto(this, newValue);
|
|
638
610
|
}
|
|
@@ -668,28 +640,6 @@ export class YearMonth extends Temporal {
|
|
|
668
640
|
|
|
669
641
|
//-----------------------------------------------------------------------
|
|
670
642
|
|
|
671
|
-
/**
|
|
672
|
-
* Returns a copy of this year-month with the specified period added.
|
|
673
|
-
*
|
|
674
|
-
* This method returns a new year-month based on this year-month with the specified period added.
|
|
675
|
-
* The adder is typically {@link Period} but may be any other type implementing
|
|
676
|
-
* the {@link TemporalAmount} interface.
|
|
677
|
-
* The calculation is delegated to the specified adjuster, which typically calls
|
|
678
|
-
* back to {@link plus}.
|
|
679
|
-
*
|
|
680
|
-
* This instance is immutable and unaffected by this method call.
|
|
681
|
-
*
|
|
682
|
-
* @param {TemporalAmount} amount the amount to add, not null
|
|
683
|
-
* @return {YearMonth} based on this year-month with the addition made, not null
|
|
684
|
-
* @throws DateTimeException if the addition cannot be made
|
|
685
|
-
* @throws ArithmeticException if numeric overflow occurs
|
|
686
|
-
*/
|
|
687
|
-
plusAmount(amount) {
|
|
688
|
-
requireNonNull(amount, 'amount');
|
|
689
|
-
requireInstance(amount, TemporalAmount, 'amount');
|
|
690
|
-
return amount.addTo(this);
|
|
691
|
-
}
|
|
692
|
-
|
|
693
643
|
/**
|
|
694
644
|
* @param {number} amountToAdd
|
|
695
645
|
* @param {TemporalUnit} unit
|
|
@@ -697,7 +647,7 @@ export class YearMonth extends Temporal {
|
|
|
697
647
|
* @throws DateTimeException if the addition cannot be made
|
|
698
648
|
* @throws ArithmeticException if numeric overflow occurs
|
|
699
649
|
*/
|
|
700
|
-
|
|
650
|
+
_plusUnit(amountToAdd, unit) {
|
|
701
651
|
requireNonNull(unit, 'unit');
|
|
702
652
|
requireInstance(unit, TemporalUnit, 'unit');
|
|
703
653
|
if (unit instanceof ChronoUnit) {
|
|
@@ -709,7 +659,7 @@ export class YearMonth extends Temporal {
|
|
|
709
659
|
case ChronoUnit.MILLENNIA: return this.plusYears(MathUtil.safeMultiply(amountToAdd, 1000));
|
|
710
660
|
case ChronoUnit.ERAS: return this.with(ChronoField.ERA, MathUtil.safeAdd(this.getLong(ChronoField.ERA), amountToAdd));
|
|
711
661
|
}
|
|
712
|
-
throw new UnsupportedTemporalTypeException(
|
|
662
|
+
throw new UnsupportedTemporalTypeException(`Unsupported unit: ${unit}`);
|
|
713
663
|
}
|
|
714
664
|
return unit.addTo(this, amountToAdd);
|
|
715
665
|
}
|
|
@@ -753,38 +703,6 @@ export class YearMonth extends Temporal {
|
|
|
753
703
|
|
|
754
704
|
//-----------------------------------------------------------------------
|
|
755
705
|
|
|
756
|
-
/**
|
|
757
|
-
* Returns a copy of this year-month with the specified period subtracted.
|
|
758
|
-
*
|
|
759
|
-
* This method returns a new year-month based on this year-month with the specified period subtracted.
|
|
760
|
-
* The subtractor is typically {@link Period} but may be any other type implementing
|
|
761
|
-
* the {@link TemporalAmount} interface.
|
|
762
|
-
* The calculation is delegated to the specified adjuster, which typically calls
|
|
763
|
-
* back to {@link minus}.
|
|
764
|
-
*
|
|
765
|
-
* This instance is immutable and unaffected by this method call.
|
|
766
|
-
*
|
|
767
|
-
* @param {TemporalAmount} amount the amount to subtract, not null
|
|
768
|
-
* @return {YearMonth} based on this year-month with the subtraction made, not null
|
|
769
|
-
* @throws DateTimeException if the subtraction cannot be made
|
|
770
|
-
* @throws ArithmeticException if numeric overflow occurs
|
|
771
|
-
*/
|
|
772
|
-
minusAmount(amount) {
|
|
773
|
-
requireNonNull(amount, 'amount');
|
|
774
|
-
return amount.subtractFrom(this);
|
|
775
|
-
}
|
|
776
|
-
|
|
777
|
-
/**
|
|
778
|
-
* @param {number} amountToSubtract the amount to subtract, not null
|
|
779
|
-
* @param {TemporalUnit} unit
|
|
780
|
-
* @return {YearMonth} based on this year-month with the subtraction made, not null
|
|
781
|
-
* @throws DateTimeException if the subtraction cannot be made
|
|
782
|
-
* @throws ArithmeticException if numeric overflow occurs
|
|
783
|
-
*/
|
|
784
|
-
minusAmountUnit(amountToSubtract, unit) {
|
|
785
|
-
return (amountToSubtract === MathUtil.MIN_SAFE_INTEGER ? this.plusAmountUnit(MathUtil.MAX_SAFE_INTEGER, unit).plusAmountUnit(1, unit) : this.plusAmountUnit(-amountToSubtract, unit));
|
|
786
|
-
}
|
|
787
|
-
|
|
788
706
|
/**
|
|
789
707
|
* Returns a copy of this year-month with the specified period in years subtracted.
|
|
790
708
|
*
|
|
@@ -939,7 +857,7 @@ export class YearMonth extends Temporal {
|
|
|
939
857
|
case ChronoUnit.MILLENNIA: return monthsUntil / 12000;
|
|
940
858
|
case ChronoUnit.ERAS: return end.getLong(ChronoField.ERA) - this.getLong(ChronoField.ERA);
|
|
941
859
|
}
|
|
942
|
-
throw new UnsupportedTemporalTypeException(
|
|
860
|
+
throw new UnsupportedTemporalTypeException(`Unsupported unit: ${unit}`);
|
|
943
861
|
}
|
|
944
862
|
return unit.between(this, end);
|
|
945
863
|
}
|
package/src/ZoneId.js
CHANGED
|
@@ -4,12 +4,12 @@
|
|
|
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 {DateTimeException} from './errors';
|
|
7
|
+
import { abstractMethodFail } from './assert';
|
|
8
|
+
import { DateTimeException } from './errors';
|
|
9
9
|
|
|
10
|
-
import {StringUtil} from './StringUtil';
|
|
10
|
+
import { StringUtil } from './StringUtil';
|
|
11
11
|
|
|
12
|
-
import {Instant} from './Instant';
|
|
12
|
+
import { Instant } from './Instant';
|
|
13
13
|
|
|
14
14
|
export class ZoneId {
|
|
15
15
|
/**
|
|
@@ -80,7 +80,7 @@ export class ZoneId {
|
|
|
80
80
|
*/
|
|
81
81
|
static of(zoneId) {
|
|
82
82
|
// Find implementation at {@link ZoneIdFactory}
|
|
83
|
-
throw new DateTimeException(
|
|
83
|
+
throw new DateTimeException(`not supported operation${zoneId}`);
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
/**
|
|
@@ -98,7 +98,7 @@ export class ZoneId {
|
|
|
98
98
|
*/
|
|
99
99
|
static ofOffset(prefix, offset) {
|
|
100
100
|
// Find implementation at {@link ZoneIdFactory}
|
|
101
|
-
throw new DateTimeException(
|
|
101
|
+
throw new DateTimeException(`not supported operation${prefix}${offset}`);
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
|
|
@@ -120,7 +120,7 @@ export class ZoneId {
|
|
|
120
120
|
*/
|
|
121
121
|
static from(temporal) {
|
|
122
122
|
// Find implementation at {@link ZoneIdFactory}
|
|
123
|
-
throw new DateTimeException(
|
|
123
|
+
throw new DateTimeException(`not supported operation${temporal}`);
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
//-----------------------------------------------------------------------
|
package/src/ZoneIdFactory.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, IllegalArgumentException} from './errors';
|
|
9
|
-
import {StringUtil} from './StringUtil';
|
|
7
|
+
import { requireNonNull } from './assert';
|
|
8
|
+
import { DateTimeException, IllegalArgumentException } from './errors';
|
|
9
|
+
import { StringUtil } from './StringUtil';
|
|
10
10
|
|
|
11
|
-
import {ZoneOffset} from './ZoneOffset';
|
|
12
|
-
import {ZoneRegion} from './ZoneRegion';
|
|
13
|
-
import {ZoneId} from './ZoneId';
|
|
11
|
+
import { ZoneOffset } from './ZoneOffset';
|
|
12
|
+
import { ZoneRegion } from './ZoneRegion';
|
|
13
|
+
import { ZoneId } from './ZoneId';
|
|
14
14
|
|
|
15
|
-
import {TemporalQueries} from './temporal/TemporalQueries';
|
|
16
|
-
import {SystemDefaultZoneId} from './zone/SystemDefaultZoneId';
|
|
17
|
-
import {ZoneRulesProvider} from './zone/ZoneRulesProvider';
|
|
15
|
+
import { TemporalQueries } from './temporal/TemporalQueries';
|
|
16
|
+
import { SystemDefaultZoneId } from './zone/SystemDefaultZoneId';
|
|
17
|
+
import { ZoneRulesProvider } from './zone/ZoneRulesProvider';
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* @see {@link ZoneId}
|
|
@@ -96,7 +96,7 @@ export class ZoneIdFactory {
|
|
|
96
96
|
return ZoneOffset.UTC;
|
|
97
97
|
}
|
|
98
98
|
if (zoneId.length === 1) {
|
|
99
|
-
throw new DateTimeException(
|
|
99
|
+
throw new DateTimeException(`Invalid zone: ${zoneId}`);
|
|
100
100
|
}
|
|
101
101
|
if (StringUtil.startsWith(zoneId, '+') || StringUtil.startsWith(zoneId, '-')) {
|
|
102
102
|
return ZoneOffset.of(zoneId);
|
|
@@ -117,7 +117,7 @@ export class ZoneIdFactory {
|
|
|
117
117
|
if (offset.totalSeconds() === 0) {
|
|
118
118
|
return new ZoneRegion('UT', offset.rules());
|
|
119
119
|
}
|
|
120
|
-
return new ZoneRegion(
|
|
120
|
+
return new ZoneRegion(`UT${offset.id()}`, offset.rules());
|
|
121
121
|
}
|
|
122
122
|
// javascript special case
|
|
123
123
|
if(zoneId === 'SYSTEM'){
|
|
@@ -151,7 +151,7 @@ export class ZoneIdFactory {
|
|
|
151
151
|
}
|
|
152
152
|
return new ZoneRegion(prefix + offset.id(), offset.rules());
|
|
153
153
|
}
|
|
154
|
-
throw new IllegalArgumentException(
|
|
154
|
+
throw new IllegalArgumentException(`Invalid prefix, must be GMT, UTC or UT: ${prefix}`);
|
|
155
155
|
}
|
|
156
156
|
|
|
157
157
|
|
|
@@ -175,8 +175,8 @@ export class ZoneIdFactory {
|
|
|
175
175
|
requireNonNull(temporal, 'temporal');
|
|
176
176
|
const obj = temporal.query(TemporalQueries.zone());
|
|
177
177
|
if (obj == null) {
|
|
178
|
-
throw new DateTimeException(
|
|
179
|
-
|
|
178
|
+
throw new DateTimeException(`Unable to obtain ZoneId from TemporalAccessor: ${
|
|
179
|
+
temporal}, type ${temporal.constructor != null ? temporal.constructor.name : ''}`);
|
|
180
180
|
}
|
|
181
181
|
return obj;
|
|
182
182
|
}
|