@js-joda/core 6.2.0 → 6.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@js-joda/core",
3
- "version": "6.2.0",
3
+ "version": "6.3.0",
4
4
  "description": "a date and time library for javascript",
5
5
  "repository": {
6
6
  "type": "git",
@@ -47,5 +47,5 @@
47
47
  "sourceMap": false,
48
48
  "instrument": false
49
49
  },
50
- "gitHead": "bb36ea96b26ee93408068c8ad8ebe8b094e96a10"
50
+ "gitHead": "8c0a3b1b555bc09fced243dac13fdf5ef9746dc7"
51
51
  }
package/src/Duration.js CHANGED
@@ -1089,6 +1089,21 @@ export class Duration extends TemporalAmount /*implements TemporalAmount, Compar
1089
1089
  }
1090
1090
 
1091
1091
  //-----------------------------------------------------------------------
1092
+ /**
1093
+ * Extracts the number of days in the duration.
1094
+ *
1095
+ * This returns the total number of days in the duration by dividing the
1096
+ * number of seconds by 86400.
1097
+ * This is based on the standard definition of a day as 24 hours.
1098
+ *
1099
+ * This instance is immutable and unaffected by this method call.
1100
+ *
1101
+ * @return {number} the number of days in the duration, may be negative
1102
+ */
1103
+ toDaysPart() {
1104
+ return MathUtil.intDiv(this._seconds, LocalTime.SECONDS_PER_DAY);
1105
+ }
1106
+
1092
1107
  /**
1093
1108
  * Extracts the number of hours part in the duration.
1094
1109
  *
@@ -1151,6 +1166,22 @@ export class Duration extends TemporalAmount /*implements TemporalAmount, Compar
1151
1166
  return MathUtil.intDiv(this._nanos, 1000000);
1152
1167
  }
1153
1168
 
1169
+ /**
1170
+ * Get the nanoseconds part within seconds of the duration.
1171
+ *
1172
+ * The length of the duration is stored using two fields - seconds and nanoseconds.
1173
+ * The nanoseconds part is a value from 0 to 999,999,999 that is an adjustment to
1174
+ * the length in seconds.
1175
+ * The total duration is defined by calling {@link Duration.nano} and {@link Duration.seconds}.
1176
+ *
1177
+ * This instance is immutable and unaffected by this method call.
1178
+ *
1179
+ * @return {number} the nanoseconds within the second part of the length of the duration, from 0 to 999,999,999
1180
+ */
1181
+ toNanosPart() {
1182
+ return this._nanos;
1183
+ }
1184
+
1154
1185
  //-----------------------------------------------------------------------
1155
1186
  /**
1156
1187
  * Compares this duration to the specified {@link Duration}.
package/src/Instant.js CHANGED
@@ -916,6 +916,12 @@ export class Instant extends Temporal {
916
916
  * @throws ArithmeticException if numeric overflow occurs
917
917
  */
918
918
  toEpochMilli() {
919
+ if (this._seconds < 0 && this._nanos > 0) {
920
+ // avoid an overflow of seconds * 1000 for instants close to the minimum epoch milli
921
+ const millis = MathUtil.safeMultiply(this._seconds + 1, 1000);
922
+ const adjustment = MathUtil.intDiv(this._nanos, NANOS_PER_MILLI) - 1000;
923
+ return MathUtil.safeAdd(millis, adjustment);
924
+ }
919
925
  const millis = MathUtil.safeMultiply(this._seconds, 1000);
920
926
  return millis + MathUtil.intDiv(this._nanos, NANOS_PER_MILLI);
921
927
  }
package/src/MonthDay.js CHANGED
@@ -25,7 +25,7 @@ import { ZoneId } from './ZoneId';
25
25
  * A month-day in the ISO-8601 calendar system, such as `--12-03`.
26
26
  *
27
27
  * {@link MonthDay} is an immutable date-time object that represents the combination
28
- * of a year and month. Any field that can be derived from a month and day, such as
28
+ * of a month and day. Any field that can be derived from a month and day, such as
29
29
  * quarter-of-year, can be obtained.
30
30
  *
31
31
  * This class does not store or represent a year, time or time-zone.
@@ -319,7 +319,7 @@ export class ZonedDateTime extends ChronoZonedDateTime {
319
319
  *
320
320
  * Converting an instant to a zoned date-time is simple as there is only one valid
321
321
  * offset for each instant. If the valid offset is different to the offset specified,
322
- * the the date-time and offset of the zoned date-time will differ from those specified.
322
+ * the date-time and offset of the zoned date-time will differ from those specified.
323
323
  *
324
324
  * If the {@link ZoneId} to be used is a {@link ZoneOffset}, this method is equivalent
325
325
  * to {@link of}.
@@ -18,10 +18,12 @@ import { IsoFields } from '../temporal/IsoFields';
18
18
  import { TemporalAccessor } from '../temporal/TemporalAccessor';
19
19
  import { TemporalQueries } from '../temporal/TemporalQueries';
20
20
 
21
+ import { Instant } from '../Instant';
21
22
  import { LocalTime } from '../LocalTime';
22
23
  import { LocalDate } from '../LocalDate';
23
24
  import { Period } from '../Period';
24
25
 
26
+ import { ZonedDateTime } from '../ZonedDateTime';
25
27
  import { ZoneOffset } from '../ZoneOffset';
26
28
 
27
29
  /**
@@ -146,19 +148,17 @@ export class DateTimeBuilder extends TemporalAccessor {
146
148
  this.fieldValues.retainAll(resolverFields);
147
149
  }
148
150
  // handle standard fields
149
- // this._mergeInstantFields();
150
- if (this._resolveFields(resolverStyle)) {
151
- // this._mergeInstantFields();
152
- }
151
+ this._mergeInstantFields();
152
+ this._resolveFields(resolverStyle);
153
153
  this._mergeDate(resolverStyle);
154
154
  this._mergeTime(resolverStyle);
155
155
  this._resolveTimeInferZeroes(resolverStyle);
156
- //this._crossCheck();
156
+ this._crossCheck();
157
157
  if (this.excessDays != null && this.excessDays.isZero() === false && this.date != null && this.time != null) {
158
158
  this.date = this.date.plus(this.excessDays);
159
159
  this.excessDays = Period.ZERO;
160
160
  }
161
- //resolveFractional();
161
+ this._resolveFractional();
162
162
  this._resolveInstant();
163
163
  return this;
164
164
  }
@@ -470,6 +470,122 @@ export class DateTimeBuilder extends TemporalAccessor {
470
470
  }
471
471
  }
472
472
 
473
+ /**
474
+ * Converts a parsed instant-seconds into a date and a second-of-day, using the parsed zone
475
+ * or, if there is none, the parsed offset. Without a zone or offset, the instant-seconds
476
+ * are left unchanged.
477
+ *
478
+ * @private
479
+ */
480
+ _mergeInstantFields() {
481
+ if (this.fieldValues.containsKey(ChronoField.INSTANT_SECONDS)) {
482
+ if (this.zone != null) {
483
+ this._mergeInstantFields0(this.zone);
484
+ } else {
485
+ const offsetSecs = this.fieldValues.get(ChronoField.OFFSET_SECONDS);
486
+ if (offsetSecs != null) {
487
+ this._mergeInstantFields0(ZoneOffset.ofTotalSeconds(offsetSecs));
488
+ }
489
+ }
490
+ }
491
+ }
492
+
493
+ /**
494
+ * @param {ZoneId} selectedZone
495
+ * @private
496
+ */
497
+ _mergeInstantFields0(selectedZone) {
498
+ const instant = Instant.ofEpochSecond(this.fieldValues.remove(ChronoField.INSTANT_SECONDS));
499
+ const zdt = ZonedDateTime.ofInstant(instant, selectedZone);
500
+ if (this.date == null) {
501
+ this._addObject(zdt.toLocalDate());
502
+ } else {
503
+ this._resolveMakeChanges(ChronoField.INSTANT_SECONDS, zdt.toLocalDate());
504
+ }
505
+ this._addFieldValue(ChronoField.SECOND_OF_DAY, zdt.toLocalTime().toSecondOfDay());
506
+ }
507
+
508
+ /**
509
+ * @param {TemporalField} targetField
510
+ * @param {LocalDate} date
511
+ * @private
512
+ */
513
+ _resolveMakeChanges(targetField, date) {
514
+ const epochDay = date.toEpochDay();
515
+ const old = this.fieldValues.get(ChronoField.EPOCH_DAY);
516
+ this.fieldValues.put(ChronoField.EPOCH_DAY, epochDay);
517
+ if (old != null && old !== epochDay) {
518
+ throw new DateTimeException(`Conflict found: ${LocalDate.ofEpochDay(old)} differs from ${LocalDate.ofEpochDay(epochDay)} while resolving ${targetField}`);
519
+ }
520
+ }
521
+
522
+ /**
523
+ * Checks the remaining field values against the resolved date and time, and removes the
524
+ * ones that match.
525
+ *
526
+ * @private
527
+ */
528
+ _crossCheck() {
529
+ if (this.date != null && this.time != null) {
530
+ this._crossCheck0(this.date.atTime(this.time));
531
+ } else if (this.date != null) {
532
+ this._crossCheck0(this.date);
533
+ } else if (this.time != null) {
534
+ this._crossCheck0(this.time);
535
+ }
536
+ }
537
+
538
+ /**
539
+ * @param {TemporalAccessor} temporal
540
+ * @private
541
+ */
542
+ _crossCheck0(temporal) {
543
+ for (const fieldName in this.fieldValues.keySet()) {
544
+ const field = ChronoField.byName(fieldName);
545
+ if (field && this.fieldValues.get(field) !== undefined) { // undefined if "removed" in EnumMap
546
+ if (temporal.isSupported(field)) {
547
+ let temporalValue;
548
+ try {
549
+ temporalValue = temporal.getLong(field);
550
+ } catch (ex) {
551
+ if (ex instanceof DateTimeException) {
552
+ continue;
553
+ }
554
+ throw ex;
555
+ }
556
+ const value = this.fieldValues.get(field);
557
+ if (temporalValue !== value) {
558
+ throw new DateTimeException(`Cross check failed: ${field} ${temporalValue} vs ${field} ${value}`);
559
+ }
560
+ this.fieldValues.remove(field);
561
+ }
562
+ }
563
+ }
564
+ }
565
+
566
+ /**
567
+ * Without a time, adds the fraction-of-second fields to a parsed instant-seconds,
568
+ * second-of-day or second-of-minute, with zero if no nano-of-second was parsed.
569
+ *
570
+ * @private
571
+ */
572
+ _resolveFractional() {
573
+ if (this.time == null &&
574
+ (this.fieldValues.containsKey(ChronoField.INSTANT_SECONDS) ||
575
+ this.fieldValues.containsKey(ChronoField.SECOND_OF_DAY) ||
576
+ this.fieldValues.containsKey(ChronoField.SECOND_OF_MINUTE))) {
577
+ if (this.fieldValues.containsKey(ChronoField.NANO_OF_SECOND)) {
578
+ const nos = this.fieldValues.get(ChronoField.NANO_OF_SECOND);
579
+ this.fieldValues.put(ChronoField.MICRO_OF_SECOND, MathUtil.intDiv(nos, 1000));
580
+ this.fieldValues.put(ChronoField.MILLI_OF_SECOND, MathUtil.intDiv(nos, 1000000));
581
+ } else {
582
+ this.fieldValues.put(ChronoField.NANO_OF_SECOND, 0);
583
+ this.fieldValues.put(ChronoField.MICRO_OF_SECOND, 0);
584
+ this.fieldValues.put(ChronoField.MILLI_OF_SECOND, 0);
585
+ }
586
+ }
587
+ }
588
+
473
589
  _resolveInstant() {
474
590
  if (this.date != null && this.time != null) {
475
591
  const offsetSecs = this.fieldValues.get(ChronoField.OFFSET_SECONDS);
@@ -199,7 +199,7 @@ export class TemporalField {
199
199
  * Checks if this field is supported by the temporal object.
200
200
  *
201
201
  * This determines whether the temporal accessor supports this field.
202
- * If this returns false, the the temporal cannot be queried for this field.
202
+ * If this returns false, the temporal cannot be queried for this field.
203
203
  *
204
204
  * There are two equivalent ways of using this method.
205
205
  * The first is to invoke this method directly.
@@ -17,7 +17,7 @@ import { LocalDateTime } from '../LocalDateTime';
17
17
  * The discontinuity is normally a gap in spring and an overlap in autumn.
18
18
  * {@link ZoneOffsetTransition} models the transition between the two offsets.
19
19
  *
20
- * Gaps occur where there are local date-times that simply do not not exist.
20
+ * Gaps occur where there are local date-times that simply do not exist.
21
21
  * An example would be when the offset changes from `+03:00` to `+04:00`.
22
22
  * This might be described as 'the clocks will move forward one hour tonight at 1am'.
23
23
  *
@@ -178,7 +178,7 @@ export class ZoneOffsetTransition {
178
178
  /**
179
179
  * Does this transition represent a gap in the local time-line.
180
180
  *
181
- * Gaps occur where there are local date-times that simply do not not exist.
181
+ * Gaps occur where there are local date-times that simply do not exist.
182
182
  * An example would be when the offset changes from `+01:00` to `+02:00`.
183
183
  * This might be described as 'the clocks will move forward one hour tonight at 1am'.
184
184
  *
@@ -1110,6 +1110,7 @@ export class Duration extends TemporalAmount {
1110
1110
  minus(amount: number, unit: TemporalUnit): Duration;
1111
1111
  minus(duration: Duration): Duration;
1112
1112
  minusDays(daysToSubtract: number): Duration;
1113
+ minusDuration(duration: Duration): Duration;
1113
1114
  minusHours(hoursToSubtract: number): Duration;
1114
1115
  minusMillis(millisToSubtract: number): Duration;
1115
1116
  minusMinutes(minutesToSubtract: number): Duration;
@@ -1136,10 +1137,12 @@ export class Duration extends TemporalAmount {
1136
1137
  toMillis(): number;
1137
1138
  toMinutes(): number;
1138
1139
  toNanos(): number;
1140
+ toDaysPart(): number;
1139
1141
  toHoursPart(): number;
1140
1142
  toMinutesPart(): number;
1141
1143
  toSecondsPart(): number;
1142
1144
  toMillisPart(): number;
1145
+ toNanosPart(): number;
1143
1146
  toString(): string;
1144
1147
  units(): TemporalUnit[];
1145
1148
  withNanos(nanoOfSecond: number): Duration;
@@ -1534,6 +1537,7 @@ export class Year extends Temporal implements TemporalAdjuster {
1534
1537
  atMonthDay(monthDay: MonthDay): LocalDate;
1535
1538
  compareTo(other: Year): number;
1536
1539
  equals(other: any): boolean;
1540
+ format(formatter: DateTimeFormatter): string;
1537
1541
  getLong(field: TemporalField): number;
1538
1542
  isAfter(other: Year): boolean;
1539
1543
  isBefore(other: Year): boolean;
@@ -1700,6 +1704,7 @@ export class OffsetDateTime extends Temporal implements TemporalAdjuster {
1700
1704
  toLocalTime(): LocalTime;
1701
1705
  toOffsetTime(): OffsetTime;
1702
1706
  toString(): string;
1707
+ toZonedDateTime(): ZonedDateTime;
1703
1708
  truncatedTo(unit: TemporalUnit): OffsetDateTime;
1704
1709
  until(endExclusive: Temporal, unit: TemporalUnit): number;
1705
1710
  with(adjuster: TemporalAdjuster): OffsetDateTime;
@@ -2069,6 +2074,7 @@ export class ZoneOffset extends ZoneId implements TemporalAdjuster {
2069
2074
  getLong(field: TemporalField): number;
2070
2075
  hashCode(): number;
2071
2076
  id(): string;
2077
+ query<R>(query: TemporalQuery<R>): R | null;
2072
2078
  rules(): ZoneRules;
2073
2079
  toString(): string;
2074
2080
  totalSeconds(): number;
@@ -2219,6 +2225,8 @@ export class DateTimeFormatterBuilder {
2219
2225
  }
2220
2226
 
2221
2227
  export class DecimalStyle {
2228
+ static STANDARD: DecimalStyle;
2229
+
2222
2230
  private constructor();
2223
2231
 
2224
2232
  decimalSeparator(): string;
@@ -2227,6 +2235,10 @@ export class DecimalStyle {
2227
2235
  negativeSign(): string;
2228
2236
  positiveSign(): string;
2229
2237
  toString(): string;
2238
+ withDecimalSeparator(decimalSeparator: string): DecimalStyle;
2239
+ withNegativeSign(negativeSign: string): DecimalStyle;
2240
+ withPositiveSign(positiveSign: string): DecimalStyle;
2241
+ withZeroDigit(zeroDigit: string): DecimalStyle;
2230
2242
  zeroDigit(): string;
2231
2243
  }
2232
2244
 
@@ -2456,10 +2468,13 @@ export class ZoneRulesProvider {
2456
2468
  export type Chronology = IsoChronology;
2457
2469
 
2458
2470
  export abstract class IsoChronology {
2471
+ static INSTANCE: IsoChronology;
2472
+
2459
2473
  static isLeapYear(prolepticYear: number): boolean;
2460
2474
 
2461
2475
  private constructor();
2462
2476
 
2477
+ date(temporal: TemporalAccessor): LocalDate;
2463
2478
  equals(other: any): boolean;
2464
2479
  resolveDate(fieldValues: any, resolverStyle: any): any;
2465
2480
  toString(): string;
@@ -108,10 +108,12 @@ declare module "js-joda" {
108
108
  toMillis(): number;
109
109
  toMinutes(): number;
110
110
  toNanos(): number;
111
+ toDaysPart(): number;
111
112
  toHoursPart(): number;
112
113
  toMinutesPart(): number;
113
114
  toSecondsPart(): number;
114
115
  toMillisPart(): number;
116
+ toNanosPart(): number;
115
117
  toString(): string;
116
118
  units(): any;
117
119
  withNanos(nanoOfSecond: number): Duration;
@@ -737,6 +739,7 @@ declare module "js-joda" {
737
739
  now(zoneIdOrClock?: ZoneId | Clock): Year; of(isoYear: number): Year;
738
740
  parse(text: string, formatter?: DateTimeFormatter): Year;
739
741
  atMonth(monthOrNumber: Month | number): Year;
742
+ format(formatter: DateTimeFormatter): string;
740
743
  plus(amountOrNumber: TemporalAmount | number, unit?: TemporalUnit): Year;
741
744
  minus(amountOrNumber: TemporalAmount | number, unit?: TemporalUnit): Year
742
745
  }
@@ -938,7 +941,9 @@ declare module "js-joda" {
938
941
  }
939
942
 
940
943
  declare class IsoChronology {
944
+ INSTANCE: IsoChronology;
941
945
  isLeapYear(prolepticYear: number): boolean;
946
+ date(temporal: TemporalAccessor): LocalDate;
942
947
  resolveDate(fieldValues: any, resolverStyle: any): any;
943
948
  equals(other: any): boolean;
944
949
  toString(): string