@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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@js-joda/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.2.1",
|
|
4
4
|
"description": "a date and time library for javascript",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -18,17 +18,17 @@
|
|
|
18
18
|
"README.md"
|
|
19
19
|
],
|
|
20
20
|
"scripts": {
|
|
21
|
-
"
|
|
22
|
-
"test": "NODE_ENV=test
|
|
23
|
-
"test-coverage": "NODE_ENV=test COVERAGE=1
|
|
24
|
-
"test-browser": "
|
|
25
|
-
"test-saucelabs": "
|
|
26
|
-
"test-ci": "npm run build-dist && npm run test && npm run test-browser
|
|
21
|
+
"version": "npm run build-dist",
|
|
22
|
+
"test": "NODE_ENV=test npx mocha --timeout 5000 --require @babel/register ./test/*Test_mochaOnly.js ./test/*Test.js ./test/**/*Test.js ./test/**/**/*Test.js",
|
|
23
|
+
"test-coverage": "NODE_ENV=test COVERAGE=1 npx nyc --report-dir=build/coverage --reporter=lcov --reporter html npx mocha --timeout 5000 --require @babel/register --reporter progress ./test/*Test.js ./test/**/*Test.js ./test/**/**/*Test.js",
|
|
24
|
+
"test-browser": "npx karma start --reporters=dots --single-run",
|
|
25
|
+
"test-saucelabs": "npx karma start --reporters=\"dots,saucelabs\" --browsers=\"sl_chrome,sl_ie,sl_firefox,sl_ios_simulator\" --single-run=true",
|
|
26
|
+
"test-ci": "npm run build-dist && npm run test && npm run test-browser && npm run test-ts-definitions && npm run test-coverage",
|
|
27
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
|
-
"build-md-toc": "
|
|
29
|
+
"build-md-toc": "npx markdown-toc -i CheatSheet.md",
|
|
30
30
|
"build-gz-check": "gzip -kf dist/js-joda.min.js && ls -alh ./dist/js-joda.min.js*",
|
|
31
|
-
"lint": "
|
|
31
|
+
"lint": "npx eslint ."
|
|
32
32
|
},
|
|
33
33
|
"keywords": [
|
|
34
34
|
"date",
|
|
@@ -41,36 +41,6 @@
|
|
|
41
41
|
},
|
|
42
42
|
"author": "pithu",
|
|
43
43
|
"homepage": "https://js-joda.github.io/js-joda",
|
|
44
|
-
"devDependencies": {
|
|
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",
|
|
53
|
-
"chai": "^4.2.0",
|
|
54
|
-
"coveralls": "^3.0.8",
|
|
55
|
-
"karma": "^4.4.1",
|
|
56
|
-
"karma-chai-plugins": "^0.9.0",
|
|
57
|
-
"karma-chrome-launcher": "^3.1.0",
|
|
58
|
-
"karma-firefox-launcher": "^1.2.0",
|
|
59
|
-
"karma-mocha": "^1.3.0",
|
|
60
|
-
"karma-phantomjs-launcher": "^1.0.4",
|
|
61
|
-
"karma-sauce-launcher": "^2.0.2",
|
|
62
|
-
"karma-sourcemap-loader": "^0.3.7",
|
|
63
|
-
"karma-webpack": "^4.0.2",
|
|
64
|
-
"markdown-toc": "^1.2.0",
|
|
65
|
-
"mocha": "^6.2.2",
|
|
66
|
-
"phantomjs-prebuilt": "^2.1.16",
|
|
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"
|
|
73
|
-
},
|
|
74
44
|
"license": "BSD-3-Clause",
|
|
75
|
-
"
|
|
45
|
+
"gitHead": "485c4b2be852563615e2d2a8c3f0bca22d86bcd4"
|
|
76
46
|
}
|
package/src/Clock.js
CHANGED
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
* @license BSD-3-Clause (see LICENSE in the root directory of this source tree)
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {abstractMethodFail, requireNonNull} from './assert';
|
|
8
|
-
import {Instant} from './Instant';
|
|
9
|
-
import {ZoneId} from './ZoneId';
|
|
10
|
-
import {ZoneOffset} from './ZoneOffset';
|
|
7
|
+
import { abstractMethodFail, requireNonNull } from './assert';
|
|
8
|
+
import { Instant } from './Instant';
|
|
9
|
+
import { ZoneId } from './ZoneId';
|
|
10
|
+
import { ZoneOffset } from './ZoneOffset';
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* A clock providing access to the current instant, date and time using a time-zone.
|
|
@@ -121,7 +121,7 @@ export class Clock {
|
|
|
121
121
|
* providing that the base clock is.
|
|
122
122
|
*
|
|
123
123
|
* @param baseClock the base clock to add the duration to, not null
|
|
124
|
-
* @param
|
|
124
|
+
* @param duration the duration to add, not null
|
|
125
125
|
* @return a clock based on the base clock with the duration added, not null
|
|
126
126
|
*/
|
|
127
127
|
static offset(baseClock, duration) {
|
|
@@ -170,7 +170,6 @@ export class Clock {
|
|
|
170
170
|
* to a date or time using a time-zone. This method returns a clock with
|
|
171
171
|
* similar properties but using a different time-zone.
|
|
172
172
|
*
|
|
173
|
-
* @param zone the time-zone to change to, not null
|
|
174
173
|
* @return a clock based on this clock with the specified time-zone, not null
|
|
175
174
|
*/
|
|
176
175
|
withZone(){
|
|
@@ -238,7 +237,7 @@ class SystemClock extends Clock {
|
|
|
238
237
|
* @returns {string}
|
|
239
238
|
*/
|
|
240
239
|
toString(){
|
|
241
|
-
return
|
|
240
|
+
return `SystemClock[${this._zone.toString()}]`;
|
|
242
241
|
}
|
|
243
242
|
|
|
244
243
|
}
|
|
@@ -325,6 +324,6 @@ class OffsetClock extends Clock {
|
|
|
325
324
|
}
|
|
326
325
|
|
|
327
326
|
toString() {
|
|
328
|
-
return
|
|
327
|
+
return `OffsetClock[${this._baseClock},${this._offset}]`;
|
|
329
328
|
}
|
|
330
|
-
}
|
|
329
|
+
}
|
package/src/DayOfWeek.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 {DateTimeException, UnsupportedTemporalTypeException, NullPointerException} from './errors';
|
|
8
|
-
import {MathUtil} from './MathUtil';
|
|
9
|
-
import {assert, requireNonNull, requireInstance} from './assert';
|
|
7
|
+
import { DateTimeException, UnsupportedTemporalTypeException, NullPointerException } from './errors';
|
|
8
|
+
import { MathUtil } from './MathUtil';
|
|
9
|
+
import { assert, requireNonNull, requireInstance } from './assert';
|
|
10
10
|
|
|
11
|
-
import {ChronoField} from './temporal/ChronoField';
|
|
12
|
-
import {ChronoUnit} from './temporal/ChronoUnit';
|
|
13
|
-
import {IllegalArgumentException} from './errors';
|
|
14
|
-
import {TemporalAccessor} from './temporal/TemporalAccessor';
|
|
15
|
-
import {TemporalQueries} from './temporal/TemporalQueries';
|
|
16
|
-
import {createTemporalQuery} from './temporal/TemporalQuery';
|
|
11
|
+
import { ChronoField } from './temporal/ChronoField';
|
|
12
|
+
import { ChronoUnit } from './temporal/ChronoUnit';
|
|
13
|
+
import { IllegalArgumentException } from './errors';
|
|
14
|
+
import { TemporalAccessor } from './temporal/TemporalAccessor';
|
|
15
|
+
import { TemporalQueries } from './temporal/TemporalQueries';
|
|
16
|
+
import { createTemporalQuery } from './temporal/TemporalQuery';
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* ### Static properties of Class {@link DayOfWeek}
|
|
@@ -93,7 +93,7 @@ export class DayOfWeek extends TemporalAccessor {
|
|
|
93
93
|
*/
|
|
94
94
|
static of(dayOfWeek) {
|
|
95
95
|
if (dayOfWeek < 1 || dayOfWeek > 7) {
|
|
96
|
-
throw new DateTimeException(
|
|
96
|
+
throw new DateTimeException(`Invalid value for DayOfWeek: ${dayOfWeek}`);
|
|
97
97
|
}
|
|
98
98
|
return ENUMS[dayOfWeek - 1];
|
|
99
99
|
}
|
|
@@ -122,8 +122,8 @@ export class DayOfWeek extends TemporalAccessor {
|
|
|
122
122
|
return DayOfWeek.of(temporal.get(ChronoField.DAY_OF_WEEK));
|
|
123
123
|
} catch (ex) {
|
|
124
124
|
if(ex instanceof DateTimeException) {
|
|
125
|
-
throw new DateTimeException(
|
|
126
|
-
temporal
|
|
125
|
+
throw new DateTimeException(`Unable to obtain DayOfWeek from TemporalAccessor: ${
|
|
126
|
+
temporal}, type ${temporal.constructor != null ? temporal.constructor.name : ''}`, ex);
|
|
127
127
|
} else {
|
|
128
128
|
throw ex;
|
|
129
129
|
}
|
|
@@ -211,7 +211,7 @@ export class DayOfWeek extends TemporalAccessor {
|
|
|
211
211
|
if (field === ChronoField.DAY_OF_WEEK) {
|
|
212
212
|
return field.range();
|
|
213
213
|
} else if (field instanceof ChronoField) {
|
|
214
|
-
throw new UnsupportedTemporalTypeException(
|
|
214
|
+
throw new UnsupportedTemporalTypeException(`Unsupported field: ${field}`);
|
|
215
215
|
}
|
|
216
216
|
return field.rangeRefinedBy(this);
|
|
217
217
|
}
|
|
@@ -272,7 +272,7 @@ export class DayOfWeek extends TemporalAccessor {
|
|
|
272
272
|
if (field === ChronoField.DAY_OF_WEEK) {
|
|
273
273
|
return this.value();
|
|
274
274
|
} else if (field instanceof ChronoField) {
|
|
275
|
-
throw new UnsupportedTemporalTypeException(
|
|
275
|
+
throw new UnsupportedTemporalTypeException(`Unsupported field: ${field}`);
|
|
276
276
|
}
|
|
277
277
|
return field.getFrom(this);
|
|
278
278
|
}
|
package/src/Duration.js
CHANGED
|
@@ -3,16 +3,16 @@
|
|
|
3
3
|
* @copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
|
|
4
4
|
* @license BSD-3-Clause (see LICENSE in the root directory of this source tree)
|
|
5
5
|
*/
|
|
6
|
-
import {requireNonNull, requireInstance} from './assert';
|
|
7
|
-
import {ArithmeticException, DateTimeParseException, UnsupportedTemporalTypeException} from './errors';
|
|
8
|
-
import {MathUtil, MAX_SAFE_INTEGER, MIN_SAFE_INTEGER} from './MathUtil';
|
|
6
|
+
import { requireNonNull, requireInstance } from './assert';
|
|
7
|
+
import { ArithmeticException, DateTimeParseException, UnsupportedTemporalTypeException } from './errors';
|
|
8
|
+
import { MathUtil, MAX_SAFE_INTEGER, MIN_SAFE_INTEGER } from './MathUtil';
|
|
9
9
|
|
|
10
|
-
import {ChronoField} from './temporal/ChronoField';
|
|
11
|
-
import {ChronoUnit} from './temporal/ChronoUnit';
|
|
12
|
-
import {TemporalAmount} from './temporal/TemporalAmount';
|
|
13
|
-
import {TemporalUnit} from './temporal/TemporalUnit';
|
|
10
|
+
import { ChronoField } from './temporal/ChronoField';
|
|
11
|
+
import { ChronoUnit } from './temporal/ChronoUnit';
|
|
12
|
+
import { TemporalAmount } from './temporal/TemporalAmount';
|
|
13
|
+
import { TemporalUnit } from './temporal/TemporalUnit';
|
|
14
14
|
|
|
15
|
-
import {LocalTime} from './LocalTime';
|
|
15
|
+
import { LocalTime } from './LocalTime';
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* A time-based amount of time, such as '34.5 seconds'.
|
|
@@ -355,7 +355,7 @@ export class Duration extends TemporalAmount /*implements TemporalAmount, Compar
|
|
|
355
355
|
}
|
|
356
356
|
return MathUtil.safeMultiply(parseFloat(parsed), multiplier);
|
|
357
357
|
} catch (ex) {
|
|
358
|
-
throw new DateTimeParseException(
|
|
358
|
+
throw new DateTimeParseException(`Text cannot be parsed to a Duration: ${errorText}`, text, 0, ex);
|
|
359
359
|
}
|
|
360
360
|
}
|
|
361
361
|
|
|
@@ -364,7 +364,7 @@ export class Duration extends TemporalAmount /*implements TemporalAmount, Compar
|
|
|
364
364
|
if (parsed == null || parsed.length === 0) {
|
|
365
365
|
return 0;
|
|
366
366
|
}
|
|
367
|
-
parsed = (parsed
|
|
367
|
+
parsed = (`${parsed}000000000`).substring(0, 9);
|
|
368
368
|
return parseFloat(parsed) * negate;
|
|
369
369
|
}
|
|
370
370
|
|
|
@@ -423,7 +423,7 @@ export class Duration extends TemporalAmount /*implements TemporalAmount, Compar
|
|
|
423
423
|
} else if (unit === ChronoUnit.NANOS) {
|
|
424
424
|
return this._nanos;
|
|
425
425
|
} else {
|
|
426
|
-
throw new UnsupportedTemporalTypeException(
|
|
426
|
+
throw new UnsupportedTemporalTypeException(`Unsupported unit: ${unit}`);
|
|
427
427
|
}
|
|
428
428
|
}
|
|
429
429
|
|
|
@@ -1151,10 +1151,10 @@ export class Duration extends TemporalAmount /*implements TemporalAmount, Compar
|
|
|
1151
1151
|
const secs = MathUtil.intMod(this._seconds, LocalTime.SECONDS_PER_MINUTE);
|
|
1152
1152
|
let rval = 'PT';
|
|
1153
1153
|
if (hours !== 0) {
|
|
1154
|
-
rval += hours
|
|
1154
|
+
rval += `${hours}H`;
|
|
1155
1155
|
}
|
|
1156
1156
|
if (minutes !== 0) {
|
|
1157
|
-
rval += minutes
|
|
1157
|
+
rval += `${minutes}M`;
|
|
1158
1158
|
}
|
|
1159
1159
|
if (secs === 0 && this._nanos === 0 && rval.length > 2) {
|
|
1160
1160
|
return rval;
|
|
@@ -1172,9 +1172,9 @@ export class Duration extends TemporalAmount /*implements TemporalAmount, Compar
|
|
|
1172
1172
|
rval += '.';
|
|
1173
1173
|
let nanoString;
|
|
1174
1174
|
if (secs < 0) {
|
|
1175
|
-
nanoString =
|
|
1175
|
+
nanoString = `${2 * LocalTime.NANOS_PER_SECOND - this._nanos}`;
|
|
1176
1176
|
} else {
|
|
1177
|
-
nanoString =
|
|
1177
|
+
nanoString = `${LocalTime.NANOS_PER_SECOND + this._nanos}`;
|
|
1178
1178
|
}
|
|
1179
1179
|
// remove the leading '1'
|
|
1180
1180
|
nanoString = nanoString.slice(1, nanoString.length);
|
package/src/Instant.js
CHANGED
|
@@ -4,22 +4,22 @@
|
|
|
4
4
|
* @license BSD-3-Clause (see LICENSE in the root directory of this source tree)
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import {requireNonNull, requireInstance} from './assert';
|
|
8
|
-
import {DateTimeException, UnsupportedTemporalTypeException} from './errors';
|
|
9
|
-
|
|
10
|
-
import {Clock} from './Clock';
|
|
11
|
-
import {LocalTime} from './LocalTime';
|
|
12
|
-
import {ZonedDateTime} from './ZonedDateTime';
|
|
13
|
-
import {MathUtil} from './MathUtil';
|
|
14
|
-
import {OffsetDateTime} from './OffsetDateTime';
|
|
15
|
-
|
|
16
|
-
import {Temporal} from './temporal/Temporal';
|
|
17
|
-
import {ChronoField} from './temporal/ChronoField';
|
|
18
|
-
import {ChronoUnit} from './temporal/ChronoUnit';
|
|
19
|
-
import {TemporalQueries} from './temporal/TemporalQueries';
|
|
20
|
-
import {TemporalUnit} from './temporal/TemporalUnit';
|
|
21
|
-
import {createTemporalQuery} from './temporal/TemporalQuery';
|
|
22
|
-
import {DateTimeFormatter} from './format/DateTimeFormatter';
|
|
7
|
+
import { requireNonNull, requireInstance } from './assert';
|
|
8
|
+
import { DateTimeException, UnsupportedTemporalTypeException } from './errors';
|
|
9
|
+
|
|
10
|
+
import { Clock } from './Clock';
|
|
11
|
+
import { LocalTime } from './LocalTime';
|
|
12
|
+
import { ZonedDateTime } from './ZonedDateTime';
|
|
13
|
+
import { MathUtil } from './MathUtil';
|
|
14
|
+
import { OffsetDateTime } from './OffsetDateTime';
|
|
15
|
+
|
|
16
|
+
import { Temporal } from './temporal/Temporal';
|
|
17
|
+
import { ChronoField } from './temporal/ChronoField';
|
|
18
|
+
import { ChronoUnit } from './temporal/ChronoUnit';
|
|
19
|
+
import { TemporalQueries } from './temporal/TemporalQueries';
|
|
20
|
+
import { TemporalUnit } from './temporal/TemporalUnit';
|
|
21
|
+
import { createTemporalQuery } from './temporal/TemporalQuery';
|
|
22
|
+
import { DateTimeFormatter } from './format/DateTimeFormatter';
|
|
23
23
|
|
|
24
24
|
const NANOS_PER_MILLI = 1000000;
|
|
25
25
|
|
|
@@ -194,8 +194,8 @@ export class Instant extends Temporal {
|
|
|
194
194
|
const nanoOfSecond = temporal.get(ChronoField.NANO_OF_SECOND);
|
|
195
195
|
return Instant.ofEpochSecond(instantSecs, nanoOfSecond);
|
|
196
196
|
} catch (ex) {
|
|
197
|
-
throw new DateTimeException(
|
|
198
|
-
|
|
197
|
+
throw new DateTimeException(`Unable to obtain Instant from TemporalAccessor: ${
|
|
198
|
+
temporal}, type ${typeof temporal}`, ex);
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
201
|
|
|
@@ -374,7 +374,7 @@ export class Instant extends Temporal {
|
|
|
374
374
|
case ChronoField.MILLI_OF_SECOND: return MathUtil.intDiv(this._nanos, NANOS_PER_MILLI);
|
|
375
375
|
case ChronoField.INSTANT_SECONDS: return this._seconds;
|
|
376
376
|
}
|
|
377
|
-
throw new UnsupportedTemporalTypeException(
|
|
377
|
+
throw new UnsupportedTemporalTypeException(`Unsupported field: ${field}`);
|
|
378
378
|
}
|
|
379
379
|
return field.getFrom(this);
|
|
380
380
|
}
|
|
@@ -405,30 +405,7 @@ export class Instant extends Temporal {
|
|
|
405
405
|
return this._nanos;
|
|
406
406
|
}
|
|
407
407
|
|
|
408
|
-
|
|
409
|
-
/**
|
|
410
|
-
* Returns an adjusted copy of this instant.
|
|
411
|
-
*
|
|
412
|
-
* This returns a new {@link Instant}, based on this one, with the date adjusted.
|
|
413
|
-
* The adjustment takes place using the specified adjuster strategy object.
|
|
414
|
-
* Read the documentation of the adjuster to understand what adjustment will be made.
|
|
415
|
-
*
|
|
416
|
-
* The result of this method is obtained by invoking the
|
|
417
|
-
* {@link TemporalAdjuster#adjustInto} method on the
|
|
418
|
-
* specified adjuster passing `this` as the argument.
|
|
419
|
-
*
|
|
420
|
-
* This instance is immutable and unaffected by this method call.
|
|
421
|
-
*
|
|
422
|
-
* @param {!TemporalAdjuster} adjuster - the adjuster to use, not null
|
|
423
|
-
* @return {Instant} an {@link Instant} based on `this` with the adjustment made, not null
|
|
424
|
-
* @throws DateTimeException if the adjustment cannot be made
|
|
425
|
-
* @throws ArithmeticException if numeric overflow occurs
|
|
426
|
-
*/
|
|
427
|
-
withAdjuster(adjuster) {
|
|
428
|
-
requireNonNull(adjuster, 'adjuster');
|
|
429
|
-
return adjuster.adjustInto(this);
|
|
430
|
-
}
|
|
431
|
-
|
|
408
|
+
//-----------------------------------------------------------------------
|
|
432
409
|
/**
|
|
433
410
|
* Returns a copy of this instant with the specified field set to a new value.
|
|
434
411
|
*
|
|
@@ -472,7 +449,7 @@ export class Instant extends Temporal {
|
|
|
472
449
|
* @throws DateTimeException if the field cannot be set
|
|
473
450
|
* @throws ArithmeticException if numeric overflow occurs
|
|
474
451
|
*/
|
|
475
|
-
|
|
452
|
+
_withField(field, newValue) {
|
|
476
453
|
requireNonNull(field, 'field');
|
|
477
454
|
if (field instanceof ChronoField) {
|
|
478
455
|
field.checkValidValue(newValue);
|
|
@@ -488,7 +465,7 @@ export class Instant extends Temporal {
|
|
|
488
465
|
case ChronoField.NANO_OF_SECOND: return (newValue !== this._nanos? Instant._create(this._seconds, newValue) : this);
|
|
489
466
|
case ChronoField.INSTANT_SECONDS: return (newValue !== this._seconds ? Instant._create(newValue, this._nanos) : this);
|
|
490
467
|
}
|
|
491
|
-
throw new UnsupportedTemporalTypeException(
|
|
468
|
+
throw new UnsupportedTemporalTypeException(`Unsupported field: ${field}`);
|
|
492
469
|
}
|
|
493
470
|
return field.adjustInto(this, newValue);
|
|
494
471
|
}
|
|
@@ -534,18 +511,6 @@ export class Instant extends Temporal {
|
|
|
534
511
|
}
|
|
535
512
|
|
|
536
513
|
//-----------------------------------------------------------------------
|
|
537
|
-
|
|
538
|
-
/**
|
|
539
|
-
* @param {!TemporalAmount} amount
|
|
540
|
-
* @return {Instant}
|
|
541
|
-
* @throws DateTimeException
|
|
542
|
-
* @throws ArithmeticException
|
|
543
|
-
*/
|
|
544
|
-
plusAmount(amount) {
|
|
545
|
-
requireNonNull(amount, 'amount');
|
|
546
|
-
return amount.addTo(this);
|
|
547
|
-
}
|
|
548
|
-
|
|
549
514
|
/**
|
|
550
515
|
* @param {!number} amountToAdd
|
|
551
516
|
* @param {!TemporalUnit} unit
|
|
@@ -553,7 +518,7 @@ export class Instant extends Temporal {
|
|
|
553
518
|
* @throws DateTimeException
|
|
554
519
|
* @throws ArithmeticException
|
|
555
520
|
*/
|
|
556
|
-
|
|
521
|
+
_plusUnit(amountToAdd, unit) {
|
|
557
522
|
requireNonNull(amountToAdd, 'amountToAdd');
|
|
558
523
|
requireNonNull(unit, 'unit');
|
|
559
524
|
requireInstance(unit, TemporalUnit);
|
|
@@ -568,7 +533,7 @@ export class Instant extends Temporal {
|
|
|
568
533
|
case ChronoUnit.HALF_DAYS: return this.plusSeconds(MathUtil.safeMultiply(amountToAdd, LocalTime.SECONDS_PER_DAY / 2));
|
|
569
534
|
case ChronoUnit.DAYS: return this.plusSeconds(MathUtil.safeMultiply(amountToAdd, LocalTime.SECONDS_PER_DAY));
|
|
570
535
|
}
|
|
571
|
-
throw new UnsupportedTemporalTypeException(
|
|
536
|
+
throw new UnsupportedTemporalTypeException(`Unsupported unit: ${unit}`);
|
|
572
537
|
}
|
|
573
538
|
return unit.addTo(this, amountToAdd);
|
|
574
539
|
}
|
|
@@ -635,17 +600,6 @@ export class Instant extends Temporal {
|
|
|
635
600
|
|
|
636
601
|
//-----------------------------------------------------------------------
|
|
637
602
|
|
|
638
|
-
/**
|
|
639
|
-
* @param {!TemporalAmount} amount
|
|
640
|
-
* @return {Instant}
|
|
641
|
-
* @throws DateTimeException
|
|
642
|
-
* @throws ArithmeticException
|
|
643
|
-
*/
|
|
644
|
-
minusAmount(amount) {
|
|
645
|
-
requireNonNull(amount, 'amount');
|
|
646
|
-
return amount.subtractFrom(this);
|
|
647
|
-
}
|
|
648
|
-
|
|
649
603
|
/**
|
|
650
604
|
* @param {!number} amountToSubtract
|
|
651
605
|
* @param {!TemporalUnit} unit
|
|
@@ -653,8 +607,8 @@ export class Instant extends Temporal {
|
|
|
653
607
|
* @throws DateTimeException
|
|
654
608
|
* @throws ArithmeticException
|
|
655
609
|
*/
|
|
656
|
-
|
|
657
|
-
return this.
|
|
610
|
+
_minusUnit(amountToSubtract, unit) {
|
|
611
|
+
return this._plusUnit(-1 * amountToSubtract, unit);
|
|
658
612
|
}
|
|
659
613
|
|
|
660
614
|
/**
|
|
@@ -808,7 +762,7 @@ export class Instant extends Temporal {
|
|
|
808
762
|
if (unit instanceof ChronoUnit) {
|
|
809
763
|
switch (unit) {
|
|
810
764
|
case ChronoUnit.NANOS: return this._nanosUntil(end);
|
|
811
|
-
case ChronoUnit.MICROS: return
|
|
765
|
+
case ChronoUnit.MICROS: return this._microsUntil(end);
|
|
812
766
|
case ChronoUnit.MILLIS: return MathUtil.safeSubtract(end.toEpochMilli(), this.toEpochMilli());
|
|
813
767
|
case ChronoUnit.SECONDS: return this._secondsUntil(end);
|
|
814
768
|
case ChronoUnit.MINUTES: return MathUtil.intDiv(this._secondsUntil(end), LocalTime.SECONDS_PER_MINUTE);
|
|
@@ -816,11 +770,23 @@ export class Instant extends Temporal {
|
|
|
816
770
|
case ChronoUnit.HALF_DAYS: return MathUtil.intDiv(this._secondsUntil(end), (12 * LocalTime.SECONDS_PER_HOUR));
|
|
817
771
|
case ChronoUnit.DAYS: return MathUtil.intDiv(this._secondsUntil(end), LocalTime.SECONDS_PER_DAY);
|
|
818
772
|
}
|
|
819
|
-
throw new UnsupportedTemporalTypeException(
|
|
773
|
+
throw new UnsupportedTemporalTypeException(`Unsupported unit: ${unit}`);
|
|
820
774
|
}
|
|
821
775
|
return unit.between(this, end);
|
|
822
776
|
}
|
|
823
777
|
|
|
778
|
+
/**
|
|
779
|
+
*
|
|
780
|
+
* @param {Temporal} end
|
|
781
|
+
* @returns {number}
|
|
782
|
+
* @private
|
|
783
|
+
*/
|
|
784
|
+
_microsUntil(end) {
|
|
785
|
+
const secsDiff = MathUtil.safeSubtract(end.epochSecond(), this.epochSecond());
|
|
786
|
+
const totalMicros = MathUtil.safeMultiply(secsDiff, 1000000);
|
|
787
|
+
return MathUtil.safeAdd(totalMicros, MathUtil.intDiv(end.nano() - this.nano(), 1000));
|
|
788
|
+
}
|
|
789
|
+
|
|
824
790
|
/**
|
|
825
791
|
*
|
|
826
792
|
* @param {Temporal} end
|