@js-joda/core 5.1.0 → 5.3.1

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": "5.1.0",
3
+ "version": "5.3.1",
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": "dda0bbb3894919782d859060bbabbaa3859775a8"
51
+ "gitHead": "a1ba3e5d59b29185156e61ffc03818c2db11291a"
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._plus(MathUtil.intDiv(amountToAdd, 1000000), MathUtil.intMod(amountToAdd, 1000000) * 1000);
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.
package/src/YearMonth.js CHANGED
@@ -881,6 +881,7 @@ export class YearMonth extends Temporal {
881
881
  * @see #isValidDay(int)
882
882
  */
883
883
  atDay(dayOfMonth) {
884
+ requireNonNull(dayOfMonth, 'dayOfMonth');
884
885
  return LocalDate.of(this._year, this._month, dayOfMonth);
885
886
  }
886
887
 
package/src/ZoneRegion.js CHANGED
@@ -29,7 +29,6 @@ import { ZoneRulesProvider } from './zone/ZoneRulesProvider';
29
29
  */
30
30
  export class ZoneRegion extends ZoneId {
31
31
  /**
32
- * not yet implemented
33
32
  * @param {string} zoneId
34
33
  * @return {ZoneId}
35
34
  */
@@ -1152,6 +1152,7 @@ export class Instant extends Temporal implements TemporalAdjuster {
1152
1152
 
1153
1153
  static from(temporal: TemporalAccessor): Instant;
1154
1154
  static now(clock?: Clock): Instant;
1155
+ static ofEpochMicro(epochMicro: number): Instant;
1155
1156
  static ofEpochMilli(epochMilli: number): Instant;
1156
1157
  static ofEpochSecond(epochSecond: number, nanoAdjustment?: number): Instant;
1157
1158
  static parse(text: string): Instant;
@@ -1171,12 +1172,14 @@ export class Instant extends Temporal implements TemporalAdjuster {
1171
1172
  isSupported(fieldOrUnit: TemporalField | TemporalUnit): boolean;
1172
1173
  minus(amountToSubtract: number, unit: TemporalUnit): Instant;
1173
1174
  minus(amount: TemporalAmount): Instant;
1175
+ minusMicros(microsToSubtract: number): Instant;
1174
1176
  minusMillis(millisToSubtract: number): Instant;
1175
1177
  minusNanos(nanosToSubtract: number): Instant;
1176
1178
  minusSeconds(secondsToSubtract: number): Instant;
1177
1179
  nano(): number;
1178
1180
  plus(amountToAdd: number, unit: TemporalUnit): Instant;
1179
1181
  plus(amount: TemporalAmount): Instant;
1182
+ plusMicros(microsToAdd: number): Instant;
1180
1183
  plusMillis(millisToAdd: number): Instant;
1181
1184
  plusNanos(nanosToAdd: number): Instant;
1182
1185
  plusSeconds(secondsToAdd: number): Instant;
@@ -122,6 +122,7 @@ declare module "js-joda" {
122
122
  MAX_SECONDS: Instant;
123
123
  from(temporal: TemporalAccessor): Instant;
124
124
  now(clock?: Clock): Instant;
125
+ ofEpochMicro(epochMicro: number): Instant;
125
126
  ofEpochMilli(epochMilli: number): Instant;
126
127
  ofEpochSecond(epochSecond: number, nanoAdjustment?: number): Instant;
127
128
  parse(text: string): Instant;
@@ -137,12 +138,14 @@ declare module "js-joda" {
137
138
  isSupported(fieldOrUnit: TemporalField | TemporalUnit): boolean;
138
139
  minus(amount: TemporalAmount): Instant;
139
140
  minus(amountToSubtract: number, unit: TemporalUnit): Instant;
141
+ minusMicros(microsToSubtract: number): Instant;
140
142
  minusMillis(millisToSubtract: number): Instant;
141
143
  minusNanos(nanosToSubtract: number): Instant;
142
144
  minusSeconds(secondsToSubtract: number): Instant;
143
145
  nano(): number;
144
146
  plus(amount: TemporalAmount): Instant;
145
147
  plus(amountToAdd: number, unit: TemporalUnit): Instant;
148
+ plusMicros(microsToAdd: number): Instant;
146
149
  plusMillis(millisToAdd: number): Instant;
147
150
  plusNanos(nanosToAdd: number): Instant;
148
151
  plusSeconds(secondsToAdd: number): Instant;
@@ -1,3 +0,0 @@
1
- //! @copyright (c) 2015-present, Philipp Thürwächter, Pattrick Hüper & js-joda contributors
2
- //! @copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
3
- //! @license BSD-3-Clause (see LICENSE in the root directory of this source tree)