@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.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)
|
|
@@ -753,9 +753,12 @@
|
|
|
753
753
|
if (this === Duration.ZERO) {
|
|
754
754
|
return 'PT0S';
|
|
755
755
|
}
|
|
756
|
-
var
|
|
757
|
-
var
|
|
758
|
-
var
|
|
756
|
+
var negativeFraction = this._seconds < 0 && this._nanos > 0;
|
|
757
|
+
var wholeSeconds = negativeFraction ? this._seconds + 1 : this._seconds;
|
|
758
|
+
var fractionNanos = negativeFraction ? LocalTime.NANOS_PER_SECOND - this._nanos : this._nanos;
|
|
759
|
+
var hours = MathUtil.intDiv(wholeSeconds, LocalTime.SECONDS_PER_HOUR);
|
|
760
|
+
var minutes = MathUtil.intDiv(MathUtil.intMod(wholeSeconds, LocalTime.SECONDS_PER_HOUR), LocalTime.SECONDS_PER_MINUTE);
|
|
761
|
+
var secs = MathUtil.intMod(wholeSeconds, LocalTime.SECONDS_PER_MINUTE);
|
|
759
762
|
var rval = 'PT';
|
|
760
763
|
if (hours !== 0) {
|
|
761
764
|
rval += hours + "H";
|
|
@@ -763,31 +766,23 @@
|
|
|
763
766
|
if (minutes !== 0) {
|
|
764
767
|
rval += minutes + "M";
|
|
765
768
|
}
|
|
766
|
-
if (secs === 0 &&
|
|
769
|
+
if (secs === 0 && fractionNanos === 0 && rval.length > 2) {
|
|
767
770
|
return rval;
|
|
768
771
|
}
|
|
769
|
-
if (secs
|
|
770
|
-
|
|
771
|
-
rval += '-0';
|
|
772
|
-
} else {
|
|
773
|
-
rval += secs + 1;
|
|
774
|
-
}
|
|
772
|
+
if (secs === 0 && negativeFraction) {
|
|
773
|
+
rval += '-0';
|
|
775
774
|
} else {
|
|
776
|
-
rval += secs;
|
|
775
|
+
rval += "" + secs;
|
|
777
776
|
}
|
|
778
|
-
if (
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
nanoString = "" + (2 * LocalTime.NANOS_PER_SECOND - this._nanos);
|
|
783
|
-
} else {
|
|
784
|
-
nanoString = "" + (LocalTime.NANOS_PER_SECOND + this._nanos);
|
|
777
|
+
if (fractionNanos > 0) {
|
|
778
|
+
var fraction = "" + fractionNanos;
|
|
779
|
+
while (fraction.length < 9) {
|
|
780
|
+
fraction = "0" + fraction;
|
|
785
781
|
}
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
while (rval.charAt(rval.length - 1) === '0') {
|
|
789
|
-
rval = rval.slice(0, rval.length - 1);
|
|
782
|
+
while (fraction.charAt(fraction.length - 1) === '0') {
|
|
783
|
+
fraction = fraction.slice(0, fraction.length - 1);
|
|
790
784
|
}
|
|
785
|
+
rval += "." + fraction;
|
|
791
786
|
}
|
|
792
787
|
rval += 'S';
|
|
793
788
|
return rval;
|
|
@@ -2957,6 +2952,7 @@
|
|
|
2957
2952
|
_this.zone = null;
|
|
2958
2953
|
_this.fieldValues = new EnumMap();
|
|
2959
2954
|
_this.leapSecond = false;
|
|
2955
|
+
_this.excessDays = Period.ZERO;
|
|
2960
2956
|
_this.dateTimeParseContext = dateTimeParseContext;
|
|
2961
2957
|
return _this;
|
|
2962
2958
|
}
|
|
@@ -4462,6 +4458,45 @@
|
|
|
4462
4458
|
if (position === length) {
|
|
4463
4459
|
return ~position;
|
|
4464
4460
|
}
|
|
4461
|
+
var region = this._parseRegion(text, position);
|
|
4462
|
+
var fixedEndPos = this._parseFixedId(context, text, position);
|
|
4463
|
+
var fixedLength = fixedEndPos >= 0 ? fixedEndPos - position : 0;
|
|
4464
|
+
if (region != null && region.parseLength > fixedLength) {
|
|
4465
|
+
context.setParsedZone(ZoneRegion.ofId(region.parsedZoneId));
|
|
4466
|
+
return position + region.parseLength;
|
|
4467
|
+
}
|
|
4468
|
+
return fixedEndPos;
|
|
4469
|
+
};
|
|
4470
|
+
_proto._parseRegion = function _parseRegion(text, position) {
|
|
4471
|
+
var availableZoneIds = ZoneRulesProvider.getAvailableZoneIds();
|
|
4472
|
+
if (availableZoneIds.length === 0) {
|
|
4473
|
+
return null;
|
|
4474
|
+
}
|
|
4475
|
+
if (zoneIdTree.size !== availableZoneIds.length) {
|
|
4476
|
+
zoneIdTree = ZoneIdTree.createTreeMap(availableZoneIds);
|
|
4477
|
+
}
|
|
4478
|
+
var maxParseLength = text.length - position;
|
|
4479
|
+
var treeMap = zoneIdTree.treeMap;
|
|
4480
|
+
var parsedZoneId = null;
|
|
4481
|
+
var parseLength = 0;
|
|
4482
|
+
while (treeMap != null) {
|
|
4483
|
+
var parsedSubZoneId = text.substr(position, Math.min(treeMap.length, maxParseLength));
|
|
4484
|
+
treeMap = treeMap.get(parsedSubZoneId);
|
|
4485
|
+
if (treeMap != null && treeMap.isLeaf) {
|
|
4486
|
+
parsedZoneId = parsedSubZoneId;
|
|
4487
|
+
parseLength = treeMap.length;
|
|
4488
|
+
}
|
|
4489
|
+
}
|
|
4490
|
+
if (parsedZoneId == null) {
|
|
4491
|
+
return null;
|
|
4492
|
+
}
|
|
4493
|
+
return {
|
|
4494
|
+
parsedZoneId: parsedZoneId,
|
|
4495
|
+
parseLength: parseLength
|
|
4496
|
+
};
|
|
4497
|
+
};
|
|
4498
|
+
_proto._parseFixedId = function _parseFixedId(context, text, position) {
|
|
4499
|
+
var length = text.length;
|
|
4465
4500
|
var nextChar = text.charAt(position);
|
|
4466
4501
|
if (nextChar === '+' || nextChar === '-') {
|
|
4467
4502
|
var newContext = context.copy();
|
|
@@ -4470,8 +4505,7 @@
|
|
|
4470
4505
|
return endPos;
|
|
4471
4506
|
}
|
|
4472
4507
|
var offset = newContext.getParsed(ChronoField.OFFSET_SECONDS);
|
|
4473
|
-
|
|
4474
|
-
context.setParsedZone(zone);
|
|
4508
|
+
context.setParsedZone(ZoneOffset.ofTotalSeconds(offset));
|
|
4475
4509
|
return endPos;
|
|
4476
4510
|
} else if (length >= position + 2) {
|
|
4477
4511
|
var nextNextChar = text.charAt(position + 1);
|
|
@@ -4492,26 +4526,6 @@
|
|
|
4492
4526
|
context.setParsedZone(ZoneOffset.UTC);
|
|
4493
4527
|
return position + 1;
|
|
4494
4528
|
}
|
|
4495
|
-
var availableZoneIds = ZoneRulesProvider.getAvailableZoneIds();
|
|
4496
|
-
if (zoneIdTree.size !== availableZoneIds.length) {
|
|
4497
|
-
zoneIdTree = ZoneIdTree.createTreeMap(availableZoneIds);
|
|
4498
|
-
}
|
|
4499
|
-
var maxParseLength = length - position;
|
|
4500
|
-
var treeMap = zoneIdTree.treeMap;
|
|
4501
|
-
var parsedZoneId = null;
|
|
4502
|
-
var parseLength = 0;
|
|
4503
|
-
while (treeMap != null) {
|
|
4504
|
-
var parsedSubZoneId = text.substr(position, Math.min(treeMap.length, maxParseLength));
|
|
4505
|
-
treeMap = treeMap.get(parsedSubZoneId);
|
|
4506
|
-
if (treeMap != null && treeMap.isLeaf) {
|
|
4507
|
-
parsedZoneId = parsedSubZoneId;
|
|
4508
|
-
parseLength = treeMap.length;
|
|
4509
|
-
}
|
|
4510
|
-
}
|
|
4511
|
-
if (parsedZoneId != null) {
|
|
4512
|
-
context.setParsedZone(ZoneRegion.ofId(parsedZoneId));
|
|
4513
|
-
return position + parseLength;
|
|
4514
|
-
}
|
|
4515
4529
|
return ~position;
|
|
4516
4530
|
};
|
|
4517
4531
|
_proto._parsePrefixedOffset = function _parsePrefixedOffset(context, text, prefixPos, position) {
|
|
@@ -5235,7 +5249,7 @@
|
|
|
5235
5249
|
var newContext = context.copy();
|
|
5236
5250
|
var minDigits = this.fractionalDigits < 0 ? 0 : this.fractionalDigits;
|
|
5237
5251
|
var maxDigits = this.fractionalDigits < 0 ? 9 : this.fractionalDigits;
|
|
5238
|
-
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).
|
|
5252
|
+
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);
|
|
5239
5253
|
var pos = parser.parse(newContext, text, position);
|
|
5240
5254
|
if (pos < 0) {
|
|
5241
5255
|
return pos;
|
|
@@ -5247,6 +5261,8 @@
|
|
|
5247
5261
|
var min = newContext.getParsed(ChronoField.MINUTE_OF_HOUR);
|
|
5248
5262
|
var secVal = newContext.getParsed(ChronoField.SECOND_OF_MINUTE);
|
|
5249
5263
|
var nanoVal = newContext.getParsed(ChronoField.NANO_OF_SECOND);
|
|
5264
|
+
var offsetSecs = newContext.getParsed(ChronoField.OFFSET_SECONDS);
|
|
5265
|
+
var offset = offsetSecs != null ? offsetSecs : 0;
|
|
5250
5266
|
var sec = secVal != null ? secVal : 0;
|
|
5251
5267
|
var nano = nanoVal != null ? nanoVal : 0;
|
|
5252
5268
|
var year = MathUtil.intMod(yearParsed, 10000);
|
|
@@ -5261,7 +5277,7 @@
|
|
|
5261
5277
|
var instantSecs;
|
|
5262
5278
|
try {
|
|
5263
5279
|
var ldt = LocalDateTime.of(year, month, day, hour, min, sec, 0).plusDays(days);
|
|
5264
|
-
instantSecs = ldt.toEpochSecond(ZoneOffset.
|
|
5280
|
+
instantSecs = ldt.toEpochSecond(ZoneOffset.ofTotalSeconds(offset));
|
|
5265
5281
|
instantSecs += MathUtil.safeMultiply(MathUtil.intDiv(yearParsed, 10000), SECONDS_PER_10000_YEARS);
|
|
5266
5282
|
} catch (ex) {
|
|
5267
5283
|
return ~position;
|
|
@@ -9683,7 +9699,7 @@
|
|
|
9683
9699
|
throw new DateTimeException('Unit must divide into a standard day without remainder');
|
|
9684
9700
|
}
|
|
9685
9701
|
var nod = MathUtil.intMod(this._seconds, LocalTime.SECONDS_PER_DAY) * LocalTime.NANOS_PER_SECOND + this._nanos;
|
|
9686
|
-
var result = MathUtil.
|
|
9702
|
+
var result = MathUtil.floorDiv(nod, dur) * dur;
|
|
9687
9703
|
return this.plusNanos(result - nod);
|
|
9688
9704
|
};
|
|
9689
9705
|
_proto._plusUnit = function _plusUnit(amountToAdd, unit) {
|