@js-joda/core 4.3.0 → 5.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 +12 -1
- package/dist/js-joda.cjs.js +13561 -0
- package/dist/js-joda.cjs.js.map +1 -0
- package/dist/js-joda.esm.js +10180 -11552
- package/dist/js-joda.esm.js.map +1 -0
- package/dist/js-joda.js +10182 -11555
- package/dist/js-joda.js.map +1 -1
- package/dist/js-joda.min.js +2 -2
- package/package.json +2 -2
- package/src/Instant.js +42 -1
- package/src/format/DateTimeFormatterBuilder.js +2 -2
- package/src/temporal/Temporal.js +16 -0
- package/src/temporal/TemporalAmount.js +16 -0
- package/typings/js-joda.d.ts +0 -1
- package/src/license-preamble.js +0 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@js-joda/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"description": "a date and time library for javascript",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"sourceMap": false,
|
|
49
49
|
"instrument": false
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "d07153c38a3d0b2b29b8185e3daaac69c624d4a9"
|
|
52
52
|
}
|
package/src/Instant.js
CHANGED
|
@@ -172,6 +172,20 @@ export class Instant extends Temporal {
|
|
|
172
172
|
return Instant._create(secs, mos * 1000000);
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
+
/**
|
|
176
|
+
* Obtains an instance of {@link Instant} using microseconds from the
|
|
177
|
+
* epoch of 1970-01-01T00:00:00Z.
|
|
178
|
+
*
|
|
179
|
+
* @param {number} epochMicro - the number of microseconds from 1970-01-01T00:00:00Z
|
|
180
|
+
* @return {Instant} an instant, not null
|
|
181
|
+
* @throws DateTimeException if the instant exceeds the maximum or minimum instant
|
|
182
|
+
*/
|
|
183
|
+
static ofEpochMicro(epochMicro) {
|
|
184
|
+
const secs = MathUtil.floorDiv(epochMicro, 1000000);
|
|
185
|
+
const mos = MathUtil.floorMod(epochMicro, 1000000);
|
|
186
|
+
return Instant._create(secs, mos * 1000);
|
|
187
|
+
}
|
|
188
|
+
|
|
175
189
|
/**
|
|
176
190
|
* Obtains an instance of {@link Instant} from a temporal object.
|
|
177
191
|
*
|
|
@@ -525,7 +539,7 @@ export class Instant extends Temporal {
|
|
|
525
539
|
if (unit instanceof ChronoUnit) {
|
|
526
540
|
switch (unit) {
|
|
527
541
|
case ChronoUnit.NANOS: return this.plusNanos(amountToAdd);
|
|
528
|
-
case ChronoUnit.MICROS: return this.
|
|
542
|
+
case ChronoUnit.MICROS: return this.plusMicros(amountToAdd);
|
|
529
543
|
case ChronoUnit.MILLIS: return this.plusMillis(amountToAdd);
|
|
530
544
|
case ChronoUnit.SECONDS: return this.plusSeconds(amountToAdd);
|
|
531
545
|
case ChronoUnit.MINUTES: return this.plusSeconds(MathUtil.safeMultiply(amountToAdd, LocalTime.SECONDS_PER_MINUTE));
|
|
@@ -578,6 +592,19 @@ export class Instant extends Temporal {
|
|
|
578
592
|
return this._plus(0, nanosToAdd);
|
|
579
593
|
}
|
|
580
594
|
|
|
595
|
+
/**
|
|
596
|
+
* Returns a copy of this instant with the specified duration in microseconds added.
|
|
597
|
+
*
|
|
598
|
+
* This instance is immutable and unaffected by this method call.
|
|
599
|
+
*
|
|
600
|
+
* @param {number} microsToAdd - the microseconds to add, positive or negative
|
|
601
|
+
* @return {Instant} an {@link Instant} based on this instant with the specified microseconds added, not null
|
|
602
|
+
* @throws DateTimeException if the result exceeds the maximum or minimum instant
|
|
603
|
+
*/
|
|
604
|
+
plusMicros(microsToAdd) {
|
|
605
|
+
return this._plus(MathUtil.intDiv(microsToAdd, 1000000), MathUtil.intMod(microsToAdd, 1000000) * 1000);
|
|
606
|
+
}
|
|
607
|
+
|
|
581
608
|
/**
|
|
582
609
|
* Returns a copy of this instant with the specified duration added.
|
|
583
610
|
*
|
|
@@ -652,6 +679,20 @@ export class Instant extends Temporal {
|
|
|
652
679
|
return this.plusNanos(-1 * nanosToSubtract);
|
|
653
680
|
}
|
|
654
681
|
|
|
682
|
+
/**
|
|
683
|
+
* Returns a copy of this instant with the specified duration in microseconds subtracted.
|
|
684
|
+
*
|
|
685
|
+
* This instance is immutable and unaffected by this method call.
|
|
686
|
+
*
|
|
687
|
+
* @param {number} microsToSubtract the microseconds to subtract, positive or negative
|
|
688
|
+
* @return {Instant} an {@link Instant} based on this instant with the specified microseconds subtracted, not null
|
|
689
|
+
* @throws DateTimeException if the result exceeds the maximum or minimum instant
|
|
690
|
+
* @throws ArithmeticException if numeric overflow occurs
|
|
691
|
+
*/
|
|
692
|
+
minusMicros(microsToSubtract) {
|
|
693
|
+
return this.plusMicros(-1 * microsToSubtract);
|
|
694
|
+
}
|
|
695
|
+
|
|
655
696
|
//-------------------------------------------------------------------------
|
|
656
697
|
/**
|
|
657
698
|
* Queries this instant using the specified query.
|
|
@@ -1424,7 +1424,7 @@ class InstantPrinterParser {
|
|
|
1424
1424
|
if (hi > 0) {
|
|
1425
1425
|
buf.append('+').append(hi);
|
|
1426
1426
|
}
|
|
1427
|
-
buf.append(ldt);
|
|
1427
|
+
buf.append(ldt.toString());
|
|
1428
1428
|
if (ldt.second() === 0) {
|
|
1429
1429
|
buf.append(':00');
|
|
1430
1430
|
}
|
|
@@ -1435,7 +1435,7 @@ class InstantPrinterParser {
|
|
|
1435
1435
|
const lo = MathUtil.intMod(zeroSecs, SECONDS_PER_10000_YEARS);
|
|
1436
1436
|
const ldt = LocalDateTime.ofEpochSecond(lo - SECONDS_0000_TO_1970, 0, ZoneOffset.UTC);
|
|
1437
1437
|
const pos = buf.length();
|
|
1438
|
-
buf.append(ldt);
|
|
1438
|
+
buf.append(ldt.toString());
|
|
1439
1439
|
if (ldt.second() === 0) {
|
|
1440
1440
|
buf.append(':00');
|
|
1441
1441
|
}
|
package/src/temporal/Temporal.js
CHANGED
|
@@ -351,3 +351,19 @@ export class Temporal extends TemporalAccessor {
|
|
|
351
351
|
abstractMethodFail('_withField');
|
|
352
352
|
}
|
|
353
353
|
}
|
|
354
|
+
|
|
355
|
+
if (typeof Symbol !== 'undefined' && Symbol.toPrimitive) {
|
|
356
|
+
Temporal.prototype[Symbol.toPrimitive] = function (hint) {
|
|
357
|
+
// hint could be 'number', 'string' or 'default'. Only 'number'
|
|
358
|
+
// should throw and 'default' is treated as 'string'.
|
|
359
|
+
if (hint !== 'number') {
|
|
360
|
+
return this.toString();
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
throw new TypeError(
|
|
364
|
+
'A conversion from Temporal to a number is not allowed. ' +
|
|
365
|
+
'To compare use the methods .equals(), .compareTo(), .isBefore() ' +
|
|
366
|
+
'or one that is more suitable to your use case.'
|
|
367
|
+
);
|
|
368
|
+
};
|
|
369
|
+
}
|
|
@@ -164,3 +164,19 @@ export class TemporalAmount {
|
|
|
164
164
|
}
|
|
165
165
|
|
|
166
166
|
}
|
|
167
|
+
|
|
168
|
+
if (typeof Symbol !== 'undefined' && Symbol.toPrimitive) {
|
|
169
|
+
TemporalAmount.prototype[Symbol.toPrimitive] = function (hint) {
|
|
170
|
+
// hint could be 'number', 'string' or 'default'. Only 'number'
|
|
171
|
+
// should throw and 'default' is treated as 'string'.
|
|
172
|
+
if (hint !== 'number') {
|
|
173
|
+
return this.toString();
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
throw new TypeError(
|
|
177
|
+
'A conversion from TemporalAmount to a number is not allowed. ' +
|
|
178
|
+
'To compare use the methods .equals(), .compareTo(), .isBefore() ' +
|
|
179
|
+
'or one that is more suitable to your use case.'
|
|
180
|
+
);
|
|
181
|
+
};
|
|
182
|
+
}
|
package/typings/js-joda.d.ts
CHANGED
|
@@ -1770,7 +1770,6 @@ export class OffsetTime extends Temporal implements TemporalAdjuster {
|
|
|
1770
1770
|
plusNanos(nanos: number): OffsetTime;
|
|
1771
1771
|
plusSeconds(seconds: number): OffsetTime;
|
|
1772
1772
|
second(): number;
|
|
1773
|
-
toEpochSecond(date: LocalDate): number;
|
|
1774
1773
|
toJSON(): string;
|
|
1775
1774
|
toLocalTime(): LocalTime;
|
|
1776
1775
|
toString(): string;
|
package/src/license-preamble.js
DELETED