@js-joda/core 6.0.1 → 6.1.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/dist/js-joda.cjs.js +64 -48
- package/dist/js-joda.cjs.js.map +1 -1
- package/dist/js-joda.esm.js +64 -48
- package/dist/js-joda.esm.js.map +1 -1
- package/dist/js-joda.js +64 -48
- package/dist/js-joda.js.map +1 -1
- package/dist/js-joda.min.js +2 -2
- package/package.json +2 -2
- package/src/Duration.js +32 -23
- package/src/Instant.js +1 -1
- package/src/format/DateTimeFormatterBuilder.js +6 -2
- package/src/format/DateTimeParseContext.js +2 -0
- package/src/format/parser/ZoneIdPrinterParser.js +62 -28
- package/typings/js-joda.flow.js +1 -1
package/dist/js-joda.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//! @version @js-joda/core - 6.0
|
|
1
|
+
//! @version @js-joda/core - 6.1.0
|
|
2
2
|
//! @copyright (c) 2015-present, Philipp Thürwächter, Pattrick Hüper & js-joda contributors
|
|
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)
|
|
@@ -747,9 +747,12 @@ var Duration = function (_TemporalAmount) {
|
|
|
747
747
|
if (this === Duration.ZERO) {
|
|
748
748
|
return 'PT0S';
|
|
749
749
|
}
|
|
750
|
-
var
|
|
751
|
-
var
|
|
752
|
-
var
|
|
750
|
+
var negativeFraction = this._seconds < 0 && this._nanos > 0;
|
|
751
|
+
var wholeSeconds = negativeFraction ? this._seconds + 1 : this._seconds;
|
|
752
|
+
var fractionNanos = negativeFraction ? LocalTime.NANOS_PER_SECOND - this._nanos : this._nanos;
|
|
753
|
+
var hours = MathUtil.intDiv(wholeSeconds, LocalTime.SECONDS_PER_HOUR);
|
|
754
|
+
var minutes = MathUtil.intDiv(MathUtil.intMod(wholeSeconds, LocalTime.SECONDS_PER_HOUR), LocalTime.SECONDS_PER_MINUTE);
|
|
755
|
+
var secs = MathUtil.intMod(wholeSeconds, LocalTime.SECONDS_PER_MINUTE);
|
|
753
756
|
var rval = 'PT';
|
|
754
757
|
if (hours !== 0) {
|
|
755
758
|
rval += hours + "H";
|
|
@@ -757,31 +760,23 @@ var Duration = function (_TemporalAmount) {
|
|
|
757
760
|
if (minutes !== 0) {
|
|
758
761
|
rval += minutes + "M";
|
|
759
762
|
}
|
|
760
|
-
if (secs === 0 &&
|
|
763
|
+
if (secs === 0 && fractionNanos === 0 && rval.length > 2) {
|
|
761
764
|
return rval;
|
|
762
765
|
}
|
|
763
|
-
if (secs
|
|
764
|
-
|
|
765
|
-
rval += '-0';
|
|
766
|
-
} else {
|
|
767
|
-
rval += secs + 1;
|
|
768
|
-
}
|
|
766
|
+
if (secs === 0 && negativeFraction) {
|
|
767
|
+
rval += '-0';
|
|
769
768
|
} else {
|
|
770
|
-
rval += secs;
|
|
769
|
+
rval += "" + secs;
|
|
771
770
|
}
|
|
772
|
-
if (
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
nanoString = "" + (2 * LocalTime.NANOS_PER_SECOND - this._nanos);
|
|
777
|
-
} else {
|
|
778
|
-
nanoString = "" + (LocalTime.NANOS_PER_SECOND + this._nanos);
|
|
771
|
+
if (fractionNanos > 0) {
|
|
772
|
+
var fraction = "" + fractionNanos;
|
|
773
|
+
while (fraction.length < 9) {
|
|
774
|
+
fraction = "0" + fraction;
|
|
779
775
|
}
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
while (rval.charAt(rval.length - 1) === '0') {
|
|
783
|
-
rval = rval.slice(0, rval.length - 1);
|
|
776
|
+
while (fraction.charAt(fraction.length - 1) === '0') {
|
|
777
|
+
fraction = fraction.slice(0, fraction.length - 1);
|
|
784
778
|
}
|
|
779
|
+
rval += "." + fraction;
|
|
785
780
|
}
|
|
786
781
|
rval += 'S';
|
|
787
782
|
return rval;
|
|
@@ -2951,6 +2946,7 @@ var Parsed = function (_Temporal) {
|
|
|
2951
2946
|
_this.zone = null;
|
|
2952
2947
|
_this.fieldValues = new EnumMap();
|
|
2953
2948
|
_this.leapSecond = false;
|
|
2949
|
+
_this.excessDays = Period.ZERO;
|
|
2954
2950
|
_this.dateTimeParseContext = dateTimeParseContext;
|
|
2955
2951
|
return _this;
|
|
2956
2952
|
}
|
|
@@ -4456,6 +4452,45 @@ var ZoneIdPrinterParser = function () {
|
|
|
4456
4452
|
if (position === length) {
|
|
4457
4453
|
return ~position;
|
|
4458
4454
|
}
|
|
4455
|
+
var region = this._parseRegion(text, position);
|
|
4456
|
+
var fixedEndPos = this._parseFixedId(context, text, position);
|
|
4457
|
+
var fixedLength = fixedEndPos >= 0 ? fixedEndPos - position : 0;
|
|
4458
|
+
if (region != null && region.parseLength > fixedLength) {
|
|
4459
|
+
context.setParsedZone(ZoneRegion.ofId(region.parsedZoneId));
|
|
4460
|
+
return position + region.parseLength;
|
|
4461
|
+
}
|
|
4462
|
+
return fixedEndPos;
|
|
4463
|
+
};
|
|
4464
|
+
_proto._parseRegion = function _parseRegion(text, position) {
|
|
4465
|
+
var availableZoneIds = ZoneRulesProvider.getAvailableZoneIds();
|
|
4466
|
+
if (availableZoneIds.length === 0) {
|
|
4467
|
+
return null;
|
|
4468
|
+
}
|
|
4469
|
+
if (zoneIdTree.size !== availableZoneIds.length) {
|
|
4470
|
+
zoneIdTree = ZoneIdTree.createTreeMap(availableZoneIds);
|
|
4471
|
+
}
|
|
4472
|
+
var maxParseLength = text.length - position;
|
|
4473
|
+
var treeMap = zoneIdTree.treeMap;
|
|
4474
|
+
var parsedZoneId = null;
|
|
4475
|
+
var parseLength = 0;
|
|
4476
|
+
while (treeMap != null) {
|
|
4477
|
+
var parsedSubZoneId = text.substr(position, Math.min(treeMap.length, maxParseLength));
|
|
4478
|
+
treeMap = treeMap.get(parsedSubZoneId);
|
|
4479
|
+
if (treeMap != null && treeMap.isLeaf) {
|
|
4480
|
+
parsedZoneId = parsedSubZoneId;
|
|
4481
|
+
parseLength = treeMap.length;
|
|
4482
|
+
}
|
|
4483
|
+
}
|
|
4484
|
+
if (parsedZoneId == null) {
|
|
4485
|
+
return null;
|
|
4486
|
+
}
|
|
4487
|
+
return {
|
|
4488
|
+
parsedZoneId: parsedZoneId,
|
|
4489
|
+
parseLength: parseLength
|
|
4490
|
+
};
|
|
4491
|
+
};
|
|
4492
|
+
_proto._parseFixedId = function _parseFixedId(context, text, position) {
|
|
4493
|
+
var length = text.length;
|
|
4459
4494
|
var nextChar = text.charAt(position);
|
|
4460
4495
|
if (nextChar === '+' || nextChar === '-') {
|
|
4461
4496
|
var newContext = context.copy();
|
|
@@ -4464,8 +4499,7 @@ var ZoneIdPrinterParser = function () {
|
|
|
4464
4499
|
return endPos;
|
|
4465
4500
|
}
|
|
4466
4501
|
var offset = newContext.getParsed(ChronoField.OFFSET_SECONDS);
|
|
4467
|
-
|
|
4468
|
-
context.setParsedZone(zone);
|
|
4502
|
+
context.setParsedZone(ZoneOffset.ofTotalSeconds(offset));
|
|
4469
4503
|
return endPos;
|
|
4470
4504
|
} else if (length >= position + 2) {
|
|
4471
4505
|
var nextNextChar = text.charAt(position + 1);
|
|
@@ -4486,26 +4520,6 @@ var ZoneIdPrinterParser = function () {
|
|
|
4486
4520
|
context.setParsedZone(ZoneOffset.UTC);
|
|
4487
4521
|
return position + 1;
|
|
4488
4522
|
}
|
|
4489
|
-
var availableZoneIds = ZoneRulesProvider.getAvailableZoneIds();
|
|
4490
|
-
if (zoneIdTree.size !== availableZoneIds.length) {
|
|
4491
|
-
zoneIdTree = ZoneIdTree.createTreeMap(availableZoneIds);
|
|
4492
|
-
}
|
|
4493
|
-
var maxParseLength = length - position;
|
|
4494
|
-
var treeMap = zoneIdTree.treeMap;
|
|
4495
|
-
var parsedZoneId = null;
|
|
4496
|
-
var parseLength = 0;
|
|
4497
|
-
while (treeMap != null) {
|
|
4498
|
-
var parsedSubZoneId = text.substr(position, Math.min(treeMap.length, maxParseLength));
|
|
4499
|
-
treeMap = treeMap.get(parsedSubZoneId);
|
|
4500
|
-
if (treeMap != null && treeMap.isLeaf) {
|
|
4501
|
-
parsedZoneId = parsedSubZoneId;
|
|
4502
|
-
parseLength = treeMap.length;
|
|
4503
|
-
}
|
|
4504
|
-
}
|
|
4505
|
-
if (parsedZoneId != null) {
|
|
4506
|
-
context.setParsedZone(ZoneRegion.ofId(parsedZoneId));
|
|
4507
|
-
return position + parseLength;
|
|
4508
|
-
}
|
|
4509
4523
|
return ~position;
|
|
4510
4524
|
};
|
|
4511
4525
|
_proto._parsePrefixedOffset = function _parsePrefixedOffset(context, text, prefixPos, position) {
|
|
@@ -5229,7 +5243,7 @@ var InstantPrinterParser = function () {
|
|
|
5229
5243
|
var newContext = context.copy();
|
|
5230
5244
|
var minDigits = this.fractionalDigits < 0 ? 0 : this.fractionalDigits;
|
|
5231
5245
|
var maxDigits = this.fractionalDigits < 0 ? 9 : this.fractionalDigits;
|
|
5232
|
-
var parser = new DateTimeFormatterBuilder().append(DateTimeFormatter.ISO_LOCAL_DATE).appendLiteral('T').appendValue(ChronoField.HOUR_OF_DAY, 2).appendLiteral(':').appendValue(ChronoField.MINUTE_OF_HOUR, 2).appendLiteral(':').appendValue(ChronoField.SECOND_OF_MINUTE, 2).appendFraction(ChronoField.NANO_OF_SECOND, minDigits, maxDigits, true).
|
|
5246
|
+
var parser = new DateTimeFormatterBuilder().append(DateTimeFormatter.ISO_LOCAL_DATE).appendLiteral('T').appendValue(ChronoField.HOUR_OF_DAY, 2).appendLiteral(':').appendValue(ChronoField.MINUTE_OF_HOUR, 2).appendLiteral(':').appendValue(ChronoField.SECOND_OF_MINUTE, 2).appendFraction(ChronoField.NANO_OF_SECOND, minDigits, maxDigits, true).appendOffsetId().toFormatter()._toPrinterParser(false);
|
|
5233
5247
|
var pos = parser.parse(newContext, text, position);
|
|
5234
5248
|
if (pos < 0) {
|
|
5235
5249
|
return pos;
|
|
@@ -5241,6 +5255,8 @@ var InstantPrinterParser = function () {
|
|
|
5241
5255
|
var min = newContext.getParsed(ChronoField.MINUTE_OF_HOUR);
|
|
5242
5256
|
var secVal = newContext.getParsed(ChronoField.SECOND_OF_MINUTE);
|
|
5243
5257
|
var nanoVal = newContext.getParsed(ChronoField.NANO_OF_SECOND);
|
|
5258
|
+
var offsetSecs = newContext.getParsed(ChronoField.OFFSET_SECONDS);
|
|
5259
|
+
var offset = offsetSecs != null ? offsetSecs : 0;
|
|
5244
5260
|
var sec = secVal != null ? secVal : 0;
|
|
5245
5261
|
var nano = nanoVal != null ? nanoVal : 0;
|
|
5246
5262
|
var year = MathUtil.intMod(yearParsed, 10000);
|
|
@@ -5255,7 +5271,7 @@ var InstantPrinterParser = function () {
|
|
|
5255
5271
|
var instantSecs;
|
|
5256
5272
|
try {
|
|
5257
5273
|
var ldt = LocalDateTime.of(year, month, day, hour, min, sec, 0).plusDays(days);
|
|
5258
|
-
instantSecs = ldt.toEpochSecond(ZoneOffset.
|
|
5274
|
+
instantSecs = ldt.toEpochSecond(ZoneOffset.ofTotalSeconds(offset));
|
|
5259
5275
|
instantSecs += MathUtil.safeMultiply(MathUtil.intDiv(yearParsed, 10000), SECONDS_PER_10000_YEARS);
|
|
5260
5276
|
} catch (ex) {
|
|
5261
5277
|
return ~position;
|
|
@@ -9677,7 +9693,7 @@ var Instant = function (_Temporal) {
|
|
|
9677
9693
|
throw new DateTimeException('Unit must divide into a standard day without remainder');
|
|
9678
9694
|
}
|
|
9679
9695
|
var nod = MathUtil.intMod(this._seconds, LocalTime.SECONDS_PER_DAY) * LocalTime.NANOS_PER_SECOND + this._nanos;
|
|
9680
|
-
var result = MathUtil.
|
|
9696
|
+
var result = MathUtil.floorDiv(nod, dur) * dur;
|
|
9681
9697
|
return this.plusNanos(result - nod);
|
|
9682
9698
|
};
|
|
9683
9699
|
_proto._plusUnit = function _plusUnit(amountToAdd, unit) {
|