@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.cjs.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)
|
|
@@ -749,9 +749,12 @@ var Duration = function (_TemporalAmount) {
|
|
|
749
749
|
if (this === Duration.ZERO) {
|
|
750
750
|
return 'PT0S';
|
|
751
751
|
}
|
|
752
|
-
var
|
|
753
|
-
var
|
|
754
|
-
var
|
|
752
|
+
var negativeFraction = this._seconds < 0 && this._nanos > 0;
|
|
753
|
+
var wholeSeconds = negativeFraction ? this._seconds + 1 : this._seconds;
|
|
754
|
+
var fractionNanos = negativeFraction ? LocalTime.NANOS_PER_SECOND - this._nanos : this._nanos;
|
|
755
|
+
var hours = MathUtil.intDiv(wholeSeconds, LocalTime.SECONDS_PER_HOUR);
|
|
756
|
+
var minutes = MathUtil.intDiv(MathUtil.intMod(wholeSeconds, LocalTime.SECONDS_PER_HOUR), LocalTime.SECONDS_PER_MINUTE);
|
|
757
|
+
var secs = MathUtil.intMod(wholeSeconds, LocalTime.SECONDS_PER_MINUTE);
|
|
755
758
|
var rval = 'PT';
|
|
756
759
|
if (hours !== 0) {
|
|
757
760
|
rval += hours + "H";
|
|
@@ -759,31 +762,23 @@ var Duration = function (_TemporalAmount) {
|
|
|
759
762
|
if (minutes !== 0) {
|
|
760
763
|
rval += minutes + "M";
|
|
761
764
|
}
|
|
762
|
-
if (secs === 0 &&
|
|
765
|
+
if (secs === 0 && fractionNanos === 0 && rval.length > 2) {
|
|
763
766
|
return rval;
|
|
764
767
|
}
|
|
765
|
-
if (secs
|
|
766
|
-
|
|
767
|
-
rval += '-0';
|
|
768
|
-
} else {
|
|
769
|
-
rval += secs + 1;
|
|
770
|
-
}
|
|
768
|
+
if (secs === 0 && negativeFraction) {
|
|
769
|
+
rval += '-0';
|
|
771
770
|
} else {
|
|
772
|
-
rval += secs;
|
|
771
|
+
rval += "" + secs;
|
|
773
772
|
}
|
|
774
|
-
if (
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
nanoString = "" + (2 * LocalTime.NANOS_PER_SECOND - this._nanos);
|
|
779
|
-
} else {
|
|
780
|
-
nanoString = "" + (LocalTime.NANOS_PER_SECOND + this._nanos);
|
|
773
|
+
if (fractionNanos > 0) {
|
|
774
|
+
var fraction = "" + fractionNanos;
|
|
775
|
+
while (fraction.length < 9) {
|
|
776
|
+
fraction = "0" + fraction;
|
|
781
777
|
}
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
while (rval.charAt(rval.length - 1) === '0') {
|
|
785
|
-
rval = rval.slice(0, rval.length - 1);
|
|
778
|
+
while (fraction.charAt(fraction.length - 1) === '0') {
|
|
779
|
+
fraction = fraction.slice(0, fraction.length - 1);
|
|
786
780
|
}
|
|
781
|
+
rval += "." + fraction;
|
|
787
782
|
}
|
|
788
783
|
rval += 'S';
|
|
789
784
|
return rval;
|
|
@@ -2953,6 +2948,7 @@ var Parsed = function (_Temporal) {
|
|
|
2953
2948
|
_this.zone = null;
|
|
2954
2949
|
_this.fieldValues = new EnumMap();
|
|
2955
2950
|
_this.leapSecond = false;
|
|
2951
|
+
_this.excessDays = Period.ZERO;
|
|
2956
2952
|
_this.dateTimeParseContext = dateTimeParseContext;
|
|
2957
2953
|
return _this;
|
|
2958
2954
|
}
|
|
@@ -4458,6 +4454,45 @@ var ZoneIdPrinterParser = function () {
|
|
|
4458
4454
|
if (position === length) {
|
|
4459
4455
|
return ~position;
|
|
4460
4456
|
}
|
|
4457
|
+
var region = this._parseRegion(text, position);
|
|
4458
|
+
var fixedEndPos = this._parseFixedId(context, text, position);
|
|
4459
|
+
var fixedLength = fixedEndPos >= 0 ? fixedEndPos - position : 0;
|
|
4460
|
+
if (region != null && region.parseLength > fixedLength) {
|
|
4461
|
+
context.setParsedZone(ZoneRegion.ofId(region.parsedZoneId));
|
|
4462
|
+
return position + region.parseLength;
|
|
4463
|
+
}
|
|
4464
|
+
return fixedEndPos;
|
|
4465
|
+
};
|
|
4466
|
+
_proto._parseRegion = function _parseRegion(text, position) {
|
|
4467
|
+
var availableZoneIds = ZoneRulesProvider.getAvailableZoneIds();
|
|
4468
|
+
if (availableZoneIds.length === 0) {
|
|
4469
|
+
return null;
|
|
4470
|
+
}
|
|
4471
|
+
if (zoneIdTree.size !== availableZoneIds.length) {
|
|
4472
|
+
zoneIdTree = ZoneIdTree.createTreeMap(availableZoneIds);
|
|
4473
|
+
}
|
|
4474
|
+
var maxParseLength = text.length - position;
|
|
4475
|
+
var treeMap = zoneIdTree.treeMap;
|
|
4476
|
+
var parsedZoneId = null;
|
|
4477
|
+
var parseLength = 0;
|
|
4478
|
+
while (treeMap != null) {
|
|
4479
|
+
var parsedSubZoneId = text.substr(position, Math.min(treeMap.length, maxParseLength));
|
|
4480
|
+
treeMap = treeMap.get(parsedSubZoneId);
|
|
4481
|
+
if (treeMap != null && treeMap.isLeaf) {
|
|
4482
|
+
parsedZoneId = parsedSubZoneId;
|
|
4483
|
+
parseLength = treeMap.length;
|
|
4484
|
+
}
|
|
4485
|
+
}
|
|
4486
|
+
if (parsedZoneId == null) {
|
|
4487
|
+
return null;
|
|
4488
|
+
}
|
|
4489
|
+
return {
|
|
4490
|
+
parsedZoneId: parsedZoneId,
|
|
4491
|
+
parseLength: parseLength
|
|
4492
|
+
};
|
|
4493
|
+
};
|
|
4494
|
+
_proto._parseFixedId = function _parseFixedId(context, text, position) {
|
|
4495
|
+
var length = text.length;
|
|
4461
4496
|
var nextChar = text.charAt(position);
|
|
4462
4497
|
if (nextChar === '+' || nextChar === '-') {
|
|
4463
4498
|
var newContext = context.copy();
|
|
@@ -4466,8 +4501,7 @@ var ZoneIdPrinterParser = function () {
|
|
|
4466
4501
|
return endPos;
|
|
4467
4502
|
}
|
|
4468
4503
|
var offset = newContext.getParsed(ChronoField.OFFSET_SECONDS);
|
|
4469
|
-
|
|
4470
|
-
context.setParsedZone(zone);
|
|
4504
|
+
context.setParsedZone(ZoneOffset.ofTotalSeconds(offset));
|
|
4471
4505
|
return endPos;
|
|
4472
4506
|
} else if (length >= position + 2) {
|
|
4473
4507
|
var nextNextChar = text.charAt(position + 1);
|
|
@@ -4488,26 +4522,6 @@ var ZoneIdPrinterParser = function () {
|
|
|
4488
4522
|
context.setParsedZone(ZoneOffset.UTC);
|
|
4489
4523
|
return position + 1;
|
|
4490
4524
|
}
|
|
4491
|
-
var availableZoneIds = ZoneRulesProvider.getAvailableZoneIds();
|
|
4492
|
-
if (zoneIdTree.size !== availableZoneIds.length) {
|
|
4493
|
-
zoneIdTree = ZoneIdTree.createTreeMap(availableZoneIds);
|
|
4494
|
-
}
|
|
4495
|
-
var maxParseLength = length - position;
|
|
4496
|
-
var treeMap = zoneIdTree.treeMap;
|
|
4497
|
-
var parsedZoneId = null;
|
|
4498
|
-
var parseLength = 0;
|
|
4499
|
-
while (treeMap != null) {
|
|
4500
|
-
var parsedSubZoneId = text.substr(position, Math.min(treeMap.length, maxParseLength));
|
|
4501
|
-
treeMap = treeMap.get(parsedSubZoneId);
|
|
4502
|
-
if (treeMap != null && treeMap.isLeaf) {
|
|
4503
|
-
parsedZoneId = parsedSubZoneId;
|
|
4504
|
-
parseLength = treeMap.length;
|
|
4505
|
-
}
|
|
4506
|
-
}
|
|
4507
|
-
if (parsedZoneId != null) {
|
|
4508
|
-
context.setParsedZone(ZoneRegion.ofId(parsedZoneId));
|
|
4509
|
-
return position + parseLength;
|
|
4510
|
-
}
|
|
4511
4525
|
return ~position;
|
|
4512
4526
|
};
|
|
4513
4527
|
_proto._parsePrefixedOffset = function _parsePrefixedOffset(context, text, prefixPos, position) {
|
|
@@ -5231,7 +5245,7 @@ var InstantPrinterParser = function () {
|
|
|
5231
5245
|
var newContext = context.copy();
|
|
5232
5246
|
var minDigits = this.fractionalDigits < 0 ? 0 : this.fractionalDigits;
|
|
5233
5247
|
var maxDigits = this.fractionalDigits < 0 ? 9 : this.fractionalDigits;
|
|
5234
|
-
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).
|
|
5248
|
+
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);
|
|
5235
5249
|
var pos = parser.parse(newContext, text, position);
|
|
5236
5250
|
if (pos < 0) {
|
|
5237
5251
|
return pos;
|
|
@@ -5243,6 +5257,8 @@ var InstantPrinterParser = function () {
|
|
|
5243
5257
|
var min = newContext.getParsed(ChronoField.MINUTE_OF_HOUR);
|
|
5244
5258
|
var secVal = newContext.getParsed(ChronoField.SECOND_OF_MINUTE);
|
|
5245
5259
|
var nanoVal = newContext.getParsed(ChronoField.NANO_OF_SECOND);
|
|
5260
|
+
var offsetSecs = newContext.getParsed(ChronoField.OFFSET_SECONDS);
|
|
5261
|
+
var offset = offsetSecs != null ? offsetSecs : 0;
|
|
5246
5262
|
var sec = secVal != null ? secVal : 0;
|
|
5247
5263
|
var nano = nanoVal != null ? nanoVal : 0;
|
|
5248
5264
|
var year = MathUtil.intMod(yearParsed, 10000);
|
|
@@ -5257,7 +5273,7 @@ var InstantPrinterParser = function () {
|
|
|
5257
5273
|
var instantSecs;
|
|
5258
5274
|
try {
|
|
5259
5275
|
var ldt = LocalDateTime.of(year, month, day, hour, min, sec, 0).plusDays(days);
|
|
5260
|
-
instantSecs = ldt.toEpochSecond(ZoneOffset.
|
|
5276
|
+
instantSecs = ldt.toEpochSecond(ZoneOffset.ofTotalSeconds(offset));
|
|
5261
5277
|
instantSecs += MathUtil.safeMultiply(MathUtil.intDiv(yearParsed, 10000), SECONDS_PER_10000_YEARS);
|
|
5262
5278
|
} catch (ex) {
|
|
5263
5279
|
return ~position;
|
|
@@ -9679,7 +9695,7 @@ var Instant = function (_Temporal) {
|
|
|
9679
9695
|
throw new DateTimeException('Unit must divide into a standard day without remainder');
|
|
9680
9696
|
}
|
|
9681
9697
|
var nod = MathUtil.intMod(this._seconds, LocalTime.SECONDS_PER_DAY) * LocalTime.NANOS_PER_SECOND + this._nanos;
|
|
9682
|
-
var result = MathUtil.
|
|
9698
|
+
var result = MathUtil.floorDiv(nod, dur) * dur;
|
|
9683
9699
|
return this.plusNanos(result - nod);
|
|
9684
9700
|
};
|
|
9685
9701
|
_proto._plusUnit = function _plusUnit(amountToAdd, unit) {
|