@js-joda/core 1.12.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +58 -1
- package/dist/js-joda.d.ts +2377 -1635
- package/dist/js-joda.esm.js +1678 -653
- package/dist/js-joda.js +1681 -654
- package/dist/js-joda.js.map +1 -1
- package/dist/js-joda.min.js +2 -2
- package/package.json +24 -21
- package/src/DayOfWeek.js +3 -3
- package/src/Duration.js +4 -4
- package/src/Instant.js +12 -54
- package/src/LocalDate.js +26 -75
- package/src/LocalDateTime.js +10 -62
- package/src/LocalTime.js +8 -61
- package/src/Month.js +4 -4
- package/src/MonthDay.js +1 -2
- package/src/OffsetDateTime.js +757 -0
- package/src/OffsetTime.js +621 -0
- package/src/Period.js +1 -1
- package/src/Year.js +73 -57
- package/src/YearMonth.js +10 -68
- package/src/ZonedDateTime.js +11 -52
- package/src/_init.js +4 -0
- package/src/chrono/ChronoLocalDate.js +2 -2
- package/src/chrono/ChronoLocalDateTime.js +2 -2
- package/src/chrono/ChronoZonedDateTime.js +2 -2
- package/src/errors.js +6 -6
- package/src/format/DateTimeBuilder.js +2 -2
- package/src/format/DateTimeFormatter.js +3 -3
- package/src/js-joda.js +6 -0
- package/src/temporal/ChronoField.js +241 -133
- package/src/temporal/ChronoUnit.js +72 -229
- package/src/temporal/DefaultInterfaceTemporal.js +118 -0
- package/src/temporal/IsoFields.js +35 -32
- package/src/temporal/Temporal.js +284 -1
- package/src/temporal/TemporalField.js +225 -1
- package/src/temporal/TemporalUnit.js +18 -19
- package/src/temporal/ValueRange.js +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@js-joda/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "a date and time library for javascript",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -19,12 +19,12 @@
|
|
|
19
19
|
],
|
|
20
20
|
"scripts": {
|
|
21
21
|
"prepublish": "npm run build-dist",
|
|
22
|
-
"test": "NODE_ENV=test ./node_modules/.bin/mocha --timeout 5000 --require @babel/register ./test/*
|
|
22
|
+
"test": "NODE_ENV=test ./node_modules/.bin/mocha --timeout 5000 --require @babel/register ./test/*Test_mochaOnly.js ./test/*Test.js ./test/**/*Test.js ./test/**/**/*Test.js",
|
|
23
23
|
"test-coverage": "NODE_ENV=test COVERAGE=1 ../../node_modules/.bin/nyc --report-dir=build/coverage --reporter=lcov --reporter html ./node_modules/.bin/mocha --timeout 5000 --require @babel/register --reporter progress ./test/*Test.js ./test/**/*Test.js ./test/**/**/*Test.js",
|
|
24
24
|
"test-browser": "./node_modules/.bin/karma start --reporters=dots --single-run",
|
|
25
|
-
"test-saucelabs": "./node_modules/.bin/karma start --reporters=\"dots,saucelabs\" --browsers=\"sl_chrome,sl_ie,sl_firefox,
|
|
25
|
+
"test-saucelabs": "./node_modules/.bin/karma start --reporters=\"dots,saucelabs\" --browsers=\"sl_chrome,sl_ie,sl_firefox,sl_ios_simulator\" --single-run=true",
|
|
26
26
|
"test-ci": "npm run build-dist && npm run test && npm run test-browser -- --browsers \"Firefox,PhantomJS\" && npm run test-ts-definitions && npm run test-coverage",
|
|
27
|
-
"test-ts-definitions": "
|
|
27
|
+
"test-ts-definitions": "TS_NODE_PROJECT='test/typescript_definitions/tsconfig.json' NODE_ENV=test mocha --timeout 5000 --require ts-node/register ./test/typescript_definitions/*.ts",
|
|
28
28
|
"build-dist": "npx rollup -c rollup.config.js",
|
|
29
29
|
"build-md-toc": "./node_modules/.bin/markdown-toc -i CheatSheet.md",
|
|
30
30
|
"build-gz-check": "gzip -kf dist/js-joda.min.js && ls -alh ./dist/js-joda.min.js*",
|
|
@@ -42,31 +42,34 @@
|
|
|
42
42
|
"author": "pithu",
|
|
43
43
|
"homepage": "https://js-joda.github.io/js-joda",
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@babel/cli": "^7.
|
|
46
|
-
"@babel/core": "^7.
|
|
47
|
-
"@babel/preset-env": "^7.
|
|
48
|
-
"@babel/register": "^7.
|
|
49
|
-
"
|
|
50
|
-
"
|
|
45
|
+
"@babel/cli": "^7.7.4",
|
|
46
|
+
"@babel/core": "^7.7.4",
|
|
47
|
+
"@babel/preset-env": "^7.7.4",
|
|
48
|
+
"@babel/register": "^7.7.4",
|
|
49
|
+
"@types/chai": "^4.2.11",
|
|
50
|
+
"@types/mocha": "^7.0.2",
|
|
51
|
+
"babel-loader": "^8.0.6",
|
|
52
|
+
"babel-plugin-istanbul": "^5.2.0",
|
|
51
53
|
"chai": "^4.2.0",
|
|
52
|
-
"coveralls": "^3.0.
|
|
53
|
-
"karma": "^4.1
|
|
54
|
+
"coveralls": "^3.0.8",
|
|
55
|
+
"karma": "^4.4.1",
|
|
54
56
|
"karma-chai-plugins": "^0.9.0",
|
|
55
|
-
"karma-chrome-launcher": "^
|
|
56
|
-
"karma-firefox-launcher": "^1.
|
|
57
|
+
"karma-chrome-launcher": "^3.1.0",
|
|
58
|
+
"karma-firefox-launcher": "^1.2.0",
|
|
57
59
|
"karma-mocha": "^1.3.0",
|
|
58
60
|
"karma-phantomjs-launcher": "^1.0.4",
|
|
59
61
|
"karma-sauce-launcher": "^2.0.2",
|
|
60
62
|
"karma-sourcemap-loader": "^0.3.7",
|
|
61
|
-
"karma-webpack": "^
|
|
63
|
+
"karma-webpack": "^4.0.2",
|
|
62
64
|
"markdown-toc": "^1.2.0",
|
|
63
|
-
"mocha": "^6.
|
|
65
|
+
"mocha": "^6.2.2",
|
|
64
66
|
"phantomjs-prebuilt": "^2.1.16",
|
|
65
|
-
"rollup": "^1.4
|
|
66
|
-
"rollup-plugin-babel": "^4.3.
|
|
67
|
-
"rollup-plugin-uglify": "^6.0.
|
|
68
|
-
"
|
|
69
|
-
"
|
|
67
|
+
"rollup": "^1.27.4",
|
|
68
|
+
"rollup-plugin-babel": "^4.3.3",
|
|
69
|
+
"rollup-plugin-uglify": "^6.0.3",
|
|
70
|
+
"ts-node": "^8.10.2",
|
|
71
|
+
"typescript": "^3.7.2",
|
|
72
|
+
"webpack": "^4.41.2"
|
|
70
73
|
},
|
|
71
74
|
"license": "BSD-3-Clause",
|
|
72
75
|
"dependencies": {}
|
package/src/DayOfWeek.js
CHANGED
|
@@ -11,7 +11,7 @@ import {assert, requireNonNull, requireInstance} from './assert';
|
|
|
11
11
|
import {ChronoField} from './temporal/ChronoField';
|
|
12
12
|
import {ChronoUnit} from './temporal/ChronoUnit';
|
|
13
13
|
import {IllegalArgumentException} from './errors';
|
|
14
|
-
import {
|
|
14
|
+
import {TemporalAccessor} from './temporal/TemporalAccessor';
|
|
15
15
|
import {TemporalQueries} from './temporal/TemporalQueries';
|
|
16
16
|
import {createTemporalQuery} from './temporal/TemporalQuery';
|
|
17
17
|
|
|
@@ -27,7 +27,7 @@ import {createTemporalQuery} from './temporal/TemporalQuery';
|
|
|
27
27
|
* DayOfWeek.SUNDAY
|
|
28
28
|
*
|
|
29
29
|
*/
|
|
30
|
-
export class DayOfWeek extends
|
|
30
|
+
export class DayOfWeek extends TemporalAccessor {
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
*
|
|
@@ -155,7 +155,7 @@ export class DayOfWeek extends Temporal {
|
|
|
155
155
|
* @return {string} the text value of the day-of-week, not null
|
|
156
156
|
*/
|
|
157
157
|
// eslint-disable-next-line no-unused-vars
|
|
158
|
-
|
|
158
|
+
displayName(style, locale) {
|
|
159
159
|
throw new IllegalArgumentException('Pattern using (localized) text not implemented yet!');
|
|
160
160
|
// return new DateTimeFormatterBuilder().appendText(ChronoField.DAY_OF_WEEK, style).toFormatter(locale).format(this);
|
|
161
161
|
}
|
package/src/Duration.js
CHANGED
|
@@ -398,7 +398,7 @@ export class Duration extends TemporalAmount /*implements TemporalAmount, Compar
|
|
|
398
398
|
* @param {Number} nanoAdjustment - the nanosecond adjustment within the second, from 0 to 999,999,999
|
|
399
399
|
*/
|
|
400
400
|
static _createSecondsNanos(seconds = 0, nanoAdjustment = 0) {
|
|
401
|
-
if (
|
|
401
|
+
if (seconds === 0 && nanoAdjustment === 0) {
|
|
402
402
|
return Duration.ZERO;
|
|
403
403
|
}
|
|
404
404
|
return new Duration(seconds, nanoAdjustment);
|
|
@@ -442,7 +442,7 @@ export class Duration extends TemporalAmount /*implements TemporalAmount, Compar
|
|
|
442
442
|
* @return {boolean} true if this duration has a total length equal to zero
|
|
443
443
|
*/
|
|
444
444
|
isZero() {
|
|
445
|
-
return
|
|
445
|
+
return this._seconds === 0 && this._nanos === 0;
|
|
446
446
|
}
|
|
447
447
|
|
|
448
448
|
/**
|
|
@@ -701,7 +701,7 @@ export class Duration extends TemporalAmount /*implements TemporalAmount, Compar
|
|
|
701
701
|
plusSecondsNanos(secondsToAdd, nanosToAdd) {
|
|
702
702
|
requireNonNull(secondsToAdd, 'secondsToAdd');
|
|
703
703
|
requireNonNull(nanosToAdd, 'nanosToAdd');
|
|
704
|
-
if (
|
|
704
|
+
if (secondsToAdd === 0 && nanosToAdd === 0) {
|
|
705
705
|
return this;
|
|
706
706
|
}
|
|
707
707
|
let epochSec = MathUtil.safeAdd(this._seconds, secondsToAdd);
|
|
@@ -720,7 +720,7 @@ export class Duration extends TemporalAmount /*implements TemporalAmount, Compar
|
|
|
720
720
|
* Otherwise {@link Duration.minusAmountUnit} is executed.
|
|
721
721
|
*
|
|
722
722
|
* @param {!(Duration|number)} durationOrNumber
|
|
723
|
-
* @param {?
|
|
723
|
+
* @param {?TemporalUnit} unit
|
|
724
724
|
* @return {Duration}
|
|
725
725
|
*/
|
|
726
726
|
minus(durationOrNumber, unit) {
|
package/src/Instant.js
CHANGED
|
@@ -11,6 +11,7 @@ import {Clock} from './Clock';
|
|
|
11
11
|
import {LocalTime} from './LocalTime';
|
|
12
12
|
import {ZonedDateTime} from './ZonedDateTime';
|
|
13
13
|
import {MathUtil} from './MathUtil';
|
|
14
|
+
import {OffsetDateTime} from './OffsetDateTime';
|
|
14
15
|
|
|
15
16
|
import {Temporal} from './temporal/Temporal';
|
|
16
17
|
import {ChronoField} from './temporal/ChronoField';
|
|
@@ -405,23 +406,6 @@ export class Instant extends Temporal {
|
|
|
405
406
|
}
|
|
406
407
|
|
|
407
408
|
//-------------------------------------------------------------------------
|
|
408
|
-
/**
|
|
409
|
-
* function overloading for {@link Instant.with}
|
|
410
|
-
*
|
|
411
|
-
* if called with 1 argument {@link Instant.withTemporalAdjuster} is called
|
|
412
|
-
* otherwise {@link Instant.with2}
|
|
413
|
-
*
|
|
414
|
-
* @param {!(TemporalAdjuster|TemporalField)} adjusterOrField
|
|
415
|
-
* @param {number} newValue
|
|
416
|
-
* @returns {Instant}
|
|
417
|
-
*/
|
|
418
|
-
with(adjusterOrField, newValue){
|
|
419
|
-
if(arguments.length === 1){
|
|
420
|
-
return this.withTemporalAdjuster(adjusterOrField);
|
|
421
|
-
} else {
|
|
422
|
-
return this.with2(adjusterOrField, newValue);
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
409
|
/**
|
|
426
410
|
* Returns an adjusted copy of this instant.
|
|
427
411
|
*
|
|
@@ -440,7 +424,7 @@ export class Instant extends Temporal {
|
|
|
440
424
|
* @throws DateTimeException if the adjustment cannot be made
|
|
441
425
|
* @throws ArithmeticException if numeric overflow occurs
|
|
442
426
|
*/
|
|
443
|
-
|
|
427
|
+
withAdjuster(adjuster) {
|
|
444
428
|
requireNonNull(adjuster, 'adjuster');
|
|
445
429
|
return adjuster.adjustInto(this);
|
|
446
430
|
}
|
|
@@ -488,7 +472,7 @@ export class Instant extends Temporal {
|
|
|
488
472
|
* @throws DateTimeException if the field cannot be set
|
|
489
473
|
* @throws ArithmeticException if numeric overflow occurs
|
|
490
474
|
*/
|
|
491
|
-
|
|
475
|
+
withFieldValue(field, newValue) {
|
|
492
476
|
requireNonNull(field, 'field');
|
|
493
477
|
if (field instanceof ChronoField) {
|
|
494
478
|
field.checkValidValue(newValue);
|
|
@@ -550,19 +534,6 @@ export class Instant extends Temporal {
|
|
|
550
534
|
}
|
|
551
535
|
|
|
552
536
|
//-----------------------------------------------------------------------
|
|
553
|
-
/**
|
|
554
|
-
*
|
|
555
|
-
* @param {TemporalAmount|number} amount
|
|
556
|
-
* @param {TemporalUnit} unit - only required if first param is a TemporalAmount
|
|
557
|
-
* @return {Instant}
|
|
558
|
-
*/
|
|
559
|
-
plus(amount, unit){
|
|
560
|
-
if(arguments.length === 1){
|
|
561
|
-
return this.plus1(amount);
|
|
562
|
-
} else {
|
|
563
|
-
return this.plus2(amount, unit);
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
537
|
|
|
567
538
|
/**
|
|
568
539
|
* @param {!TemporalAmount} amount
|
|
@@ -570,7 +541,7 @@ export class Instant extends Temporal {
|
|
|
570
541
|
* @throws DateTimeException
|
|
571
542
|
* @throws ArithmeticException
|
|
572
543
|
*/
|
|
573
|
-
|
|
544
|
+
plusAmount(amount) {
|
|
574
545
|
requireNonNull(amount, 'amount');
|
|
575
546
|
return amount.addTo(this);
|
|
576
547
|
}
|
|
@@ -582,7 +553,7 @@ export class Instant extends Temporal {
|
|
|
582
553
|
* @throws DateTimeException
|
|
583
554
|
* @throws ArithmeticException
|
|
584
555
|
*/
|
|
585
|
-
|
|
556
|
+
plusAmountUnit(amountToAdd, unit) {
|
|
586
557
|
requireNonNull(amountToAdd, 'amountToAdd');
|
|
587
558
|
requireNonNull(unit, 'unit');
|
|
588
559
|
requireInstance(unit, TemporalUnit);
|
|
@@ -653,7 +624,7 @@ export class Instant extends Temporal {
|
|
|
653
624
|
* @throws DateTimeException if the result exceeds the maximum or minimum instant
|
|
654
625
|
*/
|
|
655
626
|
_plus(secondsToAdd, nanosToAdd) {
|
|
656
|
-
if (
|
|
627
|
+
if (secondsToAdd === 0 && nanosToAdd === 0) {
|
|
657
628
|
return this;
|
|
658
629
|
}
|
|
659
630
|
let epochSec = this._seconds + secondsToAdd;
|
|
@@ -663,19 +634,6 @@ export class Instant extends Temporal {
|
|
|
663
634
|
}
|
|
664
635
|
|
|
665
636
|
//-----------------------------------------------------------------------
|
|
666
|
-
/**
|
|
667
|
-
*
|
|
668
|
-
* @param {TemporalAmount|number} amount
|
|
669
|
-
* @param {TemporalUnit} unit - only required if first param is a TemporalAmount
|
|
670
|
-
* @return {Instant}
|
|
671
|
-
*/
|
|
672
|
-
minus(amount, unit){
|
|
673
|
-
if(arguments.length === 1){
|
|
674
|
-
return this.minus1(amount);
|
|
675
|
-
} else {
|
|
676
|
-
return this.minus2(amount, unit);
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
637
|
|
|
680
638
|
/**
|
|
681
639
|
* @param {!TemporalAmount} amount
|
|
@@ -683,7 +641,7 @@ export class Instant extends Temporal {
|
|
|
683
641
|
* @throws DateTimeException
|
|
684
642
|
* @throws ArithmeticException
|
|
685
643
|
*/
|
|
686
|
-
|
|
644
|
+
minusAmount(amount) {
|
|
687
645
|
requireNonNull(amount, 'amount');
|
|
688
646
|
return amount.subtractFrom(this);
|
|
689
647
|
}
|
|
@@ -695,8 +653,8 @@ export class Instant extends Temporal {
|
|
|
695
653
|
* @throws DateTimeException
|
|
696
654
|
* @throws ArithmeticException
|
|
697
655
|
*/
|
|
698
|
-
|
|
699
|
-
return this.
|
|
656
|
+
minusAmountUnit(amountToSubtract, unit) {
|
|
657
|
+
return this.plusAmountUnit(-1 * amountToSubtract, unit);
|
|
700
658
|
}
|
|
701
659
|
|
|
702
660
|
/**
|
|
@@ -906,9 +864,9 @@ export class Instant extends Temporal {
|
|
|
906
864
|
* @return {OffsetDateTime} the offset date-time formed from this instant and the specified offset, not null
|
|
907
865
|
* @throws DateTimeException if the result exceeds the supported range
|
|
908
866
|
*/
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
867
|
+
atOffset(offset) {
|
|
868
|
+
return OffsetDateTime.ofInstant(this, offset);
|
|
869
|
+
}
|
|
912
870
|
|
|
913
871
|
/**
|
|
914
872
|
* Combines this instant with a time-zone to create a {@link ZonedDateTime}.
|
package/src/LocalDate.js
CHANGED
|
@@ -20,6 +20,8 @@ import {DateTimeFormatter} from './format/DateTimeFormatter';
|
|
|
20
20
|
|
|
21
21
|
import {Clock} from './Clock';
|
|
22
22
|
import {DayOfWeek} from './DayOfWeek';
|
|
23
|
+
import {OffsetDateTime} from './OffsetDateTime';
|
|
24
|
+
import {OffsetTime} from './OffsetTime';
|
|
23
25
|
import {Month} from './Month';
|
|
24
26
|
import {Period} from './Period';
|
|
25
27
|
import {YearConstants} from './YearConstants';
|
|
@@ -279,6 +281,10 @@ export class LocalDate extends ChronoLocalDate{
|
|
|
279
281
|
*/
|
|
280
282
|
constructor(year, month, dayOfMonth){
|
|
281
283
|
super();
|
|
284
|
+
requireNonNull(year, 'year');
|
|
285
|
+
requireNonNull(month, 'month');
|
|
286
|
+
requireNonNull(dayOfMonth, 'dayOfMonth');
|
|
287
|
+
|
|
282
288
|
if (month instanceof Month) {
|
|
283
289
|
month = month.value();
|
|
284
290
|
}
|
|
@@ -612,27 +618,6 @@ export class LocalDate extends ChronoLocalDate{
|
|
|
612
618
|
return (this.isLeapYear() ? 366 : 365);
|
|
613
619
|
}
|
|
614
620
|
|
|
615
|
-
/**
|
|
616
|
-
* function overloading for the {@link LocalDate.with} method.
|
|
617
|
-
*
|
|
618
|
-
* calling "with" with one (or less) argument, assumes that the argument is an TemporalAdjuster
|
|
619
|
-
* and {@link LocalDate.withTemporalAdjuster} is called.
|
|
620
|
-
*
|
|
621
|
-
* Otherwise a TemporalField and newValue argument is expected and
|
|
622
|
-
* {@link LocalDate.withFieldAndValue} is called.
|
|
623
|
-
*
|
|
624
|
-
* @param {!(TemporalAdjuster|TemporalField)} fieldOrAdjuster
|
|
625
|
-
* @param {number} newValue - required if first argument is a TemporalField
|
|
626
|
-
* @return {LocalDate} the new LocalDate with the newValue set.
|
|
627
|
-
*/
|
|
628
|
-
with(fieldOrAdjuster, newValue){
|
|
629
|
-
if(arguments.length < 2){
|
|
630
|
-
return this.withTemporalAdjuster(fieldOrAdjuster);
|
|
631
|
-
} else {
|
|
632
|
-
return this.withFieldAndValue(fieldOrAdjuster, newValue);
|
|
633
|
-
}
|
|
634
|
-
}
|
|
635
|
-
|
|
636
621
|
/**
|
|
637
622
|
* Returns an adjusted copy of this date.
|
|
638
623
|
*
|
|
@@ -666,7 +651,7 @@ export class LocalDate extends ChronoLocalDate{
|
|
|
666
651
|
* @throws {DateTimeException} if the adjustment cannot be made
|
|
667
652
|
* @throws {ArithmeticException} if numeric overflow occurs
|
|
668
653
|
*/
|
|
669
|
-
|
|
654
|
+
withAdjuster(adjuster) {
|
|
670
655
|
requireNonNull(adjuster, 'adjuster');
|
|
671
656
|
// optimizations
|
|
672
657
|
if (adjuster instanceof LocalDate) {
|
|
@@ -776,7 +761,7 @@ export class LocalDate extends ChronoLocalDate{
|
|
|
776
761
|
* @throws {DateTimeException} if the field cannot be set
|
|
777
762
|
* @throws {ArithmeticException} if numeric overflow occurs
|
|
778
763
|
*/
|
|
779
|
-
|
|
764
|
+
withFieldValue(field, newValue) {
|
|
780
765
|
assert(field != null, 'field', NullPointerException);
|
|
781
766
|
if (field instanceof ChronoField) {
|
|
782
767
|
const f = field;
|
|
@@ -867,26 +852,6 @@ export class LocalDate extends ChronoLocalDate{
|
|
|
867
852
|
return LocalDate.ofYearDay(this._year, dayOfYear);
|
|
868
853
|
}
|
|
869
854
|
|
|
870
|
-
/**
|
|
871
|
-
* function overloading for plus
|
|
872
|
-
*
|
|
873
|
-
* called with 1 (or less) arguments, p1 is expected to be a TemporalAmount and {@link LocalDate.plus1}
|
|
874
|
-
* is called.
|
|
875
|
-
*
|
|
876
|
-
* Otherwise {@link LocalDate.plus2} is called.
|
|
877
|
-
*
|
|
878
|
-
* @param {!(TemporalAmount|number)} p1
|
|
879
|
-
* @param {TemporalUnit} p2 - required if called with 2 arguments
|
|
880
|
-
* @return {LocalDate}
|
|
881
|
-
*/
|
|
882
|
-
plus(p1, p2){
|
|
883
|
-
if(arguments.length < 2){
|
|
884
|
-
return this.plus1(p1);
|
|
885
|
-
} else {
|
|
886
|
-
return this.plus2(p1, p2);
|
|
887
|
-
}
|
|
888
|
-
}
|
|
889
|
-
|
|
890
855
|
/**
|
|
891
856
|
* Returns a copy of this date with the specified period added.
|
|
892
857
|
*
|
|
@@ -894,14 +859,14 @@ export class LocalDate extends ChronoLocalDate{
|
|
|
894
859
|
* The amount is typically {@link Period} but may be any other type implementing
|
|
895
860
|
* the {@link TemporalAmount} interface.
|
|
896
861
|
* The calculation is delegated to the specified adjuster, which typically calls
|
|
897
|
-
* back to {@link LocalDate.
|
|
862
|
+
* back to {@link LocalDate.plusAmountUnit}.
|
|
898
863
|
*
|
|
899
864
|
* @param {!TemporalAmount} amount - the amount to add, not null
|
|
900
865
|
* @return {LocalDate} a {@link LocalDate} based on this date with the addition made, not null
|
|
901
866
|
* @throws {DateTimeException} if the addition cannot be made
|
|
902
867
|
* @throws {ArithmeticException} if numeric overflow occurs
|
|
903
868
|
*/
|
|
904
|
-
|
|
869
|
+
plusAmount(amount) {
|
|
905
870
|
requireNonNull(amount, 'amount');
|
|
906
871
|
return amount.addTo(this);
|
|
907
872
|
}
|
|
@@ -919,7 +884,7 @@ export class LocalDate extends ChronoLocalDate{
|
|
|
919
884
|
* @return {LocalDate} a {@link LocalDate} based on this date with the specified period added, not null
|
|
920
885
|
* @throws {DateTimeException} if the unit cannot be added to this type
|
|
921
886
|
*/
|
|
922
|
-
|
|
887
|
+
plusAmountUnit(amountToAdd, unit) {
|
|
923
888
|
requireNonNull(amountToAdd, 'amountToAdd');
|
|
924
889
|
requireNonNull(unit, 'unit');
|
|
925
890
|
if (unit instanceof ChronoUnit) {
|
|
@@ -1030,26 +995,6 @@ export class LocalDate extends ChronoLocalDate{
|
|
|
1030
995
|
return LocalDate.ofEpochDay(mjDay);
|
|
1031
996
|
}
|
|
1032
997
|
|
|
1033
|
-
/**
|
|
1034
|
-
* function overloading for minus
|
|
1035
|
-
*
|
|
1036
|
-
* called with 1 (or less) arguments, p1 is expected to be a TemporalAmount and {@link LocalDate.minus1}
|
|
1037
|
-
* is called.
|
|
1038
|
-
*
|
|
1039
|
-
* Otherwise {@link LocalDate.minus2} is called.
|
|
1040
|
-
*
|
|
1041
|
-
* @param {!(TemporalAmount|number)} p1
|
|
1042
|
-
* @param {TemporalUnit} p2 - required if called with 2 arguments
|
|
1043
|
-
* @return {LocalDate}
|
|
1044
|
-
*/
|
|
1045
|
-
minus(p1, p2){
|
|
1046
|
-
if(arguments.length < 2){
|
|
1047
|
-
return this.minus1(p1);
|
|
1048
|
-
} else {
|
|
1049
|
-
return this.minus2(p1, p2);
|
|
1050
|
-
}
|
|
1051
|
-
}
|
|
1052
|
-
|
|
1053
998
|
/**
|
|
1054
999
|
* Returns a copy of this date with the specified period subtracted.
|
|
1055
1000
|
*
|
|
@@ -1064,7 +1009,7 @@ export class LocalDate extends ChronoLocalDate{
|
|
|
1064
1009
|
* @throws {DateTimeException} if the subtraction cannot be made
|
|
1065
1010
|
* @throws {ArithmeticException} if numeric overflow occurs
|
|
1066
1011
|
*/
|
|
1067
|
-
|
|
1012
|
+
minusAmount(amount) {
|
|
1068
1013
|
requireNonNull(amount, 'amount');
|
|
1069
1014
|
return amount.subtractFrom(this);
|
|
1070
1015
|
}
|
|
@@ -1082,10 +1027,10 @@ export class LocalDate extends ChronoLocalDate{
|
|
|
1082
1027
|
* @return {LocalDate} a {@link LocalDate} based on this date with the specified period subtracted, not null
|
|
1083
1028
|
* @throws {DateTimeException} if the unit cannot be added to this type
|
|
1084
1029
|
*/
|
|
1085
|
-
|
|
1030
|
+
minusAmountUnit(amountToSubtract, unit) {
|
|
1086
1031
|
requireNonNull(amountToSubtract, 'amountToSubtract');
|
|
1087
1032
|
requireNonNull(unit, 'unit');
|
|
1088
|
-
return this.
|
|
1033
|
+
return this.plusAmountUnit(-1 * amountToSubtract, unit);
|
|
1089
1034
|
}
|
|
1090
1035
|
|
|
1091
1036
|
/**
|
|
@@ -1373,7 +1318,7 @@ export class LocalDate extends ChronoLocalDate{
|
|
|
1373
1318
|
* if called with 1 argument {@link LocalDate.atTime1} is called
|
|
1374
1319
|
* otherwise {@link LocalDate.atTime4}
|
|
1375
1320
|
*
|
|
1376
|
-
* @return {LocalDateTime} the local date-time formed from this date and the specified params
|
|
1321
|
+
* @return {LocalDateTime|OffsetDateTime} the local date-time formed from this date and the specified params
|
|
1377
1322
|
*/
|
|
1378
1323
|
atTime(){
|
|
1379
1324
|
if(arguments.length===1){
|
|
@@ -1390,10 +1335,18 @@ export class LocalDate extends ChronoLocalDate{
|
|
|
1390
1335
|
* All possible combinations of date and time are valid.
|
|
1391
1336
|
*
|
|
1392
1337
|
* @param {LocalTime} time - the time to combine with, not null
|
|
1393
|
-
* @return {LocalDateTime} the
|
|
1338
|
+
* @return {LocalDateTime|OffsetDateTime} the date-time formed from this date and the specified time, not null
|
|
1394
1339
|
*/
|
|
1395
1340
|
atTime1(time) {
|
|
1396
|
-
|
|
1341
|
+
requireNonNull(time, 'time');
|
|
1342
|
+
if (time instanceof LocalTime) {
|
|
1343
|
+
return LocalDateTime.of(this, time);
|
|
1344
|
+
} else if (time instanceof OffsetTime) {
|
|
1345
|
+
return this._atTimeOffsetTime(time);
|
|
1346
|
+
} else {
|
|
1347
|
+
throw new IllegalArgumentException('time must be an instance of LocalTime or OffsetTime' +
|
|
1348
|
+
(time && time.constructor && time.constructor.name ? ', but is ' + time.constructor.name : ''));
|
|
1349
|
+
}
|
|
1397
1350
|
}
|
|
1398
1351
|
|
|
1399
1352
|
/**
|
|
@@ -1424,11 +1377,9 @@ export class LocalDate extends ChronoLocalDate{
|
|
|
1424
1377
|
* @param {OffsetTime} time - the time to combine with, not null
|
|
1425
1378
|
* @return {OffsetDateTime} the offset date-time formed from this date and the specified time, not null
|
|
1426
1379
|
*/
|
|
1427
|
-
/*
|
|
1428
1380
|
_atTimeOffsetTime(time) { // atTime(offsetTime)
|
|
1429
|
-
return OffsetDateTime.of(LocalDateTime.of(this, time.toLocalTime()), time.
|
|
1381
|
+
return OffsetDateTime.of(LocalDateTime.of(this, time.toLocalTime()), time.offset());
|
|
1430
1382
|
}
|
|
1431
|
-
*/
|
|
1432
1383
|
|
|
1433
1384
|
/**
|
|
1434
1385
|
* Combines this date with the time of midnight to create a {@link LocalDateTime}
|
package/src/LocalDateTime.js
CHANGED
|
@@ -12,6 +12,7 @@ import {Clock} from './Clock';
|
|
|
12
12
|
import {Instant} from './Instant';
|
|
13
13
|
import {LocalDate} from './LocalDate';
|
|
14
14
|
import {LocalTime} from './LocalTime';
|
|
15
|
+
import {OffsetDateTime} from './OffsetDateTime';
|
|
15
16
|
import {ZonedDateTime} from './ZonedDateTime';
|
|
16
17
|
import {ZoneId} from './ZoneId';
|
|
17
18
|
import {ZoneOffset} from './ZoneOffset';
|
|
@@ -316,7 +317,7 @@ implements Temporal, TemporalAdjuster, Serializable */ {
|
|
|
316
317
|
* @return {LocalDateTime} the date-time, not null
|
|
317
318
|
*/
|
|
318
319
|
_withDateTime(newDate, newTime) {
|
|
319
|
-
if (this._date
|
|
320
|
+
if (this._date.equals(newDate) && this._time.equals(newTime)) {
|
|
320
321
|
return this;
|
|
321
322
|
}
|
|
322
323
|
return new LocalDateTime(newDate, newTime);
|
|
@@ -593,23 +594,6 @@ implements Temporal, TemporalAdjuster, Serializable */ {
|
|
|
593
594
|
}
|
|
594
595
|
|
|
595
596
|
//-----------------------------------------------------------------------
|
|
596
|
-
/**
|
|
597
|
-
* function overloading for {@link LocalDateTime.with}
|
|
598
|
-
*
|
|
599
|
-
* if called with 1 argument, {@link LocalDateTime.withTemporalAdjuster} is applied,
|
|
600
|
-
* otherwise {@link LocalDateTime.with2}.
|
|
601
|
-
*
|
|
602
|
-
* @param {!(TemporalAdjuster|TemporalField)} adjusterOrField
|
|
603
|
-
* @param {number} newValue - only require if first argument is a TemporalField
|
|
604
|
-
* @returns {LocalDateTime}
|
|
605
|
-
*/
|
|
606
|
-
with(adjusterOrField, newValue){
|
|
607
|
-
if(arguments.length === 1){
|
|
608
|
-
return this.withTemporalAdjuster(adjusterOrField);
|
|
609
|
-
} else {
|
|
610
|
-
return this.with2(adjusterOrField, newValue);
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
597
|
|
|
614
598
|
/**
|
|
615
599
|
* Returns an adjusted copy of this date-time.
|
|
@@ -653,7 +637,7 @@ implements Temporal, TemporalAdjuster, Serializable */ {
|
|
|
653
637
|
* @throws {DateTimeException} if the adjustment cannot be made
|
|
654
638
|
* @throws {ArithmeticException} if numeric overflow occurs
|
|
655
639
|
*/
|
|
656
|
-
|
|
640
|
+
withAdjuster(adjuster) {
|
|
657
641
|
requireNonNull(adjuster, 'adjuster');
|
|
658
642
|
// optimizations
|
|
659
643
|
if (adjuster instanceof LocalDate) {
|
|
@@ -699,7 +683,7 @@ implements Temporal, TemporalAdjuster, Serializable */ {
|
|
|
699
683
|
* @throws {DateTimeException} if the field cannot be set
|
|
700
684
|
* @throws {ArithmeticException} if numeric overflow occurs
|
|
701
685
|
*/
|
|
702
|
-
|
|
686
|
+
withFieldValue(field, newValue) {
|
|
703
687
|
requireNonNull(field, 'field');
|
|
704
688
|
if (field instanceof ChronoField) {
|
|
705
689
|
if (field.isTimeBased()) {
|
|
@@ -855,23 +839,6 @@ implements Temporal, TemporalAdjuster, Serializable */ {
|
|
|
855
839
|
}
|
|
856
840
|
|
|
857
841
|
//-----------------------------------------------------------------------
|
|
858
|
-
/**
|
|
859
|
-
* function overloading for {@link LocalDateTime.plus}
|
|
860
|
-
*
|
|
861
|
-
* if called with 1 argument {@link LocalDateTime.plusTemporalAmount} is applied,
|
|
862
|
-
* otherwise {@link LocalDateTime.plus2}
|
|
863
|
-
*
|
|
864
|
-
* @param {!(TemporalAmount|number)} amount
|
|
865
|
-
* @param {TemporalUnit} unit
|
|
866
|
-
* @returns {LocalDateTime}
|
|
867
|
-
*/
|
|
868
|
-
plus(amount, unit){
|
|
869
|
-
if(arguments.length === 1){
|
|
870
|
-
return this.plusTemporalAmount(amount);
|
|
871
|
-
} else {
|
|
872
|
-
return this.plus2(amount, unit);
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
842
|
|
|
876
843
|
/**
|
|
877
844
|
* Returns a copy of this date-time with the specified period added.
|
|
@@ -889,7 +856,7 @@ implements Temporal, TemporalAdjuster, Serializable */ {
|
|
|
889
856
|
* @throws {DateTimeException} if the addition cannot be made
|
|
890
857
|
* @throws {ArithmeticException} if numeric overflow occurs
|
|
891
858
|
*/
|
|
892
|
-
|
|
859
|
+
plusAmount(amount) {
|
|
893
860
|
requireNonNull(amount, 'amount');
|
|
894
861
|
return amount.addTo(this);
|
|
895
862
|
}
|
|
@@ -909,7 +876,7 @@ implements Temporal, TemporalAdjuster, Serializable */ {
|
|
|
909
876
|
* @return {LocalDateTime} a {@link LocalDateTime} based on this date-time with the specified period added, not null
|
|
910
877
|
* @throws {DateTimeException} if the unit cannot be added to this type
|
|
911
878
|
*/
|
|
912
|
-
|
|
879
|
+
plusAmountUnit(amountToAdd, unit) {
|
|
913
880
|
requireNonNull(unit, 'unit');
|
|
914
881
|
if (unit instanceof ChronoUnit) {
|
|
915
882
|
switch (unit) {
|
|
@@ -1069,23 +1036,6 @@ implements Temporal, TemporalAdjuster, Serializable */ {
|
|
|
1069
1036
|
}
|
|
1070
1037
|
|
|
1071
1038
|
//-----------------------------------------------------------------------
|
|
1072
|
-
/**
|
|
1073
|
-
* function overloading for {@link LocalDateTime.minus}
|
|
1074
|
-
*
|
|
1075
|
-
* if called with 1 argument {@link LocalDateTime.minusTemporalAmount} is applied,
|
|
1076
|
-
* otherwise {@link LocalDateTime.minus2}
|
|
1077
|
-
*
|
|
1078
|
-
* @param {!(TemporalAmount|number)} amount
|
|
1079
|
-
* @param {TemporalUnit} unit
|
|
1080
|
-
* @returns {LocalDateTime}
|
|
1081
|
-
*/
|
|
1082
|
-
minus(amount, unit){
|
|
1083
|
-
if(arguments.length === 1){
|
|
1084
|
-
return this.minusTemporalAmount(amount);
|
|
1085
|
-
} else {
|
|
1086
|
-
return this.minus2(amount, unit);
|
|
1087
|
-
}
|
|
1088
|
-
}
|
|
1089
1039
|
|
|
1090
1040
|
/**
|
|
1091
1041
|
* Returns a copy of this date-time with the specified period subtracted.
|
|
@@ -1103,7 +1053,7 @@ implements Temporal, TemporalAdjuster, Serializable */ {
|
|
|
1103
1053
|
* @throws {DateTimeException} if the subtraction cannot be made
|
|
1104
1054
|
* @throws {ArithmeticException} if numeric overflow occurs
|
|
1105
1055
|
*/
|
|
1106
|
-
|
|
1056
|
+
minusAmount(amount) {
|
|
1107
1057
|
requireNonNull(amount, 'amount');
|
|
1108
1058
|
return amount.subtractFrom(this);
|
|
1109
1059
|
}
|
|
@@ -1123,9 +1073,9 @@ implements Temporal, TemporalAdjuster, Serializable */ {
|
|
|
1123
1073
|
* @return {LocalDateTime} a {@link LocalDateTime} based on this date-time with the specified period subtracted, not null
|
|
1124
1074
|
* @throws {DateTimeException} if the unit cannot be added to this type
|
|
1125
1075
|
*/
|
|
1126
|
-
|
|
1076
|
+
minusAmountUnit(amountToSubtract, unit) {
|
|
1127
1077
|
requireNonNull(unit, 'unit');
|
|
1128
|
-
return this.
|
|
1078
|
+
return this.plusAmountUnit(-1 * amountToSubtract, unit);
|
|
1129
1079
|
}
|
|
1130
1080
|
|
|
1131
1081
|
//-----------------------------------------------------------------------
|
|
@@ -1282,7 +1232,7 @@ implements Temporal, TemporalAdjuster, Serializable */ {
|
|
|
1282
1232
|
*/
|
|
1283
1233
|
_plusWithOverflow(newDate, hours, minutes, seconds, nanos, sign) {
|
|
1284
1234
|
// 9223372036854775808 long, 2147483648 int
|
|
1285
|
-
if (
|
|
1235
|
+
if (hours === 0 && minutes === 0 && seconds === 0 && nanos === 0) {
|
|
1286
1236
|
return this._withDateTime(newDate, this._time);
|
|
1287
1237
|
}
|
|
1288
1238
|
let totDays = MathUtil.intDiv(nanos, LocalTime.NANOS_PER_DAY) + // max/24*60*60*1B
|
|
@@ -1465,11 +1415,9 @@ implements Temporal, TemporalAdjuster, Serializable */ {
|
|
|
1465
1415
|
* @param {ZoneOffset} offset the offset to combine with, not null
|
|
1466
1416
|
* @return {OffsetDateTime} the offset date-time formed from this date-time and the specified offset, not null
|
|
1467
1417
|
*/
|
|
1468
|
-
/*
|
|
1469
1418
|
atOffset(offset) {
|
|
1470
1419
|
return OffsetDateTime.of(this, offset);
|
|
1471
1420
|
}
|
|
1472
|
-
*/
|
|
1473
1421
|
|
|
1474
1422
|
/**
|
|
1475
1423
|
* Combines this date-time with a time-zone to create a {@link ZonedDateTime}.
|