@js-joda/extra 0.8.1 → 0.9.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.
@@ -1,329 +1,707 @@
1
- //! @version @js-joda/extra - 0.8.1
1
+ //! @version @js-joda/extra - 0.9.1
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)
5
5
 
6
6
  (function (global, factory) {
7
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@js-joda/core')) :
8
- typeof define === 'function' && define.amd ? define(['exports', '@js-joda/core'], factory) :
9
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.JSJodaExtra = {}, global.JSJoda));
7
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@js-joda/core')) :
8
+ typeof define === 'function' && define.amd ? define(['exports', '@js-joda/core'], factory) :
9
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.JSJodaExtra = {}, global.JSJoda));
10
10
  })(this, (function (exports, core) { 'use strict';
11
11
 
12
- /**
13
- * @copyright (c) 2016, Philipp Thürwächter & Pattrick Hüper
14
- * @license BSD-3-Clause (see LICENSE in the root directory of this source tree)
15
- */
16
- function requireNonNull(value, parameterName) {
17
- if (value == null) {
18
- throw new core.NullPointerException(parameterName + " must not be null");
19
- }
12
+ function _inheritsLoose(subClass, superClass) {
13
+ subClass.prototype = Object.create(superClass.prototype);
14
+ subClass.prototype.constructor = subClass;
15
+
16
+ _setPrototypeOf(subClass, superClass);
17
+ }
18
+
19
+ function _setPrototypeOf(o, p) {
20
+ _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
21
+ o.__proto__ = p;
22
+ return o;
23
+ };
24
+
25
+ return _setPrototypeOf(o, p);
26
+ }
27
+
28
+ /**
29
+ * @copyright (c) 2016, Philipp Thürwächter & Pattrick Hüper
30
+ * @license BSD-3-Clause (see LICENSE in the root directory of this source tree)
31
+ */
32
+ function requireNonNull(value, parameterName) {
33
+ if (value == null) {
34
+ throw new core.NullPointerException(parameterName + " must not be null");
35
+ }
20
36
 
21
- return value;
37
+ return value;
38
+ }
39
+ function requireInstance(value, _class, parameterName) {
40
+ if (!(value instanceof _class)) {
41
+ throw new core.IllegalArgumentException(parameterName + " must be an instance of " + (_class.name ? _class.name : _class) + (value && value.constructor && value.constructor.name ? ", but is " + value.constructor.name : ''));
22
42
  }
23
- function requireInstance(value, _class, parameterName) {
24
- if (!(value instanceof _class)) {
25
- throw new core.IllegalArgumentException(parameterName + " must be an instance of " + (_class.name ? _class.name : _class) + (value && value.constructor && value.constructor.name ? ", but is " + value.constructor.name : ''));
43
+
44
+ return value;
45
+ }
46
+
47
+ var MathUtil$1 = core._.MathUtil;
48
+ var DayOfMonth = function (_TemporalAccessor) {
49
+ _inheritsLoose(DayOfMonth, _TemporalAccessor);
50
+
51
+ DayOfMonth.now = function now(zoneIdOrClock) {
52
+ switch (arguments.length) {
53
+ case 0:
54
+ return DayOfMonth.now0();
55
+
56
+ case 1:
57
+ requireNonNull(zoneIdOrClock, 'clockOrZone');
58
+
59
+ if (zoneIdOrClock instanceof core.ZoneId) {
60
+ return DayOfMonth.nowZoneId(zoneIdOrClock);
61
+ }
62
+
63
+ if (zoneIdOrClock instanceof core.Clock) {
64
+ return DayOfMonth.nowClock(zoneIdOrClock);
65
+ }
66
+
67
+ throw new core.IllegalArgumentException("zoneIdOrClock must be an instance of ZoneId or Clock, but is " + zoneIdOrClock.constructor.name);
68
+
69
+ default:
70
+ throw new core.IllegalArgumentException("Invalid number of arguments: " + arguments.length);
26
71
  }
72
+ };
73
+
74
+ DayOfMonth.now0 = function now0() {
75
+ return this.now(core.Clock.systemDefaultZone());
76
+ };
77
+
78
+ DayOfMonth.nowZoneId = function nowZoneId(zone) {
79
+ return this.now(core.Clock.system(zone));
80
+ };
81
+
82
+ DayOfMonth.nowClock = function nowClock(clock) {
83
+ var now = core.LocalDate.now(clock);
84
+ return DayOfMonth.of(now.dayOfMonth());
85
+ };
86
+
87
+ DayOfMonth.of = function of(dayOfMonth) {
88
+ if (1 <= dayOfMonth && dayOfMonth <= 31) {
89
+ return DayOfMonth.VALUES[dayOfMonth - 1];
90
+ } else {
91
+ throw new core.DateTimeException("Invalid value for DayOfMonth: " + dayOfMonth);
92
+ }
93
+ };
94
+
95
+ DayOfMonth.from = function from(temporal) {
96
+ if (temporal instanceof DayOfMonth) {
97
+ return temporal;
98
+ }
99
+
100
+ requireNonNull(temporal, 'temporal');
27
101
 
28
- return value;
102
+ try {
103
+ return DayOfMonth.of(temporal.get(core.ChronoField.DAY_OF_MONTH));
104
+ } catch (ex) {
105
+ throw new core.DateTimeException("Unable to obtain DayOfMonth from TemporalAccessor: " + temporal + " of type " + temporal.constructor.name, ex);
106
+ }
107
+ };
108
+
109
+ function DayOfMonth(dayOfMonth) {
110
+ var _this;
111
+
112
+ _this = _TemporalAccessor.call(this) || this;
113
+ _this._day = MathUtil$1.safeToInt(dayOfMonth);
114
+ return _this;
29
115
  }
30
116
 
31
- /*
32
- * @copyright (c) 2016, Philipp Thürwächter & Pattrick Hüper
33
- * @copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
34
- * @license BSD-3-Clause (see LICENSE in the root directory of this source tree)
35
- */
36
- var Interval = function () {
37
- Interval.of = function of(startInstant, endInstantOrDuration) {
38
- if (endInstantOrDuration instanceof core.Duration) {
39
- return Interval.ofInstantDuration(startInstant, endInstantOrDuration);
40
- } else {
41
- return Interval.ofInstantInstant(startInstant, endInstantOrDuration);
42
- }
43
- };
117
+ var _proto = DayOfMonth.prototype;
44
118
 
45
- Interval.ofInstantInstant = function ofInstantInstant(startInclusive, endExclusive) {
46
- requireNonNull(startInclusive, 'startInclusive');
47
- requireNonNull(endExclusive, 'endExclusive');
48
- requireInstance(startInclusive, core.Instant, 'startInclusive');
49
- requireInstance(endExclusive, core.Instant, 'endExclusive');
119
+ _proto.value = function value() {
120
+ return this._day;
121
+ };
50
122
 
51
- if (endExclusive.isBefore(startInclusive)) {
52
- throw new core.DateTimeException('End instant must on or after start instant');
53
- }
123
+ _proto.isSupported = function isSupported(field) {
124
+ if (field instanceof core.ChronoField) {
125
+ return field === core.ChronoField.DAY_OF_MONTH;
126
+ }
54
127
 
55
- return new Interval(startInclusive, endExclusive);
56
- };
128
+ return field != null && field.isSupportedBy(this);
129
+ };
57
130
 
58
- Interval.ofInstantDuration = function ofInstantDuration(startInclusive, duration) {
59
- requireNonNull(startInclusive, 'startInclusive');
60
- requireNonNull(duration, 'duration');
61
- requireInstance(startInclusive, core.Instant, 'startInclusive');
62
- requireInstance(duration, core.Duration, 'duration');
131
+ _proto.range = function range(field) {
132
+ requireNonNull(field, 'field');
63
133
 
64
- if (duration.isNegative()) {
65
- throw new core.DateTimeException('Duration must not be zero or negative');
66
- }
134
+ if (field === core.ChronoField.DAY_OF_MONTH) {
135
+ return field.range();
136
+ }
67
137
 
68
- return new Interval(startInclusive, startInclusive.plus(duration));
69
- };
138
+ return _TemporalAccessor.prototype.range.call(this, field);
139
+ };
70
140
 
71
- Interval.parse = function parse(text) {
72
- requireNonNull(text, 'text');
141
+ _proto.get = function get(field) {
142
+ return this.range(field).checkValidIntValue(this.getLong(field), field);
143
+ };
73
144
 
74
- if (!(typeof text === 'string')) {
75
- throw new core.IllegalArgumentException("text must be a string, but is " + text.constructor.name);
76
- }
145
+ _proto.getLong = function getLong(field) {
146
+ requireNonNull(field, 'field');
77
147
 
78
- for (var i = 0; i < text.length; i += 1) {
79
- if (text.charAt(i) === '/') {
80
- var firstChar = text.charAt(0);
148
+ if (field === core.ChronoField.DAY_OF_MONTH) {
149
+ return this._day;
150
+ } else if (field instanceof core.ChronoField) {
151
+ throw new core.UnsupportedTemporalTypeException("Unsupported field: " + field);
152
+ }
81
153
 
82
- if (firstChar === 'P' || firstChar === 'p') {
83
- var duration = core.Duration.parse(text.substring(0, i));
84
- var end = core.ZonedDateTime.parse(text.substring(i + 1, text.length)).toInstant();
85
- return Interval.of(end.minus(duration), end);
86
- } else {
87
- var start = core.ZonedDateTime.parse(text.substring(0, i)).toInstant();
154
+ return field.getFrom(this);
155
+ };
88
156
 
89
- if (i + 1 < text.length) {
90
- var c = text.charAt(i + 1);
157
+ _proto.isValidYearMonth = function isValidYearMonth(yearMonth) {
158
+ return yearMonth != null && yearMonth.isValidDay(this._day);
159
+ };
91
160
 
92
- if (c === 'P' || c === 'p') {
93
- var _duration = core.Duration.parse(text.substring(i + 1, text.length));
161
+ _proto.query = function query(_query) {
162
+ requireNonNull(_query, 'query');
163
+ requireInstance(_query, core.TemporalQuery, 'query');
94
164
 
95
- return Interval.of(start, start.plus(_duration));
96
- }
97
- }
165
+ if (_query === core.TemporalQueries.chronology()) {
166
+ return core.IsoChronology.INSTANCE;
167
+ }
98
168
 
99
- var _end = core.ZonedDateTime.parse(text.substring(i + 1, text.length)).toInstant();
169
+ return _TemporalAccessor.prototype.query.call(this, _query);
170
+ };
100
171
 
101
- return Interval.of(start, _end);
102
- }
172
+ _proto.adjustInto = function adjustInto(temporal) {
173
+ requireNonNull(temporal, 'temporal');
174
+ return temporal.with(core.ChronoField.DAY_OF_MONTH, this._day);
175
+ };
176
+
177
+ _proto.atMonth = function atMonth(month) {
178
+ requireNonNull(month, 'month');
179
+
180
+ if (month instanceof core.Month) {
181
+ return core.MonthDay.of(month, Math.min(this._day, month.maxLength()));
182
+ } else {
183
+ return core.MonthDay.of(month, Math.min(this._day, core.Month.of(month).maxLength()));
184
+ }
185
+ };
186
+
187
+ _proto.atYearMonth = function atYearMonth(yearMonth) {
188
+ requireNonNull(yearMonth, 'yearMonth');
189
+ return yearMonth.atDay(Math.min(this._day, yearMonth.lengthOfMonth()));
190
+ };
191
+
192
+ _proto.compareTo = function compareTo(other) {
193
+ requireNonNull(other, 'other');
194
+ requireInstance(other, DayOfMonth, 'other');
195
+ return this._day - other._day;
196
+ };
197
+
198
+ _proto.equals = function equals(obj) {
199
+ if (this === obj) {
200
+ return true;
201
+ }
202
+
203
+ if (obj instanceof DayOfMonth) {
204
+ return this._day === obj._day;
205
+ }
206
+
207
+ return false;
208
+ };
209
+
210
+ _proto.hashCode = function hashCode() {
211
+ return this._day;
212
+ };
213
+
214
+ _proto.toString = function toString() {
215
+ return "DayOfMonth:" + this._day;
216
+ };
217
+
218
+ return DayOfMonth;
219
+ }(core.TemporalAccessor);
220
+ function _init$2() {
221
+ DayOfMonth.VALUES = new Array(31);
222
+
223
+ for (var i = 0; i < 31; i++) {
224
+ DayOfMonth.VALUES[i] = new DayOfMonth(i + 1);
225
+ }
226
+ }
227
+
228
+ var MathUtil = core._.MathUtil;
229
+ var DayOfYear = function (_TemporalAccessor) {
230
+ _inheritsLoose(DayOfYear, _TemporalAccessor);
231
+
232
+ DayOfYear.now = function now(zoneIdOrClock) {
233
+ switch (arguments.length) {
234
+ case 0:
235
+ return DayOfYear.now0();
236
+
237
+ case 1:
238
+ requireNonNull(zoneIdOrClock, 'clockOrZone');
239
+
240
+ if (zoneIdOrClock instanceof core.ZoneId) {
241
+ return DayOfYear.nowZoneId(zoneIdOrClock);
103
242
  }
104
- }
105
243
 
106
- throw new core.DateTimeParseException('Interval cannot be parsed, no forward slash found', text, 0);
107
- };
244
+ if (zoneIdOrClock instanceof core.Clock) {
245
+ return DayOfYear.nowClock(zoneIdOrClock);
246
+ }
247
+
248
+ throw new core.IllegalArgumentException("zoneIdOrClock must be an instance of ZoneId or Clock, but is " + zoneIdOrClock.constructor.name);
108
249
 
109
- function Interval(startInclusive, endExclusive) {
110
- this._start = startInclusive;
111
- this._end = endExclusive;
250
+ default:
251
+ throw new core.IllegalArgumentException("Invalid number of arguments: " + arguments.length);
112
252
  }
253
+ };
254
+
255
+ DayOfYear.now0 = function now0() {
256
+ return DayOfYear.now(core.Clock.systemDefaultZone());
257
+ };
258
+
259
+ DayOfYear.nowZoneId = function nowZoneId(zone) {
260
+ return DayOfYear.now(core.Clock.system(zone));
261
+ };
262
+
263
+ DayOfYear.nowClock = function nowClock(clock) {
264
+ var now = core.LocalDate.now(clock);
265
+ return DayOfYear.of(now.dayOfYear());
266
+ };
267
+
268
+ DayOfYear.of = function of(dayOfYear) {
269
+ if (1 <= dayOfYear && dayOfYear <= 366) {
270
+ return DayOfYear.VALUES[dayOfYear - 1];
271
+ } else {
272
+ throw new core.DateTimeException("Invalid value for DayOfYear: " + dayOfYear);
273
+ }
274
+ };
113
275
 
114
- var _proto = Interval.prototype;
276
+ DayOfYear.from = function from(temporal) {
277
+ requireNonNull(temporal, 'temporal');
278
+ requireInstance(temporal, core.TemporalAccessor, 'temporal');
115
279
 
116
- _proto.start = function start() {
117
- return this._start;
118
- };
280
+ if (temporal instanceof DayOfYear) {
281
+ return temporal;
282
+ }
119
283
 
120
- _proto.end = function end() {
121
- return this._end;
122
- };
284
+ try {
285
+ return DayOfYear.of(temporal.get(core.ChronoField.DAY_OF_YEAR));
286
+ } catch (ex) {
287
+ throw new core.DateTimeException("Unable to obtain DayOfYear from TemporalAccessor: " + temporal + " of type " + temporal.constructor.name, ex);
288
+ }
289
+ };
123
290
 
124
- _proto.isEmpty = function isEmpty() {
125
- return this._start.equals(this._end);
126
- };
291
+ function DayOfYear(dayOfYear) {
292
+ var _this;
127
293
 
128
- _proto.isUnboundedStart = function isUnboundedStart() {
129
- return this._start.equals(core.Instant.MIN);
130
- };
294
+ _this = _TemporalAccessor.call(this) || this;
295
+ _this._day = MathUtil.safeToInt(dayOfYear);
296
+ return _this;
297
+ }
131
298
 
132
- _proto.isUnboundedEnd = function isUnboundedEnd() {
133
- return this._end.equals(core.Instant.MAX);
134
- };
299
+ var _proto = DayOfYear.prototype;
135
300
 
136
- _proto.withStart = function withStart(start) {
137
- return Interval.of(start, this._end);
138
- };
301
+ _proto.value = function value() {
302
+ return this._day;
303
+ };
139
304
 
140
- _proto.withEnd = function withEnd(end) {
141
- return Interval.of(this._start, end);
142
- };
305
+ _proto.isSupported = function isSupported(field) {
306
+ if (field instanceof core.ChronoField) {
307
+ return field === core.ChronoField.DAY_OF_YEAR;
308
+ }
143
309
 
144
- _proto.contains = function contains(instant) {
145
- requireNonNull(instant, 'instant');
146
- requireInstance(instant, core.Instant, 'instant');
147
- return this._start.compareTo(instant) <= 0 && (instant.compareTo(this._end) < 0 || this.isUnboundedEnd());
148
- };
310
+ return field != null && field.isSupportedBy(this);
311
+ };
149
312
 
150
- _proto.encloses = function encloses(other) {
151
- requireNonNull(other, 'other');
152
- requireInstance(other, Interval, 'other');
153
- return this._start.compareTo(other.start()) <= 0 && other.end().compareTo(this._end) <= 0;
154
- };
313
+ _proto.range = function range(field) {
314
+ requireNonNull(field, 'field');
155
315
 
156
- _proto.abuts = function abuts(other) {
157
- requireNonNull(other, 'other');
158
- requireInstance(other, Interval, 'other');
159
- return !this._end.equals(other.start()) !== !this._start.equals(other.end());
160
- };
316
+ if (field === core.ChronoField.DAY_OF_YEAR) {
317
+ return field.range();
318
+ }
161
319
 
162
- _proto.isConnected = function isConnected(other) {
163
- requireNonNull(other, 'other');
164
- requireInstance(other, Interval, 'other');
165
- return this.equals(other) || this._start.compareTo(other.end()) <= 0 && other.start().compareTo(this._end) <= 0;
166
- };
320
+ return _TemporalAccessor.prototype.range.call(this, field);
321
+ };
167
322
 
168
- _proto.overlaps = function overlaps(other) {
169
- requireNonNull(other, 'other');
170
- requireInstance(other, Interval, 'other');
171
- return other.equals(this) || this._start.compareTo(other.end()) < 0 && other.start().compareTo(this._end) < 0;
172
- };
323
+ _proto.get = function get(field) {
324
+ return this.range(field).checkValidIntValue(this.getLong(field), field);
325
+ };
173
326
 
174
- _proto.intersection = function intersection(other) {
175
- requireNonNull(other, 'other');
176
- requireInstance(other, Interval, 'other');
327
+ _proto.getLong = function getLong(field) {
328
+ requireNonNull(field, 'field');
177
329
 
178
- if (this.isConnected(other) === false) {
179
- throw new core.DateTimeException("Intervals do not connect: " + this + " and " + other);
180
- }
330
+ if (field === core.ChronoField.DAY_OF_YEAR) {
331
+ return this._day;
332
+ } else if (field instanceof core.ChronoField) {
333
+ throw new core.UnsupportedTemporalTypeException("Unsupported field: " + field);
334
+ }
181
335
 
182
- var cmpStart = this._start.compareTo(other.start());
336
+ return field.getFrom(this);
337
+ };
183
338
 
184
- var cmpEnd = this._end.compareTo(other.end());
339
+ _proto.isValidYear = function isValidYear(year) {
340
+ return this._day < 366 || core.Year.isLeap(year);
341
+ };
185
342
 
186
- if (cmpStart >= 0 && cmpEnd <= 0) {
187
- return this;
188
- } else if (cmpStart <= 0 && cmpEnd >= 0) {
189
- return other;
190
- } else {
191
- var newStart = cmpStart >= 0 ? this._start : other.start();
192
- var newEnd = cmpEnd <= 0 ? this._end : other.end();
193
- return Interval.of(newStart, newEnd);
194
- }
195
- };
343
+ _proto.query = function query(_query) {
344
+ requireNonNull(_query, 'query');
345
+ requireInstance(_query, core.TemporalQuery, 'query');
196
346
 
197
- _proto.union = function union(other) {
198
- requireNonNull(other, 'other');
199
- requireInstance(other, Interval, 'other');
347
+ if (_query === core.TemporalQueries.chronology()) {
348
+ return core.IsoChronology.INSTANCE;
349
+ }
200
350
 
201
- if (this.isConnected(other) === false) {
202
- throw new core.DateTimeException("Intervals do not connect: " + this + " and " + other);
203
- }
351
+ return _TemporalAccessor.prototype.query.call(this, _query);
352
+ };
353
+
354
+ _proto.adjustInto = function adjustInto(temporal) {
355
+ requireNonNull(temporal, 'temporal');
356
+ return temporal.with(core.ChronoField.DAY_OF_YEAR, this._day);
357
+ };
204
358
 
205
- var cmpStart = this._start.compareTo(other.start());
359
+ _proto.atYear = function atYear(year) {
360
+ requireNonNull(year, 'year');
206
361
 
207
- var cmpEnd = this._end.compareTo(other.end());
362
+ if (year instanceof core.Year) {
363
+ return year.atDay(this._day);
364
+ } else {
365
+ return core.LocalDate.ofYearDay(year, this._day);
366
+ }
367
+ };
208
368
 
209
- if (cmpStart >= 0 && cmpEnd <= 0) {
210
- return other;
211
- } else if (cmpStart <= 0 && cmpEnd >= 0) {
212
- return this;
213
- } else {
214
- var newStart = cmpStart >= 0 ? other.start() : this._start;
215
- var newEnd = cmpEnd <= 0 ? other.end() : this._end;
216
- return Interval.of(newStart, newEnd);
369
+ _proto.compareTo = function compareTo(other) {
370
+ requireNonNull(other, 'other');
371
+ requireInstance(other, DayOfYear, 'other');
372
+ return this._day - other._day;
373
+ };
374
+
375
+ _proto.equals = function equals(obj) {
376
+ if (this === obj) {
377
+ return true;
378
+ }
379
+
380
+ if (obj instanceof DayOfYear) {
381
+ return this._day === obj._day;
382
+ }
383
+
384
+ return false;
385
+ };
386
+
387
+ _proto.hashCode = function hashCode() {
388
+ return this._day;
389
+ };
390
+
391
+ _proto.toString = function toString() {
392
+ return "DayOfYear:" + this._day;
393
+ };
394
+
395
+ return DayOfYear;
396
+ }(core.TemporalAccessor);
397
+ function _init$1() {
398
+ DayOfYear.VALUES = new Array(366);
399
+
400
+ for (var i = 0; i < 366; i++) {
401
+ DayOfYear.VALUES[i] = new DayOfYear(i + 1);
402
+ }
403
+ }
404
+
405
+ /*
406
+ * @copyright (c) 2016, Philipp Thürwächter & Pattrick Hüper
407
+ * @copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
408
+ * @license BSD-3-Clause (see LICENSE in the root directory of this source tree)
409
+ */
410
+ var Interval = function () {
411
+ Interval.of = function of(startInstant, endInstantOrDuration) {
412
+ if (endInstantOrDuration instanceof core.Duration) {
413
+ return Interval.ofInstantDuration(startInstant, endInstantOrDuration);
414
+ } else {
415
+ return Interval.ofInstantInstant(startInstant, endInstantOrDuration);
416
+ }
417
+ };
418
+
419
+ Interval.ofInstantInstant = function ofInstantInstant(startInclusive, endExclusive) {
420
+ requireNonNull(startInclusive, 'startInclusive');
421
+ requireNonNull(endExclusive, 'endExclusive');
422
+ requireInstance(startInclusive, core.Instant, 'startInclusive');
423
+ requireInstance(endExclusive, core.Instant, 'endExclusive');
424
+
425
+ if (endExclusive.isBefore(startInclusive)) {
426
+ throw new core.DateTimeException('End instant must on or after start instant');
427
+ }
428
+
429
+ return new Interval(startInclusive, endExclusive);
430
+ };
431
+
432
+ Interval.ofInstantDuration = function ofInstantDuration(startInclusive, duration) {
433
+ requireNonNull(startInclusive, 'startInclusive');
434
+ requireNonNull(duration, 'duration');
435
+ requireInstance(startInclusive, core.Instant, 'startInclusive');
436
+ requireInstance(duration, core.Duration, 'duration');
437
+
438
+ if (duration.isNegative()) {
439
+ throw new core.DateTimeException('Duration must not be zero or negative');
440
+ }
441
+
442
+ return new Interval(startInclusive, startInclusive.plus(duration));
443
+ };
444
+
445
+ Interval.parse = function parse(text) {
446
+ requireNonNull(text, 'text');
447
+
448
+ if (!(typeof text === 'string')) {
449
+ throw new core.IllegalArgumentException("text must be a string, but is " + text.constructor.name);
450
+ }
451
+
452
+ for (var i = 0; i < text.length; i += 1) {
453
+ if (text.charAt(i) === '/') {
454
+ var firstChar = text.charAt(0);
455
+
456
+ if (firstChar === 'P' || firstChar === 'p') {
457
+ var duration = core.Duration.parse(text.substring(0, i));
458
+ var end = core.ZonedDateTime.parse(text.substring(i + 1, text.length)).toInstant();
459
+ return Interval.of(end.minus(duration), end);
460
+ } else {
461
+ var start = core.ZonedDateTime.parse(text.substring(0, i)).toInstant();
462
+
463
+ if (i + 1 < text.length) {
464
+ var c = text.charAt(i + 1);
465
+
466
+ if (c === 'P' || c === 'p') {
467
+ var _duration = core.Duration.parse(text.substring(i + 1, text.length));
468
+
469
+ return Interval.of(start, start.plus(_duration));
470
+ }
471
+ }
472
+
473
+ var _end = core.ZonedDateTime.parse(text.substring(i + 1, text.length)).toInstant();
474
+
475
+ return Interval.of(start, _end);
476
+ }
217
477
  }
218
- };
478
+ }
479
+
480
+ throw new core.DateTimeParseException('Interval cannot be parsed, no forward slash found', text, 0);
481
+ };
482
+
483
+ function Interval(startInclusive, endExclusive) {
484
+ this._start = startInclusive;
485
+ this._end = endExclusive;
486
+ }
487
+
488
+ var _proto = Interval.prototype;
489
+
490
+ _proto.start = function start() {
491
+ return this._start;
492
+ };
493
+
494
+ _proto.end = function end() {
495
+ return this._end;
496
+ };
497
+
498
+ _proto.isEmpty = function isEmpty() {
499
+ return this._start.equals(this._end);
500
+ };
501
+
502
+ _proto.isUnboundedStart = function isUnboundedStart() {
503
+ return this._start.equals(core.Instant.MIN);
504
+ };
505
+
506
+ _proto.isUnboundedEnd = function isUnboundedEnd() {
507
+ return this._end.equals(core.Instant.MAX);
508
+ };
509
+
510
+ _proto.withStart = function withStart(start) {
511
+ return Interval.of(start, this._end);
512
+ };
513
+
514
+ _proto.withEnd = function withEnd(end) {
515
+ return Interval.of(this._start, end);
516
+ };
517
+
518
+ _proto.contains = function contains(instant) {
519
+ requireNonNull(instant, 'instant');
520
+ requireInstance(instant, core.Instant, 'instant');
521
+ return this._start.compareTo(instant) <= 0 && (instant.compareTo(this._end) < 0 || this.isUnboundedEnd());
522
+ };
523
+
524
+ _proto.encloses = function encloses(other) {
525
+ requireNonNull(other, 'other');
526
+ requireInstance(other, Interval, 'other');
527
+ return this._start.compareTo(other.start()) <= 0 && other.end().compareTo(this._end) <= 0;
528
+ };
529
+
530
+ _proto.abuts = function abuts(other) {
531
+ requireNonNull(other, 'other');
532
+ requireInstance(other, Interval, 'other');
533
+ return !this._end.equals(other.start()) !== !this._start.equals(other.end());
534
+ };
535
+
536
+ _proto.isConnected = function isConnected(other) {
537
+ requireNonNull(other, 'other');
538
+ requireInstance(other, Interval, 'other');
539
+ return this.equals(other) || this._start.compareTo(other.end()) <= 0 && other.start().compareTo(this._end) <= 0;
540
+ };
541
+
542
+ _proto.overlaps = function overlaps(other) {
543
+ requireNonNull(other, 'other');
544
+ requireInstance(other, Interval, 'other');
545
+ return other.equals(this) || this._start.compareTo(other.end()) < 0 && other.start().compareTo(this._end) < 0;
546
+ };
547
+
548
+ _proto.intersection = function intersection(other) {
549
+ requireNonNull(other, 'other');
550
+ requireInstance(other, Interval, 'other');
551
+
552
+ if (this.isConnected(other) === false) {
553
+ throw new core.DateTimeException("Intervals do not connect: " + this + " and " + other);
554
+ }
219
555
 
220
- _proto.span = function span(other) {
221
- requireNonNull(other, 'other');
222
- requireInstance(other, Interval, 'other');
556
+ var cmpStart = this._start.compareTo(other.start());
557
+
558
+ var cmpEnd = this._end.compareTo(other.end());
559
+
560
+ if (cmpStart >= 0 && cmpEnd <= 0) {
561
+ return this;
562
+ } else if (cmpStart <= 0 && cmpEnd >= 0) {
563
+ return other;
564
+ } else {
565
+ var newStart = cmpStart >= 0 ? this._start : other.start();
566
+ var newEnd = cmpEnd <= 0 ? this._end : other.end();
567
+ return Interval.of(newStart, newEnd);
568
+ }
569
+ };
570
+
571
+ _proto.union = function union(other) {
572
+ requireNonNull(other, 'other');
573
+ requireInstance(other, Interval, 'other');
574
+
575
+ if (this.isConnected(other) === false) {
576
+ throw new core.DateTimeException("Intervals do not connect: " + this + " and " + other);
577
+ }
223
578
 
224
- var cmpStart = this._start.compareTo(other.start());
579
+ var cmpStart = this._start.compareTo(other.start());
225
580
 
226
- var cmpEnd = this._end.compareTo(other.end());
581
+ var cmpEnd = this._end.compareTo(other.end());
227
582
 
583
+ if (cmpStart >= 0 && cmpEnd <= 0) {
584
+ return other;
585
+ } else if (cmpStart <= 0 && cmpEnd >= 0) {
586
+ return this;
587
+ } else {
228
588
  var newStart = cmpStart >= 0 ? other.start() : this._start;
229
589
  var newEnd = cmpEnd <= 0 ? other.end() : this._end;
230
590
  return Interval.of(newStart, newEnd);
231
- };
591
+ }
592
+ };
232
593
 
233
- _proto.isAfter = function isAfter(instantOrInterval) {
234
- if (instantOrInterval instanceof core.Instant) {
235
- return this.isAfterInstant(instantOrInterval);
236
- } else {
237
- return this.isAfterInterval(instantOrInterval);
238
- }
239
- };
594
+ _proto.span = function span(other) {
595
+ requireNonNull(other, 'other');
596
+ requireInstance(other, Interval, 'other');
240
597
 
241
- _proto.isBefore = function isBefore(instantOrInterval) {
242
- if (instantOrInterval instanceof core.Instant) {
243
- return this.isBeforeInstant(instantOrInterval);
244
- } else {
245
- return this.isBeforeInterval(instantOrInterval);
246
- }
247
- };
598
+ var cmpStart = this._start.compareTo(other.start());
248
599
 
249
- _proto.isAfterInstant = function isAfterInstant(instant) {
250
- return this._start.compareTo(instant) > 0;
251
- };
600
+ var cmpEnd = this._end.compareTo(other.end());
252
601
 
253
- _proto.isBeforeInstant = function isBeforeInstant(instant) {
254
- return this._end.compareTo(instant) <= 0 && this._start.compareTo(instant) < 0;
255
- };
602
+ var newStart = cmpStart >= 0 ? other.start() : this._start;
603
+ var newEnd = cmpEnd <= 0 ? other.end() : this._end;
604
+ return Interval.of(newStart, newEnd);
605
+ };
256
606
 
257
- _proto.isAfterInterval = function isAfterInterval(interval) {
258
- return this._start.compareTo(interval.end()) >= 0 && !interval.equals(this);
259
- };
607
+ _proto.isAfter = function isAfter(instantOrInterval) {
608
+ if (instantOrInterval instanceof core.Instant) {
609
+ return this.isAfterInstant(instantOrInterval);
610
+ } else {
611
+ return this.isAfterInterval(instantOrInterval);
612
+ }
613
+ };
260
614
 
261
- _proto.isBeforeInterval = function isBeforeInterval(interval) {
262
- return this._end.compareTo(interval.start()) <= 0 && !interval.equals(this);
263
- };
615
+ _proto.isBefore = function isBefore(instantOrInterval) {
616
+ if (instantOrInterval instanceof core.Instant) {
617
+ return this.isBeforeInstant(instantOrInterval);
618
+ } else {
619
+ return this.isBeforeInterval(instantOrInterval);
620
+ }
621
+ };
264
622
 
265
- _proto.toDuration = function toDuration() {
266
- return core.Duration.between(this._start, this._end);
267
- };
623
+ _proto.isAfterInstant = function isAfterInstant(instant) {
624
+ return this._start.compareTo(instant) > 0;
625
+ };
268
626
 
269
- _proto.equals = function equals(obj) {
270
- if (this === obj) {
271
- return true;
272
- }
627
+ _proto.isBeforeInstant = function isBeforeInstant(instant) {
628
+ return this._end.compareTo(instant) <= 0 && this._start.compareTo(instant) < 0;
629
+ };
273
630
 
274
- if (obj instanceof Interval) {
275
- return this._start.equals(obj.start()) && this._end.equals(obj.end());
276
- }
631
+ _proto.isAfterInterval = function isAfterInterval(interval) {
632
+ return this._start.compareTo(interval.end()) >= 0 && !interval.equals(this);
633
+ };
277
634
 
278
- return false;
279
- };
635
+ _proto.isBeforeInterval = function isBeforeInterval(interval) {
636
+ return this._end.compareTo(interval.start()) <= 0 && !interval.equals(this);
637
+ };
280
638
 
281
- _proto.hashCode = function hashCode() {
282
- return this._start.hashCode() ^ this._end.hashCode();
283
- };
639
+ _proto.toDuration = function toDuration() {
640
+ return core.Duration.between(this._start, this._end);
641
+ };
284
642
 
285
- _proto.toString = function toString() {
286
- return this._start.toString() + "/" + this._end.toString();
287
- };
643
+ _proto.equals = function equals(obj) {
644
+ if (this === obj) {
645
+ return true;
646
+ }
288
647
 
289
- return Interval;
290
- }();
291
- function _init() {
292
- Interval.ALL = Interval.of(core.Instant.MIN, core.Instant.MAX);
293
- }
648
+ if (obj instanceof Interval) {
649
+ return this._start.equals(obj.start()) && this._end.equals(obj.end());
650
+ }
294
651
 
295
- /*
296
- * @copyright (c) 2016, Philipp Thürwächter & Pattrick Hüper
297
- * @license BSD-3-Clause (see LICENSE in the root directory of this source tree)
298
- */
299
- var isInit = false;
652
+ return false;
653
+ };
300
654
 
301
- function init() {
302
- if (isInit) {
303
- return;
304
- }
655
+ _proto.hashCode = function hashCode() {
656
+ return this._start.hashCode() ^ this._end.hashCode();
657
+ };
658
+
659
+ _proto.toString = function toString() {
660
+ return this._start.toString() + "/" + this._end.toString();
661
+ };
305
662
 
306
- isInit = true;
307
- _init();
663
+ return Interval;
664
+ }();
665
+ function _init() {
666
+ Interval.ALL = Interval.of(core.Instant.MIN, core.Instant.MAX);
667
+ }
668
+
669
+ /*
670
+ * @copyright (c) 2016, Philipp Thürwächter & Pattrick Hüper
671
+ * @license BSD-3-Clause (see LICENSE in the root directory of this source tree)
672
+ */
673
+ var isInit = false;
674
+
675
+ function init() {
676
+ if (isInit) {
677
+ return;
308
678
  }
309
679
 
310
- init();
680
+ isInit = true;
681
+ _init$2();
682
+ _init$1();
683
+ _init();
684
+ }
685
+
686
+ init();
311
687
 
312
- /*
313
- * @copyright (c) 2016, Philipp Thuerwaechter & Pattrick Hueper
314
- * @license BSD-3-Clause (see LICENSE.md in the root directory of this source tree)
315
- */
316
- function plug () {}
688
+ /*
689
+ * @copyright (c) 2016, Philipp Thuerwaechter & Pattrick Hueper
690
+ * @license BSD-3-Clause (see LICENSE.md in the root directory of this source tree)
691
+ */
692
+ function plug () {}
317
693
 
318
- /*
319
- * @copyright (c) 2016, Philipp Thuerwaechter & Pattrick Hueper
320
- * @license BSD-3-Clause (see LICENSE.md in the root directory of this source tree)
321
- */
322
- core.use(plug);
694
+ /*
695
+ * @copyright (c) 2016, Philipp Thuerwaechter & Pattrick Hueper
696
+ * @license BSD-3-Clause (see LICENSE.md in the root directory of this source tree)
697
+ */
698
+ core.use(plug);
323
699
 
324
- exports.Interval = Interval;
700
+ exports.DayOfMonth = DayOfMonth;
701
+ exports.DayOfYear = DayOfYear;
702
+ exports.Interval = Interval;
325
703
 
326
- Object.defineProperty(exports, '__esModule', { value: true });
704
+ Object.defineProperty(exports, '__esModule', { value: true });
327
705
 
328
706
  }));
329
707
  //# sourceMappingURL=js-joda-extra.js.map