@js-joda/extra 0.8.1 → 0.9.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-extra.esm.js +379 -3
- package/dist/js-joda-extra.esm.js.map +1 -1
- package/dist/js-joda-extra.js +619 -241
- package/dist/js-joda-extra.js.map +1 -1
- package/dist/js-joda-extra.min.js +2 -2
- package/package.json +3 -3
- package/src/DayOfMonth.js +487 -0
- package/src/DayOfYear.js +472 -0
- package/src/_init.js +4 -0
- package/src/js-joda-extra.js +4 -0
- package/src/plug.js +4 -0
- package/typings/js-joda-extra.d.ts +46 -1
|
@@ -1,9 +1,25 @@
|
|
|
1
|
-
//! @version @js-joda/extra - 0.
|
|
1
|
+
//! @version @js-joda/extra - 0.9.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)
|
|
5
5
|
|
|
6
|
-
import { NullPointerException, IllegalArgumentException,
|
|
6
|
+
import { NullPointerException, IllegalArgumentException, _, ChronoField, UnsupportedTemporalTypeException, TemporalQueries, IsoChronology, Month, MonthDay, TemporalAccessor, ZoneId, Clock, LocalDate, DateTimeException, TemporalQuery, Year, Instant, Duration, ZonedDateTime, DateTimeParseException, use } from '@js-joda/core';
|
|
7
|
+
|
|
8
|
+
function _inheritsLoose(subClass, superClass) {
|
|
9
|
+
subClass.prototype = Object.create(superClass.prototype);
|
|
10
|
+
subClass.prototype.constructor = subClass;
|
|
11
|
+
|
|
12
|
+
_setPrototypeOf(subClass, superClass);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function _setPrototypeOf(o, p) {
|
|
16
|
+
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
|
|
17
|
+
o.__proto__ = p;
|
|
18
|
+
return o;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
return _setPrototypeOf(o, p);
|
|
22
|
+
}
|
|
7
23
|
|
|
8
24
|
/**
|
|
9
25
|
* @copyright (c) 2016, Philipp Thürwächter & Pattrick Hüper
|
|
@@ -24,6 +40,364 @@ function requireInstance(value, _class, parameterName) {
|
|
|
24
40
|
return value;
|
|
25
41
|
}
|
|
26
42
|
|
|
43
|
+
var MathUtil$1 = _.MathUtil;
|
|
44
|
+
var DayOfMonth = function (_TemporalAccessor) {
|
|
45
|
+
_inheritsLoose(DayOfMonth, _TemporalAccessor);
|
|
46
|
+
|
|
47
|
+
DayOfMonth.now = function now(zoneIdOrClock) {
|
|
48
|
+
switch (arguments.length) {
|
|
49
|
+
case 0:
|
|
50
|
+
return DayOfMonth.now0();
|
|
51
|
+
|
|
52
|
+
case 1:
|
|
53
|
+
requireNonNull(zoneIdOrClock, 'clockOrZone');
|
|
54
|
+
|
|
55
|
+
if (zoneIdOrClock instanceof ZoneId) {
|
|
56
|
+
return DayOfMonth.nowZoneId(zoneIdOrClock);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (zoneIdOrClock instanceof Clock) {
|
|
60
|
+
return DayOfMonth.nowClock(zoneIdOrClock);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
throw new IllegalArgumentException("zoneIdOrClock must be an instance of ZoneId or Clock, but is " + zoneIdOrClock.constructor.name);
|
|
64
|
+
|
|
65
|
+
default:
|
|
66
|
+
throw new IllegalArgumentException("Invalid number of arguments: " + arguments.length);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
DayOfMonth.now0 = function now0() {
|
|
71
|
+
return this.now(Clock.systemDefaultZone());
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
DayOfMonth.nowZoneId = function nowZoneId(zone) {
|
|
75
|
+
return this.now(Clock.system(zone));
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
DayOfMonth.nowClock = function nowClock(clock) {
|
|
79
|
+
var now = LocalDate.now(clock);
|
|
80
|
+
return DayOfMonth.of(now.dayOfMonth());
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
DayOfMonth.of = function of(dayOfMonth) {
|
|
84
|
+
if (1 <= dayOfMonth && dayOfMonth <= 31) {
|
|
85
|
+
return DayOfMonth.VALUES[dayOfMonth - 1];
|
|
86
|
+
} else {
|
|
87
|
+
throw new DateTimeException("Invalid value for DayOfMonth: " + dayOfMonth);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
DayOfMonth.from = function from(temporal) {
|
|
92
|
+
if (temporal instanceof DayOfMonth) {
|
|
93
|
+
return temporal;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
requireNonNull(temporal, 'temporal');
|
|
97
|
+
|
|
98
|
+
try {
|
|
99
|
+
return DayOfMonth.of(temporal.get(ChronoField.DAY_OF_MONTH));
|
|
100
|
+
} catch (ex) {
|
|
101
|
+
throw new DateTimeException("Unable to obtain DayOfMonth from TemporalAccessor: " + temporal + " of type " + temporal.constructor.name, ex);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
function DayOfMonth(dayOfMonth) {
|
|
106
|
+
var _this;
|
|
107
|
+
|
|
108
|
+
_this = _TemporalAccessor.call(this) || this;
|
|
109
|
+
_this._day = MathUtil$1.safeToInt(dayOfMonth);
|
|
110
|
+
return _this;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
var _proto = DayOfMonth.prototype;
|
|
114
|
+
|
|
115
|
+
_proto.value = function value() {
|
|
116
|
+
return this._day;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
_proto.isSupported = function isSupported(field) {
|
|
120
|
+
if (field instanceof ChronoField) {
|
|
121
|
+
return field === ChronoField.DAY_OF_MONTH;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return field != null && field.isSupportedBy(this);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
_proto.range = function range(field) {
|
|
128
|
+
requireNonNull(field, 'field');
|
|
129
|
+
|
|
130
|
+
if (field === ChronoField.DAY_OF_MONTH) {
|
|
131
|
+
return field.range();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return _TemporalAccessor.prototype.range.call(this, field);
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
_proto.get = function get(field) {
|
|
138
|
+
return this.range(field).checkValidIntValue(this.getLong(field), field);
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
_proto.getLong = function getLong(field) {
|
|
142
|
+
requireNonNull(field, 'field');
|
|
143
|
+
|
|
144
|
+
if (field === ChronoField.DAY_OF_MONTH) {
|
|
145
|
+
return this._day;
|
|
146
|
+
} else if (field instanceof ChronoField) {
|
|
147
|
+
throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return field.getFrom(this);
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
_proto.isValidYearMonth = function isValidYearMonth(yearMonth) {
|
|
154
|
+
return yearMonth != null && yearMonth.isValidDay(this._day);
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
_proto.query = function query(_query) {
|
|
158
|
+
requireNonNull(_query, 'query');
|
|
159
|
+
requireInstance(_query, TemporalQuery, 'query');
|
|
160
|
+
|
|
161
|
+
if (_query === TemporalQueries.chronology()) {
|
|
162
|
+
return IsoChronology.INSTANCE;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return _TemporalAccessor.prototype.query.call(this, _query);
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
_proto.adjustInto = function adjustInto(temporal) {
|
|
169
|
+
requireNonNull(temporal, 'temporal');
|
|
170
|
+
return temporal.with(ChronoField.DAY_OF_MONTH, this._day);
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
_proto.atMonth = function atMonth(month) {
|
|
174
|
+
requireNonNull(month, 'month');
|
|
175
|
+
|
|
176
|
+
if (month instanceof Month) {
|
|
177
|
+
return MonthDay.of(month, Math.min(this._day, month.maxLength()));
|
|
178
|
+
} else {
|
|
179
|
+
return MonthDay.of(month, Math.min(this._day, Month.of(month).maxLength()));
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
_proto.atYearMonth = function atYearMonth(yearMonth) {
|
|
184
|
+
requireNonNull(yearMonth, 'yearMonth');
|
|
185
|
+
return yearMonth.atDay(Math.min(this._day, yearMonth.lengthOfMonth()));
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
_proto.compareTo = function compareTo(other) {
|
|
189
|
+
requireNonNull(other, 'other');
|
|
190
|
+
requireInstance(other, DayOfMonth, 'other');
|
|
191
|
+
return this._day - other._day;
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
_proto.equals = function equals(obj) {
|
|
195
|
+
if (this === obj) {
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (obj instanceof DayOfMonth) {
|
|
200
|
+
return this._day === obj._day;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return false;
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
_proto.hashCode = function hashCode() {
|
|
207
|
+
return this._day;
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
_proto.toString = function toString() {
|
|
211
|
+
return "DayOfMonth:" + this._day;
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
return DayOfMonth;
|
|
215
|
+
}(TemporalAccessor);
|
|
216
|
+
function _init$2() {
|
|
217
|
+
DayOfMonth.VALUES = new Array(31);
|
|
218
|
+
|
|
219
|
+
for (var i = 0; i < 31; i++) {
|
|
220
|
+
DayOfMonth.VALUES[i] = new DayOfMonth(i + 1);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
var MathUtil = _.MathUtil;
|
|
225
|
+
var DayOfYear = function (_TemporalAccessor) {
|
|
226
|
+
_inheritsLoose(DayOfYear, _TemporalAccessor);
|
|
227
|
+
|
|
228
|
+
DayOfYear.now = function now(zoneIdOrClock) {
|
|
229
|
+
switch (arguments.length) {
|
|
230
|
+
case 0:
|
|
231
|
+
return DayOfYear.now0();
|
|
232
|
+
|
|
233
|
+
case 1:
|
|
234
|
+
requireNonNull(zoneIdOrClock, 'clockOrZone');
|
|
235
|
+
|
|
236
|
+
if (zoneIdOrClock instanceof ZoneId) {
|
|
237
|
+
return DayOfYear.nowZoneId(zoneIdOrClock);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (zoneIdOrClock instanceof Clock) {
|
|
241
|
+
return DayOfYear.nowClock(zoneIdOrClock);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
throw new IllegalArgumentException("zoneIdOrClock must be an instance of ZoneId or Clock, but is " + zoneIdOrClock.constructor.name);
|
|
245
|
+
|
|
246
|
+
default:
|
|
247
|
+
throw new IllegalArgumentException("Invalid number of arguments: " + arguments.length);
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
DayOfYear.now0 = function now0() {
|
|
252
|
+
return DayOfYear.now(Clock.systemDefaultZone());
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
DayOfYear.nowZoneId = function nowZoneId(zone) {
|
|
256
|
+
return DayOfYear.now(Clock.system(zone));
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
DayOfYear.nowClock = function nowClock(clock) {
|
|
260
|
+
var now = LocalDate.now(clock);
|
|
261
|
+
return DayOfYear.of(now.dayOfYear());
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
DayOfYear.of = function of(dayOfYear) {
|
|
265
|
+
if (1 <= dayOfYear && dayOfYear <= 366) {
|
|
266
|
+
return DayOfYear.VALUES[dayOfYear - 1];
|
|
267
|
+
} else {
|
|
268
|
+
throw new DateTimeException("Invalid value for DayOfYear: " + dayOfYear);
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
DayOfYear.from = function from(temporal) {
|
|
273
|
+
requireNonNull(temporal, 'temporal');
|
|
274
|
+
requireInstance(temporal, TemporalAccessor, 'temporal');
|
|
275
|
+
|
|
276
|
+
if (temporal instanceof DayOfYear) {
|
|
277
|
+
return temporal;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
try {
|
|
281
|
+
return DayOfYear.of(temporal.get(ChronoField.DAY_OF_YEAR));
|
|
282
|
+
} catch (ex) {
|
|
283
|
+
throw new DateTimeException("Unable to obtain DayOfYear from TemporalAccessor: " + temporal + " of type " + temporal.constructor.name, ex);
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
function DayOfYear(dayOfYear) {
|
|
288
|
+
var _this;
|
|
289
|
+
|
|
290
|
+
_this = _TemporalAccessor.call(this) || this;
|
|
291
|
+
_this._day = MathUtil.safeToInt(dayOfYear);
|
|
292
|
+
return _this;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
var _proto = DayOfYear.prototype;
|
|
296
|
+
|
|
297
|
+
_proto.value = function value() {
|
|
298
|
+
return this._day;
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
_proto.isSupported = function isSupported(field) {
|
|
302
|
+
if (field instanceof ChronoField) {
|
|
303
|
+
return field === ChronoField.DAY_OF_YEAR;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
return field != null && field.isSupportedBy(this);
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
_proto.range = function range(field) {
|
|
310
|
+
requireNonNull(field, 'field');
|
|
311
|
+
|
|
312
|
+
if (field === ChronoField.DAY_OF_YEAR) {
|
|
313
|
+
return field.range();
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
return _TemporalAccessor.prototype.range.call(this, field);
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
_proto.get = function get(field) {
|
|
320
|
+
return this.range(field).checkValidIntValue(this.getLong(field), field);
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
_proto.getLong = function getLong(field) {
|
|
324
|
+
requireNonNull(field, 'field');
|
|
325
|
+
|
|
326
|
+
if (field === ChronoField.DAY_OF_YEAR) {
|
|
327
|
+
return this._day;
|
|
328
|
+
} else if (field instanceof ChronoField) {
|
|
329
|
+
throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
return field.getFrom(this);
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
_proto.isValidYear = function isValidYear(year) {
|
|
336
|
+
return this._day < 366 || Year.isLeap(year);
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
_proto.query = function query(_query) {
|
|
340
|
+
requireNonNull(_query, 'query');
|
|
341
|
+
requireInstance(_query, TemporalQuery, 'query');
|
|
342
|
+
|
|
343
|
+
if (_query === TemporalQueries.chronology()) {
|
|
344
|
+
return IsoChronology.INSTANCE;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
return _TemporalAccessor.prototype.query.call(this, _query);
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
_proto.adjustInto = function adjustInto(temporal) {
|
|
351
|
+
requireNonNull(temporal, 'temporal');
|
|
352
|
+
return temporal.with(ChronoField.DAY_OF_YEAR, this._day);
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
_proto.atYear = function atYear(year) {
|
|
356
|
+
requireNonNull(year, 'year');
|
|
357
|
+
|
|
358
|
+
if (year instanceof Year) {
|
|
359
|
+
return year.atDay(this._day);
|
|
360
|
+
} else {
|
|
361
|
+
return LocalDate.ofYearDay(year, this._day);
|
|
362
|
+
}
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
_proto.compareTo = function compareTo(other) {
|
|
366
|
+
requireNonNull(other, 'other');
|
|
367
|
+
requireInstance(other, DayOfYear, 'other');
|
|
368
|
+
return this._day - other._day;
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
_proto.equals = function equals(obj) {
|
|
372
|
+
if (this === obj) {
|
|
373
|
+
return true;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
if (obj instanceof DayOfYear) {
|
|
377
|
+
return this._day === obj._day;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
return false;
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
_proto.hashCode = function hashCode() {
|
|
384
|
+
return this._day;
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
_proto.toString = function toString() {
|
|
388
|
+
return "DayOfYear:" + this._day;
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
return DayOfYear;
|
|
392
|
+
}(TemporalAccessor);
|
|
393
|
+
function _init$1() {
|
|
394
|
+
DayOfYear.VALUES = new Array(366);
|
|
395
|
+
|
|
396
|
+
for (var i = 0; i < 366; i++) {
|
|
397
|
+
DayOfYear.VALUES[i] = new DayOfYear(i + 1);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
27
401
|
/*
|
|
28
402
|
* @copyright (c) 2016, Philipp Thürwächter & Pattrick Hüper
|
|
29
403
|
* @copyright (c) 2007-present, Stephen Colebourne & Michael Nascimento Santos
|
|
@@ -300,6 +674,8 @@ function init() {
|
|
|
300
674
|
}
|
|
301
675
|
|
|
302
676
|
isInit = true;
|
|
677
|
+
_init$2();
|
|
678
|
+
_init$1();
|
|
303
679
|
_init();
|
|
304
680
|
}
|
|
305
681
|
|
|
@@ -317,5 +693,5 @@ function plug () {}
|
|
|
317
693
|
*/
|
|
318
694
|
use(plug);
|
|
319
695
|
|
|
320
|
-
export { Interval };
|
|
696
|
+
export { DayOfMonth, DayOfYear, Interval };
|
|
321
697
|
//# sourceMappingURL=js-joda-extra.esm.js.map
|