@js-joda/core 1.12.0 → 3.2.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.
@@ -0,0 +1,757 @@
1
+ /**
2
+ * @copyright (c) 2016-present, Philipp Thürwächter & Pattrick Hüper & js-joda contributors
3
+ * @copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
4
+ * @license BSD-3-Clause (see LICENSE in the root directory of this source tree)
5
+ */
6
+
7
+ import {ChronoField} from './temporal/ChronoField';
8
+ import {ChronoUnit} from './temporal/ChronoUnit';
9
+ import {Clock} from './Clock';
10
+ import {DateTimeFormatter} from './format/DateTimeFormatter';
11
+ import {DefaultInterfaceTemporal} from './temporal/DefaultInterfaceTemporal';
12
+ import {Instant} from './Instant';
13
+ import {IsoChronology} from './chrono/IsoChronology';
14
+ import {LocalDateTime} from './LocalDateTime';
15
+ import {LocalDate} from './LocalDate';
16
+ import {LocalTime} from './LocalTime';
17
+ import {MathUtil} from './MathUtil';
18
+ import {OffsetTime} from './OffsetTime';
19
+ import {TemporalQueries} from './temporal/TemporalQueries';
20
+ import {ZonedDateTime} from './ZonedDateTime';
21
+ import {ZoneId} from './ZoneId';
22
+ import {ZoneOffset} from './ZoneOffset';
23
+ import {DateTimeException, IllegalArgumentException} from './errors';
24
+
25
+ import {createTemporalQuery} from './temporal/TemporalQuery';
26
+ import {requireInstance, requireNonNull} from './assert';
27
+
28
+ /**
29
+ * A date-time with an offset from UTC/Greenwich in the ISO-8601 calendar system,
30
+ * such as 2007-12-23T10:15:30+01:00.
31
+ */
32
+ export class OffsetDateTime extends DefaultInterfaceTemporal {
33
+ /**
34
+ * @param {TemporaroAccessor} temporal
35
+ * @return {OffsetDateTime}
36
+ */
37
+ static from(temporal) {
38
+ requireNonNull(temporal, 'temporal');
39
+ if (temporal instanceof OffsetDateTime) {
40
+ return temporal;
41
+ }
42
+ try {
43
+ const offset = ZoneOffset.from(temporal);
44
+ try {
45
+ const ldt = LocalDateTime.from(temporal);
46
+ return OffsetDateTime.of(ldt, offset);
47
+ } catch (_) {
48
+ const instant = Instant.from(temporal);
49
+ return OffsetDateTime.ofInstant(instant, offset);
50
+ }
51
+ } catch (ex) {
52
+ throw new DateTimeException(`Unable to obtain OffsetDateTime TemporalAccessor: ${temporal}, type ${temporal.constructor != null ? temporal.constructor.name : ''}`);
53
+ }
54
+ }
55
+
56
+ /**
57
+ * @param {Clock|ZoneId|null} clockOrZone
58
+ * @return {OffsetDateTime}
59
+ */
60
+ static now(clockOrZone) {
61
+ if (arguments.length === 0) {
62
+ return OffsetDateTime.now(Clock.systemDefaultZone());
63
+ } else {
64
+ requireNonNull(clockOrZone, 'clockOrZone');
65
+ if (clockOrZone instanceof ZoneId) {
66
+ return OffsetDateTime.now(Clock.system(clockOrZone));
67
+ } else if (clockOrZone instanceof Clock) {
68
+ const now = clockOrZone.instant(); // called once
69
+ return OffsetDateTime.ofInstant(now, clockOrZone.zone().rules().offset(now));
70
+ } else {
71
+ throw new IllegalArgumentException('clockOrZone must be an instance of ZoneId or Clock');
72
+ }
73
+ }
74
+ }
75
+
76
+ /**
77
+ * @return {OffsetDateTime}
78
+ */
79
+ static of() {
80
+ if (arguments.length <= 2) {
81
+ return OffsetDateTime.ofDateTime.apply(this, arguments);
82
+ } else if (arguments.length === 3) {
83
+ return OffsetDateTime.ofDateAndTime.apply(this, arguments);
84
+ } else {
85
+ return OffsetDateTime.ofNumbers.apply(this, arguments);
86
+ }
87
+ }
88
+
89
+ static ofDateTime(dateTime, offset) {
90
+ return new OffsetDateTime(dateTime, offset);
91
+ }
92
+
93
+ static ofDateAndTime(date, time, offset) {
94
+ const dt = LocalDateTime.of(date, time);
95
+ return new OffsetDateTime(dt, offset);
96
+ }
97
+
98
+ static ofNumbers(year, month, dayOfMonth, hour=0, minute=0, second=0, nanoOfSecond=0, offset) {
99
+ const dt = LocalDateTime.of(year, month, dayOfMonth, hour, minute, second, nanoOfSecond);
100
+ return new OffsetDateTime(dt, offset);
101
+ }
102
+
103
+ /**
104
+ * @param {Instant} instant
105
+ * @param {ZoneId} zone
106
+ * @return {OffsetDateTime}
107
+ */
108
+ static ofInstant(instant, zone){
109
+ requireNonNull(instant, 'instant');
110
+ requireNonNull(zone, 'zone');
111
+ const rules = zone.rules();
112
+ const offset = rules.offset(instant);
113
+ const ldt = LocalDateTime.ofEpochSecond(instant.epochSecond(), instant.nano(), offset);
114
+ return new OffsetDateTime(ldt, offset);
115
+ }
116
+
117
+ /**
118
+ * @param {string} text
119
+ * @param {DateTimeFormatter|undefined} formatter
120
+ * @return {OffsetTime}
121
+ */
122
+ static parse(text, formatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME){
123
+ requireNonNull(formatter, 'formatter');
124
+ return formatter.parse(text, OffsetDateTime.FROM);
125
+ }
126
+
127
+ // TODO: Need java.util.Comparater interface.
128
+ // static timeLineOrder() {
129
+ //
130
+ // }
131
+
132
+ //-----------------------------------------------------------------------
133
+
134
+
135
+ /**
136
+ * @param {LocalDateTime} dateTime
137
+ * @param {ZoneOffset} offset
138
+ * @private
139
+ */
140
+ constructor(dateTime, offset) {
141
+ super();
142
+ requireNonNull(dateTime, 'dateTime');
143
+ requireInstance(dateTime, LocalDateTime, 'dateTime');
144
+ requireNonNull(offset, 'offset');
145
+ requireInstance(offset, ZoneOffset, 'offset');
146
+ this._dateTime = dateTime;
147
+ this._offset = offset;
148
+ }
149
+
150
+ /**
151
+ *
152
+ * @param {Temporal} temporal
153
+ * @return {Temporal}
154
+ */
155
+ adjustInto(temporal) {
156
+ return temporal
157
+ .with(ChronoField.EPOCH_DAY, this.toLocalDate().toEpochDay())
158
+ .with(ChronoField.NANO_OF_DAY, this.toLocalTime().toNanoOfDay())
159
+ .with(ChronoField.OFFSET_SECONDS, this.offset().totalSeconds());
160
+ }
161
+
162
+ until(endExclusive, unit) {
163
+ let end = OffsetDateTime.from(endExclusive);
164
+ if (unit instanceof ChronoUnit) {
165
+ end = end.withOffsetSameInstant(this._offset);
166
+ return this._dateTime.until(end._dateTime, unit);
167
+ }
168
+ return unit.between(this, end);
169
+ }
170
+
171
+ /**
172
+ * @param {ZoneId}zone
173
+ * @return {ZonedDateTime}
174
+ */
175
+ atZoneSameInstant(zone) {
176
+ return ZonedDateTime.ofInstant(this._dateTime, this._offset, zone);
177
+ }
178
+
179
+ /**
180
+ * @param {ZoneId} zone
181
+ * @return {ZonedDateTime}
182
+ */
183
+ atZoneSimilarLocal(zone) {
184
+ return ZonedDateTime.ofLocal(this._dateTime, zone, this._offset);
185
+ }
186
+
187
+ query(query) {
188
+ requireNonNull(query, 'query');
189
+ if (query === TemporalQueries.chronology()) {
190
+ return IsoChronology.INSTANCE;
191
+ } else if (query === TemporalQueries.precision()) {
192
+ return ChronoUnit.NANOS;
193
+ } else if (query === TemporalQueries.offset() || query === TemporalQueries.zone()) {
194
+ return this.offset();
195
+ } else if (query === TemporalQueries.localDate()) {
196
+ return this.toLocalDate();
197
+ } else if (query === TemporalQueries.localTime()) {
198
+ return this.toLocalTime();
199
+ } else if (query === TemporalQueries.zoneId()) {
200
+ return null;
201
+ }
202
+ return super.query(query);
203
+ }
204
+
205
+ get(field) {
206
+ if (field instanceof ChronoField) {
207
+ switch (field) {
208
+ case ChronoField.INSTANT_SECONDS: throw new DateTimeException('Field too large for an int: ' + field);
209
+ case ChronoField.OFFSET_SECONDS: return this.offset().totalSeconds();
210
+ }
211
+ return this._dateTime.get(field);
212
+ }
213
+ return super.get(field);
214
+ }
215
+
216
+ getLong(field) {
217
+ if (field instanceof ChronoField) {
218
+ switch (field) {
219
+ case ChronoField.INSTANT_SECONDS: return this.toEpochSecond();
220
+ case ChronoField.OFFSET_SECONDS: return this.offset().totalSeconds();
221
+ }
222
+ return this._dateTime.getLong(field);
223
+ }
224
+ return field.getFrom(this);
225
+ }
226
+
227
+ /**
228
+ * @return {ZoneOffset}
229
+ */
230
+ offset() {
231
+ return this._offset;
232
+ }
233
+
234
+ /**
235
+ * @return {number} the year, from MIN_YEAR to MAX_YEAR
236
+ */
237
+ year() {
238
+ return this._dateTime.year();
239
+ }
240
+
241
+ /**
242
+ * @return {number} the month-of-year, from 1 to 12
243
+ * @see #month()
244
+ */
245
+ monthValue() {
246
+ return this._dateTime.monthValue();
247
+ }
248
+
249
+ /**
250
+ * @return {{number} }the month-of-year, not null
251
+ * @see #monthValue()
252
+ */
253
+ month() {
254
+ return this._dateTime.month();
255
+ }
256
+
257
+ /**
258
+ * @return {number} the day-of-month, from 1 to 31
259
+ */
260
+ dayOfMonth() {
261
+ return this._dateTime.dayOfMonth();
262
+ }
263
+
264
+ /**
265
+ * @return {number} the day-of-year, from 1 to 365, or 366 in a leap year
266
+ */
267
+ dayOfYear() {
268
+ return this._dateTime.dayOfYear();
269
+ }
270
+
271
+ /**
272
+ * @return {number} the day-of-week, not null
273
+ */
274
+ dayOfWeek() {
275
+ return this._dateTime.dayOfWeek();
276
+ }
277
+
278
+ /**
279
+ * @return {number} the hour-of-day, from 0 to 23
280
+ */
281
+ hour() {
282
+ return this._dateTime.hour();
283
+ }
284
+
285
+ /**
286
+ * @return {number} the minute-of-hour, from 0 to 59
287
+ */
288
+ minute() {
289
+ return this._dateTime.minute();
290
+ }
291
+
292
+ /**
293
+ * @return {number} the second-of-minute, from 0 to 59
294
+ */
295
+ second() {
296
+ return this._dateTime.second();
297
+ }
298
+
299
+ /**
300
+ * @return {number} the nano-of-second, from 0 to 999,999,999
301
+ */
302
+ nano() {
303
+ return this._dateTime.nano();
304
+ }
305
+
306
+ //-----------------------------------------------------------------------
307
+ /**
308
+ * @return {LocalDateTime}the local date-time part of this date-time, not null
309
+ */
310
+ toLocalDateTime() {
311
+ return this._dateTime;
312
+ }
313
+
314
+ /**
315
+ * @return {LocalDate} the date part of this date-time, not null
316
+ */
317
+ toLocalDate() {
318
+ return this._dateTime.toLocalDate();
319
+ }
320
+
321
+ /**
322
+ * @return {LocalTime} the time part of this date-time, not null
323
+ */
324
+ toLocalTime() {
325
+ return this._dateTime.toLocalTime();
326
+ }
327
+
328
+ /**
329
+ * @return {OffsetTime} an OffsetTime representing the time and offset, not null
330
+ */
331
+ toOffsetTime() {
332
+ return OffsetTime.of(this._dateTime.toLocalTime(), this._offset);
333
+ }
334
+
335
+ /**
336
+ * @return {ZonedDateTime}a zoned date-time representing the same local date-time and offset, not null
337
+ */
338
+ toZonedDateTime() {
339
+ return ZonedDateTime.of(this._dateTime, this._offset);
340
+ }
341
+
342
+ /**
343
+ * @return {Instant} an {@code Instant} representing the same instant, not null
344
+ */
345
+ toInstant() {
346
+ return this._dateTime.toInstant(this._offset);
347
+ }
348
+
349
+ /**
350
+ * @return {number} the number of seconds from the epoch of 1970-01-01T00:00:00Z
351
+ */
352
+ toEpochSecond() {
353
+ return this._dateTime.toEpochSecond(this._offset);
354
+ }
355
+
356
+ isSupported(fieldOrUnit) {
357
+ if (fieldOrUnit instanceof ChronoField) {
358
+ return fieldOrUnit.isDateBased() || fieldOrUnit.isTimeBased();
359
+ }
360
+ if (fieldOrUnit instanceof ChronoUnit) {
361
+ return fieldOrUnit.isDateBased() || fieldOrUnit.isTimeBased();
362
+ }
363
+ return fieldOrUnit != null && fieldOrUnit.isSupportedBy(this);
364
+ }
365
+
366
+ range(field) {
367
+ if (field instanceof ChronoField) {
368
+ if (field === ChronoField.INSTANT_SECONDS || field === ChronoField.OFFSET_SECONDS) {
369
+ return field.range();
370
+ }
371
+ return this._dateTime.range(field);
372
+ }
373
+ return field.rangeRefinedBy(this);
374
+ }
375
+
376
+ withAdjuster(adjuster) {
377
+ requireNonNull(adjuster);
378
+ // optimizations
379
+ if (adjuster instanceof LocalDate || adjuster instanceof LocalTime || adjuster instanceof LocalDateTime) {
380
+ return this._withDateTimeOffset(this._dateTime.with(adjuster), this._offset);
381
+ } else if (adjuster instanceof Instant) {
382
+ return OffsetDateTime.ofInstant(adjuster, this._offset);
383
+ } else if (adjuster instanceof ZoneOffset) {
384
+ return this._withDateTimeOffset(this._dateTime, adjuster);
385
+ } else if (adjuster instanceof OffsetDateTime) {
386
+ return adjuster;
387
+ }
388
+ return adjuster.adjustInto(this);
389
+ }
390
+
391
+ withFieldValue(field, newValue) {
392
+ requireNonNull(field);
393
+ if (field instanceof ChronoField) {
394
+ const f = field;
395
+ switch (f) {
396
+ case ChronoField.INSTANT_SECONDS: return OffsetDateTime.ofInstant(Instant.ofEpochSecond(newValue, this.nano()), this._offset);
397
+ case ChronoField.OFFSET_SECONDS: {
398
+ return this._withDateTimeOffset(this._dateTime, ZoneOffset.ofTotalSeconds(f.checkValidIntValue(newValue)));
399
+ }
400
+ }
401
+ return this._withDateTimeOffset(this._dateTime.with(field, newValue), this._offset);
402
+ }
403
+ return field.adjustInto(this, newValue);
404
+ }
405
+
406
+ _withDateTimeOffset(dateTime, offset) {
407
+ if (this._dateTime === dateTime && this._offset.equals(offset)) {
408
+ return this;
409
+ }
410
+ return new OffsetDateTime(dateTime, offset);
411
+ }
412
+
413
+ /**
414
+ * @param {int} year
415
+ * @return {OffsetDateTime}
416
+ */
417
+ withYear(year) {
418
+ return this._withDateTimeOffset(this._dateTime.withYear(year), this._offset);
419
+ }
420
+
421
+ /**
422
+ * @param {int} month
423
+ * @return {OffsetDateTime}
424
+ */
425
+ withMonth(month) {
426
+ return this._withDateTimeOffset(this._dateTime.withMonth(month), this._offset);
427
+ }
428
+
429
+ /**
430
+ * @param {int} dayOfMonth
431
+ * @return {OffsetDateTime}
432
+ */
433
+ withDayOfMonth(dayOfMonth) {
434
+ return this._withDateTimeOffset(this._dateTime.withDayOfMonth(dayOfMonth), this._offset);
435
+ }
436
+
437
+ /**
438
+ * @param {int} dayOfYear
439
+ * @return {OffsetDateTime}
440
+ */
441
+ withDayOfYear(dayOfYear) {
442
+ return this._withDateTimeOffset(this._dateTime.withDayOfYear(dayOfYear), this._offset);
443
+ }
444
+
445
+ /**
446
+ * @param {int} hour
447
+ * @return {OffsetDateTime}
448
+ */
449
+ withHour(hour) {
450
+ return this._withDateTimeOffset(this._dateTime.withHour(hour), this._offset);
451
+ }
452
+
453
+ /**
454
+ * @param {int} minute
455
+ * @return {OffsetDateTime}
456
+ */
457
+ withMinute(minute) {
458
+ return this._withDateTimeOffset(this._dateTime.withMinute(minute), this._offset);
459
+ }
460
+
461
+ /**
462
+ * @param {int} second
463
+ * @return {OffsetDateTime}
464
+ */
465
+ withSecond(second) {
466
+ return this._withDateTimeOffset(this._dateTime.withSecond(second), this._offset);
467
+ }
468
+
469
+ /**
470
+ * @param {int} nanoOfSecond
471
+ * @return {OffsetDateTime}
472
+ */
473
+ withNano(nanoOfSecond) {
474
+ return this._withDateTimeOffset(this._dateTime.withNano(nanoOfSecond), this._offset);
475
+ }
476
+
477
+ /**
478
+ * @param {ZoneOffset} offset
479
+ * @return {OffsetDateTime}
480
+ */
481
+ withOffsetSameLocal(offset) {
482
+ requireNonNull(offset, 'offset');
483
+ return this._withDateTimeOffset(this._dateTime, offset);
484
+ }
485
+
486
+ /**
487
+ * @param {ZoneOffset} offset
488
+ * @return {OffsetDateTime}
489
+ */
490
+ withOffsetSameInstant(offset) {
491
+ requireNonNull(offset, 'offset');
492
+ if (offset.equals(this._offset)) {
493
+ return this;
494
+ }
495
+ const difference = offset.totalSeconds() - this._offset.totalSeconds();
496
+ const adjusted = this._dateTime.plusSeconds(difference);
497
+ return new OffsetDateTime(adjusted, offset);
498
+ }
499
+
500
+ /**
501
+ * @param {TemporalUnit} unit
502
+ * @return {OffsetDateTime}
503
+ */
504
+ truncatedTo(unit) {
505
+ return this._withDateTimeOffset(this._dateTime.truncatedTo(unit), this._offset);
506
+ }
507
+
508
+ plusAmount(amount) {
509
+ requireNonNull(amount, 'amount');
510
+ return amount.addTo(this);
511
+ }
512
+
513
+ plusAmountUnit(amountToAdd, unit) {
514
+ if (unit instanceof ChronoUnit) {
515
+ return this._withDateTimeOffset(this._dateTime.plus(amountToAdd, unit), this._offset);
516
+ }
517
+ return unit.addTo(this, amountToAdd);
518
+ }
519
+
520
+ /**
521
+ * @param {int} years
522
+ * @return {OffsetTime}
523
+ */
524
+ plusYears(years) {
525
+ return this._withDateTimeOffset(this._dateTime.plusYears(years), this._offset);
526
+ }
527
+
528
+ /**
529
+ * @param {int} months
530
+ * @return {OffsetTime}
531
+ */
532
+ plusMonths(months) {
533
+ return this._withDateTimeOffset(this._dateTime.plusMonths(months), this._offset);
534
+ }
535
+
536
+ /**
537
+ * @param {int} weeks
538
+ * @return {OffsetTime}
539
+ */
540
+ plusWeeks(weeks) {
541
+ return this._withDateTimeOffset(this._dateTime.plusWeeks(weeks), this._offset);
542
+ }
543
+
544
+ /**
545
+ * @param {int} days
546
+ * @return {OffsetTime}
547
+ */
548
+ plusDays(days) {
549
+ return this._withDateTimeOffset(this._dateTime.plusDays(days), this._offset);
550
+ }
551
+
552
+ /**
553
+ * @param {int} hours
554
+ * @return {OffsetTime}
555
+ */
556
+ plusHours(hours) {
557
+ return this._withDateTimeOffset(this._dateTime.plusHours(hours), this._offset);
558
+ }
559
+
560
+ /**
561
+ * @param {int} minutes
562
+ * @return {OffsetTime}
563
+ */
564
+ plusMinutes(minutes) {
565
+ return this._withDateTimeOffset(this._dateTime.plusMinutes(minutes), this._offset);
566
+ }
567
+
568
+ /**
569
+ * @param {int} seconds
570
+ * @return {OffsetTime}
571
+ */
572
+ plusSeconds(seconds) {
573
+ return this._withDateTimeOffset(this._dateTime.plusSeconds(seconds), this._offset);
574
+ }
575
+
576
+ /**
577
+ * @param {int} nanos
578
+ * @return {OffsetTime}
579
+ */
580
+ plusNanos(nanos) {
581
+ return this._withDateTimeOffset(this._dateTime.plusNanos(nanos), this._offset);
582
+ }
583
+
584
+ minusAmount(amount) {
585
+ requireNonNull(amount);
586
+ return amount.subtractFrom(this);
587
+ }
588
+
589
+ minusAmountUnit(amountToSubtract, unit) {
590
+ return this.plus(-1 * amountToSubtract, unit);
591
+ }
592
+
593
+ /**
594
+ * @param {int} years
595
+ * @return {OffsetTime}
596
+ */
597
+ minusYears(years) {
598
+ return this._withDateTimeOffset(this._dateTime.minusYears(years), this._offset);
599
+ }
600
+
601
+ /**
602
+ * @param {int} months
603
+ * @return {OffsetTime}
604
+ */
605
+ minusMonths(months) {
606
+ return this._withDateTimeOffset(this._dateTime.minusMonths(months), this._offset);
607
+ }
608
+
609
+ /**
610
+ * @param {int} weeks
611
+ * @return {OffsetTime}
612
+ */
613
+ minusWeeks(weeks) {
614
+ return this._withDateTimeOffset(this._dateTime.minusWeeks(weeks), this._offset);
615
+ }
616
+
617
+ /**
618
+ * @param {int} days
619
+ * @return {OffsetTime}
620
+ */
621
+ minusDays(days) {
622
+ return this._withDateTimeOffset(this._dateTime.minusDays(days), this._offset);
623
+ }
624
+
625
+ /**
626
+ * @param {int} hours
627
+ * @return {OffsetTime}
628
+ */
629
+ minusHours(hours) {
630
+ return this._withDateTimeOffset(this._dateTime.minusHours(hours), this._offset);
631
+ }
632
+
633
+ /**
634
+ * @param {int} minutes
635
+ * @return {OffsetTime}
636
+ */
637
+ minusMinutes(minutes) {
638
+ return this._withDateTimeOffset(this._dateTime.minusMinutes(minutes), this._offset);
639
+ }
640
+
641
+ /**
642
+ * @param {int} seconds
643
+ * @return {OffsetTime}
644
+ */
645
+ minusSeconds(seconds) {
646
+ return this._withDateTimeOffset(this._dateTime.minusSeconds(seconds), this._offset);
647
+ }
648
+
649
+ /**
650
+ * @param {int} nanos
651
+ * @return {OffsetTime}
652
+ */
653
+ minusNanos(nanos) {
654
+ return this._withDateTimeOffset(this._dateTime.minusNanos(nanos), this._offset);
655
+ }
656
+
657
+ compareTo(other) {
658
+ requireNonNull(other, 'other');
659
+ requireInstance(other, OffsetDateTime, 'other');
660
+ if (this.offset().equals(other.offset())) {
661
+ return this.toLocalDateTime().compareTo(other.toLocalDateTime());
662
+ }
663
+ let cmp = MathUtil.compareNumbers(this.toEpochSecond(), other.toEpochSecond());
664
+ if (cmp === 0) {
665
+ cmp = this.toLocalTime().nano() - other.toLocalTime().nano();
666
+ if (cmp === 0) {
667
+ cmp = this.toLocalDateTime().compareTo(other.toLocalDateTime());
668
+ }
669
+ }
670
+ return cmp;
671
+ }
672
+
673
+ /**
674
+ * @param {OffsetDateTime} other
675
+ * @return {boolean}
676
+ */
677
+ isAfter(other) {
678
+ requireNonNull(other, 'other');
679
+ const thisEpochSec = this.toEpochSecond();
680
+ const otherEpochSec = other.toEpochSecond();
681
+ return thisEpochSec > otherEpochSec || (thisEpochSec === otherEpochSec && this.toLocalTime().nano() > other.toLocalTime().nano());
682
+ }
683
+
684
+ /**
685
+ * @param {OffsetDateTime} other
686
+ * @return {boolean}
687
+ */
688
+ isBefore(other) {
689
+ requireNonNull(other, 'other');
690
+ const thisEpochSec = this.toEpochSecond();
691
+ const otherEpochSec = other.toEpochSecond();
692
+ return thisEpochSec < otherEpochSec || (thisEpochSec === otherEpochSec && this.toLocalTime().nano() < other.toLocalTime().nano());
693
+ }
694
+
695
+ /**
696
+ * @param {OffsetDateTime} other
697
+ * @return {boolean}
698
+ */
699
+ isEqual(other) {
700
+ requireNonNull(other, 'other');
701
+ return this.toEpochSecond() === other.toEpochSecond() && this.toLocalTime().nano() === other.toLocalTime().nano();
702
+ }
703
+
704
+ //-----------------------------------------------------------------------
705
+ /**
706
+ * @param other
707
+ * @return {boolean}
708
+ */
709
+ equals(other) {
710
+ if (this === other) {
711
+ return true;
712
+ }
713
+ if (other instanceof OffsetDateTime) {
714
+ return this._dateTime.equals(other._dateTime) && this._offset.equals(other._offset);
715
+ }
716
+ return false;
717
+ }
718
+
719
+ /**
720
+ * @return {number}
721
+ */
722
+ hashCode() {
723
+ return this._dateTime.hashCode() ^ this._offset.hashCode();
724
+ }
725
+
726
+ toString() {
727
+ return this._dateTime.toString() + this._offset.toString();
728
+ }
729
+
730
+ /**
731
+ *
732
+ * @return {string} same as {@link LocalDateTime.toString}
733
+ */
734
+ toJSON() {
735
+ return this.toString();
736
+ }
737
+
738
+ /**
739
+ * @param {DateTimeFormatter} formatter
740
+ * @return {string}
741
+ */
742
+ format(formatter) {
743
+ requireNonNull(formatter, 'formatter');
744
+ return formatter.format(this);
745
+ }
746
+ }
747
+
748
+
749
+ export function _init() {
750
+ OffsetDateTime.MIN = LocalDateTime.MIN.atOffset(ZoneOffset.MAX);
751
+
752
+ OffsetDateTime.MAX = LocalDateTime.MAX.atOffset(ZoneOffset.MIN);
753
+
754
+ OffsetDateTime.FROM = createTemporalQuery('OffsetDateTime.FROM', (temporal) => {
755
+ return OffsetDateTime.from(temporal);
756
+ });
757
+ }