@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
package/src/DayOfYear.js
ADDED
|
@@ -0,0 +1,472 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @copyright (c) 2022, Philipp Thürwächter & Pattrick Hüper & Michał Sobkiewicz
|
|
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, Clock, DateTimeException, IllegalArgumentException, IsoChronology, LocalDate, TemporalAccessor, TemporalQueries, TemporalQuery, UnsupportedTemporalTypeException, Year, ZoneId } from '@js-joda/core';
|
|
8
|
+
|
|
9
|
+
// TODO: hm... is this a good idea?? copied from joda currently, could we add a js-joda-utils module??
|
|
10
|
+
import { requireInstance, requireNonNull } from './assert';
|
|
11
|
+
import { _ as jodaInternal } from '@js-joda/core';
|
|
12
|
+
|
|
13
|
+
const MathUtil = jodaInternal.MathUtil;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A day-of-year in the ISO-8601 calendar system.
|
|
17
|
+
*
|
|
18
|
+
* {@link DayOfYear} is an immutable date-time object that represents a day-of-year.
|
|
19
|
+
* It is a type-safe way of representing a day-of-year in an application.
|
|
20
|
+
* Any field that can be derived from a day-of-year can be obtained.
|
|
21
|
+
*
|
|
22
|
+
* This class does not store or represent a year, month, time or time-zone.
|
|
23
|
+
* For example, the value "51" can be stored in a {@link DayOfYear} and
|
|
24
|
+
* would represent the 51st day of any year.
|
|
25
|
+
*/
|
|
26
|
+
export class DayOfYear extends TemporalAccessor {
|
|
27
|
+
/**
|
|
28
|
+
* Function overloading for {@link DayOfYear.now}:
|
|
29
|
+
* * if called with no arguments, {@link DayOfYear.now0} is executed;
|
|
30
|
+
* * if called with an instance of {@link ZoneId}, then {@link DayOfYear.nowZoneId} is executed;
|
|
31
|
+
* * if called with an instance of {@link Clock}, then {@link DayOfYear.nowClock} is executed;
|
|
32
|
+
* * otherwise {@link IllegalArgumentException} is thrown.
|
|
33
|
+
*
|
|
34
|
+
* @param {?(ZoneId|Clock)} zoneIdOrClock
|
|
35
|
+
* @returns {DayOfYear}
|
|
36
|
+
*/
|
|
37
|
+
static now(zoneIdOrClock) {
|
|
38
|
+
switch (arguments.length) {
|
|
39
|
+
case 0:
|
|
40
|
+
return DayOfYear.now0();
|
|
41
|
+
case 1:
|
|
42
|
+
requireNonNull(zoneIdOrClock, 'clockOrZone');
|
|
43
|
+
if (zoneIdOrClock instanceof ZoneId) {
|
|
44
|
+
return DayOfYear.nowZoneId(zoneIdOrClock);
|
|
45
|
+
}
|
|
46
|
+
if (zoneIdOrClock instanceof Clock) {
|
|
47
|
+
return DayOfYear.nowClock(zoneIdOrClock);
|
|
48
|
+
}
|
|
49
|
+
throw new IllegalArgumentException(`zoneIdOrClock must be an instance of ZoneId or Clock, but is ${zoneIdOrClock.constructor.name}`);
|
|
50
|
+
default:
|
|
51
|
+
throw new IllegalArgumentException(`Invalid number of arguments: ${arguments.length}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
//-----------------------------------------------------------------------
|
|
56
|
+
/**
|
|
57
|
+
* Obtains the current day-of-year from the system clock in the default time-zone.
|
|
58
|
+
*
|
|
59
|
+
* This will query the {@link Clock.systemDefaultZone} system clock in the default
|
|
60
|
+
* time-zone to obtain the current day-of-year.
|
|
61
|
+
* The zone and offset will be set based on the time-zone in the clock.
|
|
62
|
+
*
|
|
63
|
+
* Using this method will prevent the ability to use an alternate clock for testing
|
|
64
|
+
* because the clock is hard-coded.
|
|
65
|
+
*
|
|
66
|
+
* @return the current day-of-year using the system clock and default time-zone, not null
|
|
67
|
+
* @private
|
|
68
|
+
*/
|
|
69
|
+
static now0() {
|
|
70
|
+
return DayOfYear.now(Clock.systemDefaultZone());
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Obtains the current day-of-year from the system clock in the specified time-zone.
|
|
75
|
+
*
|
|
76
|
+
* This will query the {@link Clock.system} system clock to obtain the current day-of-year.
|
|
77
|
+
* Specifying the time-zone avoids dependence on the default time-zone.
|
|
78
|
+
*
|
|
79
|
+
* Using this method will prevent the ability to use an alternate clock for testing
|
|
80
|
+
* because the clock is hard-coded.
|
|
81
|
+
*
|
|
82
|
+
* @param zone the zone ID to use, not null
|
|
83
|
+
* @return the current day-of-year using the system clock, not null
|
|
84
|
+
* @private
|
|
85
|
+
*/
|
|
86
|
+
static nowZoneId(zone) {
|
|
87
|
+
return DayOfYear.now(Clock.system(zone));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Obtains the current day-of-year from the specified clock.
|
|
92
|
+
*
|
|
93
|
+
* This will query the specified clock to obtain the current day-of-year.
|
|
94
|
+
* Using this method allows the use of an alternate clock for testing.
|
|
95
|
+
* The alternate clock may be introduced using {@link Clock} dependency injection.
|
|
96
|
+
*
|
|
97
|
+
* @param clock the clock to use, not null
|
|
98
|
+
* @return the current day-of-year, not null
|
|
99
|
+
* @private
|
|
100
|
+
*/
|
|
101
|
+
static nowClock(clock) {
|
|
102
|
+
const now = LocalDate.now(clock); // called once
|
|
103
|
+
return DayOfYear.of(now.dayOfYear());
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
//-----------------------------------------------------------------------
|
|
107
|
+
/**
|
|
108
|
+
* Obtains an instance of {@link DayOfYear}.
|
|
109
|
+
*
|
|
110
|
+
* A day-of-year object represents one of the 366 days of the year, from 1 to 366.
|
|
111
|
+
*
|
|
112
|
+
* @param dayOfYear the day-of-year to represent, from 1 to 366
|
|
113
|
+
* @return the day-of-year, not null
|
|
114
|
+
* @throws {DateTimeException} if the day-of-year is invalid
|
|
115
|
+
*/
|
|
116
|
+
static of(dayOfYear) {
|
|
117
|
+
if (1 <= dayOfYear && dayOfYear <= 366) {
|
|
118
|
+
return DayOfYear.VALUES[dayOfYear - 1];
|
|
119
|
+
} else {
|
|
120
|
+
throw new DateTimeException(`Invalid value for DayOfYear: ${dayOfYear}`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
//-----------------------------------------------------------------------
|
|
125
|
+
/**
|
|
126
|
+
* Obtains an instance of {@link DayOfYear} from a date-time object.
|
|
127
|
+
*
|
|
128
|
+
* This obtains a day-of-year based on the specified temporal.
|
|
129
|
+
* A {@link TemporalAccessor} represents an arbitrary set of date and time information,
|
|
130
|
+
* which this factory converts to an instance of {@link DayOfYear}.
|
|
131
|
+
*
|
|
132
|
+
* The conversion extracts the {@link ChronoField.DAY_OF_YEAR} day-of-year field.
|
|
133
|
+
* The extraction is only permitted if the temporal object has an ISO
|
|
134
|
+
* chronology, or can be converted to a {@link LocalDate}.
|
|
135
|
+
*
|
|
136
|
+
* This method matches the signature of the functional interface {@link TemporalQuery}
|
|
137
|
+
* allowing it to be used in queries via method reference, {@link DayOfYear.from}.
|
|
138
|
+
*
|
|
139
|
+
* @param temporal the temporal object to convert, not null
|
|
140
|
+
* @return the day-of-year, not null
|
|
141
|
+
* @throws {DateTimeException} if unable to convert to a {@link DayOfYear}
|
|
142
|
+
*/
|
|
143
|
+
static from(temporal) {
|
|
144
|
+
requireNonNull(temporal, 'temporal');
|
|
145
|
+
requireInstance(temporal, TemporalAccessor, 'temporal');
|
|
146
|
+
if (temporal instanceof DayOfYear) {
|
|
147
|
+
return temporal;
|
|
148
|
+
}
|
|
149
|
+
try {
|
|
150
|
+
/* TODO: only IsoChronology for now
|
|
151
|
+
if (IsoChronology.INSTANCE.equals(Chronology.from(temporal)) == false) {
|
|
152
|
+
temporal = LocalDate.from(temporal);
|
|
153
|
+
}*/
|
|
154
|
+
return DayOfYear.of(temporal.get(ChronoField.DAY_OF_YEAR));
|
|
155
|
+
} catch (ex) {
|
|
156
|
+
throw new DateTimeException(`Unable to obtain DayOfYear from TemporalAccessor: ${temporal} of type ${temporal.constructor.name}`, ex);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
//-----------------------------------------------------------------------
|
|
162
|
+
/**
|
|
163
|
+
* Constructor, previously validated.
|
|
164
|
+
*
|
|
165
|
+
* @param {number} dayOfYear the day-of-year being represented, from 1 to 366.
|
|
166
|
+
* @private
|
|
167
|
+
*/
|
|
168
|
+
constructor(dayOfYear) {
|
|
169
|
+
super();
|
|
170
|
+
this._day = MathUtil.safeToInt(dayOfYear);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
//-----------------------------------------------------------------------
|
|
174
|
+
/**
|
|
175
|
+
* Gets the day-of-year value.
|
|
176
|
+
*
|
|
177
|
+
* @return the day-of-year, from 1 to 366
|
|
178
|
+
*/
|
|
179
|
+
value() {
|
|
180
|
+
return this._day;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
//-----------------------------------------------------------------------
|
|
184
|
+
/**
|
|
185
|
+
* Checks if the specified field is supported.
|
|
186
|
+
*
|
|
187
|
+
* This checks if this day-of-year can be queried for the specified field.
|
|
188
|
+
* If false, then calling the {@link DayOfYear.range} range,
|
|
189
|
+
* {@link DayOfYear.get} get and {@link DayOfYear.getLong} getLong
|
|
190
|
+
* methods will throw an exception.
|
|
191
|
+
*
|
|
192
|
+
* If the field is a {@link ChronoField} then the query is implemented here.
|
|
193
|
+
* The supported fields are:
|
|
194
|
+
*
|
|
195
|
+
* * {@link ChronoField.DAY_OF_YEAR}
|
|
196
|
+
*
|
|
197
|
+
* All other {@link ChronoField} instances will return false.
|
|
198
|
+
*
|
|
199
|
+
* If the field is not a {@link ChronoField}, then the result of this method
|
|
200
|
+
* is obtained by invoking {@link TemporalField.isSupportedBy}
|
|
201
|
+
* passing this as the argument.
|
|
202
|
+
* Whether the field is supported is determined by the field.
|
|
203
|
+
*
|
|
204
|
+
* @param field the field to check, null returns false
|
|
205
|
+
* @return true if the field is supported on this day-of-year, false if not
|
|
206
|
+
*/
|
|
207
|
+
isSupported(field) {
|
|
208
|
+
if (field instanceof ChronoField) {
|
|
209
|
+
return field === ChronoField.DAY_OF_YEAR;
|
|
210
|
+
}
|
|
211
|
+
return field != null && field.isSupportedBy(this);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
//-----------------------------------------------------------------------
|
|
215
|
+
/**
|
|
216
|
+
* Gets the range of valid values for the specified field.
|
|
217
|
+
*
|
|
218
|
+
* The range object expresses the minimum and maximum valid values for a field.
|
|
219
|
+
* This day-of-year is used to enhance the accuracy of the returned range.
|
|
220
|
+
* If it is not possible to return the range, because the field is not supported
|
|
221
|
+
* or for some other reason, an exception is thrown.
|
|
222
|
+
*
|
|
223
|
+
* If the field is a {@link ChronoField} then the query is implemented here.
|
|
224
|
+
* The {@link DayOfYear.isSupported} supported fields will return
|
|
225
|
+
* appropriate range instances.
|
|
226
|
+
* All other {@code ChronoField} instances will throw an {@link UnsupportedTemporalTypeException}.
|
|
227
|
+
*
|
|
228
|
+
* If the field is not a {@link ChronoField}, then the result of this method
|
|
229
|
+
* is obtained by invoking {@link TemporalField.rangeRefinedBy}
|
|
230
|
+
* passing this as the argument.
|
|
231
|
+
* Whether the range can be obtained is determined by the field.
|
|
232
|
+
*
|
|
233
|
+
* @param field the field to query the range for, not null
|
|
234
|
+
* @return the range of valid values for the field, not null
|
|
235
|
+
* @throws {DateTimeException} if the range for the field cannot be obtained
|
|
236
|
+
* @throws {UnsupportedTemporalTypeException} if the field is not supported
|
|
237
|
+
*/
|
|
238
|
+
range(field) {
|
|
239
|
+
requireNonNull(field, 'field');
|
|
240
|
+
if (field === ChronoField.DAY_OF_YEAR) {
|
|
241
|
+
return field.range();
|
|
242
|
+
}
|
|
243
|
+
return super.range(field);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Gets the value of the specified field from this day-of-year as an `int`.
|
|
248
|
+
*
|
|
249
|
+
* This queries this day-of-year for the value for the specified field.
|
|
250
|
+
* The returned value will always be within the valid range of values for the field.
|
|
251
|
+
* If it is not possible to return the value, because the field is not supported
|
|
252
|
+
* or for some other reason, an exception is thrown.
|
|
253
|
+
*
|
|
254
|
+
* If the field is a {@link ChronoField} then the query is implemented here.
|
|
255
|
+
* The {@link DayOfYear.isSupported} supported fields will return valid
|
|
256
|
+
* values based on this day-of-year.
|
|
257
|
+
* All other {@link ChronoField} instances will throw an {@link UnsupportedTemporalTypeException}.
|
|
258
|
+
*
|
|
259
|
+
* If the field is not a {@link ChronoField}, then the result of this method
|
|
260
|
+
* is obtained by invoking {@link TemporalField.getFrom}
|
|
261
|
+
* passing this as the argument. Whether the value can be obtained,
|
|
262
|
+
* and what the value represents, is determined by the field.
|
|
263
|
+
*
|
|
264
|
+
* @param field the field to get, not null
|
|
265
|
+
* @return the value for the field
|
|
266
|
+
* @throws {DateTimeException} if a value for the field cannot be obtained or
|
|
267
|
+
* the value is outside the range of valid values for the field
|
|
268
|
+
* @throws {UnsupportedTemporalTypeException} if the field is not supported or
|
|
269
|
+
* the range of values exceeds an `int`
|
|
270
|
+
* @throws {ArithmeticException} if numeric overflow occurs
|
|
271
|
+
*/
|
|
272
|
+
get(field) {
|
|
273
|
+
return this.range(field).checkValidIntValue(this.getLong(field), field);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Gets the value of the specified field from this day-of-year as a `long`.
|
|
278
|
+
*
|
|
279
|
+
* This queries this day-of-year for the value for the specified field.
|
|
280
|
+
* If it is not possible to return the value, because the field is not supported
|
|
281
|
+
* or for some other reason, an exception is thrown.
|
|
282
|
+
*
|
|
283
|
+
* If the field is a {@link ChronoField} then the query is implemented here.
|
|
284
|
+
* The {@link DayOfYear.isSupported} supported fields will return valid
|
|
285
|
+
* values based on this day-of-year.
|
|
286
|
+
* All other {@code ChronoField} instances will throw an {@link UnsupportedTemporalTypeException}.
|
|
287
|
+
*
|
|
288
|
+
* If the field is not a {@link ChronoField}, then the result of this method
|
|
289
|
+
* is obtained by invoking {@link TemporalField.getFrom}
|
|
290
|
+
* passing this as the argument. Whether the value can be obtained,
|
|
291
|
+
* and what the value represents, is determined by the field.
|
|
292
|
+
*
|
|
293
|
+
* @param field the field to get, not null
|
|
294
|
+
* @return the value for the field
|
|
295
|
+
* @throws {DateTimeException} if a value for the field cannot be obtained
|
|
296
|
+
* @throws {UnsupportedTemporalTypeException} if the field is not supported
|
|
297
|
+
* @throws {ArithmeticException} if numeric overflow occurs
|
|
298
|
+
*/
|
|
299
|
+
getLong(field) {
|
|
300
|
+
requireNonNull(field, 'field');
|
|
301
|
+
if (field === ChronoField.DAY_OF_YEAR) {
|
|
302
|
+
return this._day;
|
|
303
|
+
} else if (field instanceof ChronoField) {
|
|
304
|
+
throw new UnsupportedTemporalTypeException(`Unsupported field: ${field}`);
|
|
305
|
+
}
|
|
306
|
+
return field.getFrom(this);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
//-----------------------------------------------------------------------
|
|
310
|
+
/**
|
|
311
|
+
* Checks if the year is valid for this day-of-year.
|
|
312
|
+
*
|
|
313
|
+
* This method checks whether this day-of-yearand the input year form
|
|
314
|
+
* a valid date. This can only return false for day-of-year 366.
|
|
315
|
+
*
|
|
316
|
+
* @param year the year to validate
|
|
317
|
+
* @return true if the year is valid for this day-of-year
|
|
318
|
+
*/
|
|
319
|
+
isValidYear(year) {
|
|
320
|
+
return (this._day < 366 || Year.isLeap(year));
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
//-----------------------------------------------------------------------
|
|
324
|
+
/**
|
|
325
|
+
* Queries this day-of-year using the specified query.
|
|
326
|
+
*
|
|
327
|
+
* This queries this day-of-year using the specified query strategy object.
|
|
328
|
+
* The {@link TemporalQuery} object defines the logic to be used to
|
|
329
|
+
* obtain the result. Read the documentation of the query to understand
|
|
330
|
+
* what the result of this method will be.
|
|
331
|
+
*
|
|
332
|
+
* The result of this method is obtained by invoking the
|
|
333
|
+
* {@link TemporalQuery.queryFrom} method on the
|
|
334
|
+
* specified query passing this as the argument.
|
|
335
|
+
*
|
|
336
|
+
* @param query the query to invoke, not null
|
|
337
|
+
* @return the query result, null may be returned (defined by the query)
|
|
338
|
+
* @throws {DateTimeException} if unable to query (defined by the query)
|
|
339
|
+
* @throws {ArithmeticException} if numeric overflow occurs (defined by the query)
|
|
340
|
+
*/
|
|
341
|
+
query(query) {
|
|
342
|
+
requireNonNull(query, 'query');
|
|
343
|
+
requireInstance(query, TemporalQuery, 'query');
|
|
344
|
+
if (query === TemporalQueries.chronology()) {
|
|
345
|
+
return IsoChronology.INSTANCE;
|
|
346
|
+
}
|
|
347
|
+
return super.query(query);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Adjusts the specified temporal object to have this day-of-year.
|
|
352
|
+
*
|
|
353
|
+
* This returns a temporal object of the same observable type as the input
|
|
354
|
+
* with the day-of-year changed to be the same as this.
|
|
355
|
+
*
|
|
356
|
+
* The adjustment is equivalent to using {@link Temporal.with}
|
|
357
|
+
* passing {@link ChronoField.DAY_OF_YEAR} as the field.
|
|
358
|
+
* If the specified temporal object does not use the ISO calendar system then
|
|
359
|
+
* a {@link DateTimeException} is thrown.
|
|
360
|
+
*
|
|
361
|
+
* In most cases, it is clearer to reverse the calling pattern by using
|
|
362
|
+
* {@link Temporal.with}:
|
|
363
|
+
* ```
|
|
364
|
+
* // these two lines are equivalent, but the second approach is recommended
|
|
365
|
+
* temporal = thisDay.adjustInto(temporal);
|
|
366
|
+
* temporal = temporal.with(thisDay);
|
|
367
|
+
* ```
|
|
368
|
+
*
|
|
369
|
+
* This instance is immutable and unaffected by this method call.
|
|
370
|
+
*
|
|
371
|
+
* @param temporal the target object to be adjusted, not null
|
|
372
|
+
* @return the adjusted object, not null
|
|
373
|
+
* @throws {DateTimeException} if unable to make the adjustment
|
|
374
|
+
* @throws {ArithmeticException} if numeric overflow occurs
|
|
375
|
+
*/
|
|
376
|
+
adjustInto(temporal) {
|
|
377
|
+
requireNonNull(temporal, 'temporal');
|
|
378
|
+
/* TODO: only IsoChronology for now
|
|
379
|
+
if (Chronology.from(temporal).equals(IsoChronology.INSTANCE) === false) {
|
|
380
|
+
throw new DateTimeException("Adjustment only supported on ISO date-time");
|
|
381
|
+
}*/
|
|
382
|
+
return temporal.with(ChronoField.DAY_OF_YEAR, this._day);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
//-----------------------------------------------------------------------
|
|
386
|
+
/**
|
|
387
|
+
* Combines this day-of-year with a year to create a {@link LocalDate}.
|
|
388
|
+
*
|
|
389
|
+
* This returns a {@link LocalDate} formed from this day and the specified year.
|
|
390
|
+
*
|
|
391
|
+
* This method can be used as part of a chain to produce a date:
|
|
392
|
+
* ```
|
|
393
|
+
* LocalDate date = day.atYear(year);
|
|
394
|
+
* ```
|
|
395
|
+
*
|
|
396
|
+
* The day-of-year value 366 is only valid in a leap year.
|
|
397
|
+
*
|
|
398
|
+
* @param year the year to use ({@link Year} or `int`), not null
|
|
399
|
+
* @return the local date formed from this day and the specified year, not null
|
|
400
|
+
* @throws {DateTimeException} if the year is invalid or this is day 366 and the year is not a leap year
|
|
401
|
+
*/
|
|
402
|
+
atYear(year) {
|
|
403
|
+
requireNonNull(year, 'year');
|
|
404
|
+
if (year instanceof Year) {
|
|
405
|
+
return year.atDay(this._day);
|
|
406
|
+
} else {
|
|
407
|
+
return LocalDate.ofYearDay(year, this._day);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
//-----------------------------------------------------------------------
|
|
412
|
+
/**
|
|
413
|
+
* Compares this day-of-year to another.
|
|
414
|
+
*
|
|
415
|
+
* The comparison is based on the value of the day.
|
|
416
|
+
* It is "consistent with equals", as defined by {@link Comparable}.
|
|
417
|
+
*
|
|
418
|
+
* @param other the other day-of-year instance, not null
|
|
419
|
+
* @return the comparator value, negative if less, positive if greater
|
|
420
|
+
*/
|
|
421
|
+
compareTo(other) {
|
|
422
|
+
requireNonNull(other, 'other');
|
|
423
|
+
requireInstance(other, DayOfYear, 'other');
|
|
424
|
+
return this._day - other._day;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
//-----------------------------------------------------------------------
|
|
428
|
+
/**
|
|
429
|
+
* Checks if this day-of-year is equal to another day-of-year.
|
|
430
|
+
*
|
|
431
|
+
* @param obj the other day-of-year instance, null returns false
|
|
432
|
+
* @return true if the day-of-year is the same
|
|
433
|
+
*/
|
|
434
|
+
equals(obj) {
|
|
435
|
+
if (this === obj) {
|
|
436
|
+
return true;
|
|
437
|
+
}
|
|
438
|
+
if (obj instanceof DayOfYear) {
|
|
439
|
+
return this._day === obj._day;
|
|
440
|
+
}
|
|
441
|
+
return false;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* A hash code for this day-of-year.
|
|
446
|
+
*
|
|
447
|
+
* @return a suitable hash code
|
|
448
|
+
*/
|
|
449
|
+
hashCode() {
|
|
450
|
+
return this._day;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
//-----------------------------------------------------------------------
|
|
454
|
+
/**
|
|
455
|
+
* Outputs this day-of-year as a {@link String}.
|
|
456
|
+
*
|
|
457
|
+
* @return a string representation of this day-of-year, not null
|
|
458
|
+
*/
|
|
459
|
+
toString() {
|
|
460
|
+
return `DayOfYear:${this._day}`;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
export function _init() {
|
|
465
|
+
/**
|
|
466
|
+
* Cache of singleton instances.
|
|
467
|
+
*/
|
|
468
|
+
DayOfYear.VALUES = new Array(366);
|
|
469
|
+
for (let i = 0; i < 366; i++) {
|
|
470
|
+
DayOfYear.VALUES[i] = new DayOfYear(i + 1);
|
|
471
|
+
}
|
|
472
|
+
}
|
package/src/_init.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
* @license BSD-3-Clause (see LICENSE in the root directory of this source tree)
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import { _init as dayOfMonthInit } from './DayOfMonth';
|
|
7
|
+
import { _init as dayOfYearInit } from './DayOfYear';
|
|
6
8
|
import { _init as intervalInit } from './Interval';
|
|
7
9
|
|
|
8
10
|
let isInit = false;
|
|
@@ -14,6 +16,8 @@ function init() {
|
|
|
14
16
|
|
|
15
17
|
isInit = true;
|
|
16
18
|
|
|
19
|
+
dayOfMonthInit();
|
|
20
|
+
dayOfYearInit();
|
|
17
21
|
intervalInit();
|
|
18
22
|
}
|
|
19
23
|
|
package/src/js-joda-extra.js
CHANGED
|
@@ -5,11 +5,15 @@
|
|
|
5
5
|
|
|
6
6
|
import { use } from '@js-joda/core';
|
|
7
7
|
|
|
8
|
+
import { DayOfMonth } from './DayOfMonth';
|
|
9
|
+
import { DayOfYear } from './DayOfYear';
|
|
8
10
|
import { Interval } from './Interval';
|
|
9
11
|
import plug from './plug';
|
|
10
12
|
|
|
11
13
|
use(plug);
|
|
12
14
|
|
|
13
15
|
export {
|
|
16
|
+
DayOfMonth,
|
|
17
|
+
DayOfYear,
|
|
14
18
|
Interval,
|
|
15
19
|
};
|
package/src/plug.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
* @license BSD-3-Clause (see LICENSE.md in the root directory of this source tree)
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
// import { DayOfMonth } from './DayOfMonth';
|
|
7
|
+
// import { DayOfYear } from './DayOfYear';
|
|
6
8
|
// import { Interval } from './Interval';
|
|
7
9
|
|
|
8
10
|
import './_init';
|
|
@@ -14,5 +16,7 @@ import './_init';
|
|
|
14
16
|
*/
|
|
15
17
|
export default function (/* jsJoda */) {
|
|
16
18
|
// assign new prop to jsJoda context is useless, because it lives only in the local context
|
|
19
|
+
// jsJoda.DayOfMonth = DayOfMonth;
|
|
20
|
+
// jsJoda.DayOfYear = DayOfYear;
|
|
17
21
|
// jsJoda.Interval = Interval;
|
|
18
22
|
}
|
|
@@ -1,4 +1,49 @@
|
|
|
1
|
-
import { Instant, Duration } from '@js-joda/core';
|
|
1
|
+
import { Instant, Duration, TemporalAccessor, Clock, ZoneId, TemporalField, ValueRange, TemporalQuery, Temporal, LocalDate, Year, MonthDay, YearMonth, Month } from '@js-joda/core';
|
|
2
|
+
|
|
3
|
+
export class DayOfMonth extends TemporalAccessor {
|
|
4
|
+
static from(temporal: TemporalAccessor): DayOfMonth;
|
|
5
|
+
static now(zoneIdOrClock?: ZoneId | Clock): DayOfMonth;
|
|
6
|
+
static of(dayOfMonth: number): DayOfMonth;
|
|
7
|
+
|
|
8
|
+
private constructor(dayOfMonth: number);
|
|
9
|
+
|
|
10
|
+
adjustInto(temporal: Temporal): Temporal;
|
|
11
|
+
atMonth(month: number | Month): MonthDay;
|
|
12
|
+
atYearMonth(yearMonth: YearMonth): LocalDate;
|
|
13
|
+
compareTo(other: DayOfMonth): number;
|
|
14
|
+
equals(obj: any): boolean;
|
|
15
|
+
get(field: TemporalField): number;
|
|
16
|
+
getLong(field: TemporalField): number;
|
|
17
|
+
value(): number;
|
|
18
|
+
hashCode(): number;
|
|
19
|
+
isSupported(field: TemporalField): boolean;
|
|
20
|
+
isValidYearMonth(yearMonth: YearMonth): boolean;
|
|
21
|
+
query<R>(query: TemporalQuery<R>): R | null;
|
|
22
|
+
range(field: TemporalField): ValueRange;
|
|
23
|
+
toString(): string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export class DayOfYear extends TemporalAccessor {
|
|
27
|
+
static from(temporal: TemporalAccessor): DayOfYear;
|
|
28
|
+
static now(zoneIdOrClock?: ZoneId | Clock): DayOfYear;
|
|
29
|
+
static of(dayOfYear: number): DayOfYear;
|
|
30
|
+
|
|
31
|
+
private constructor(dayOfYear: number);
|
|
32
|
+
|
|
33
|
+
adjustInto(temporal: Temporal): Temporal;
|
|
34
|
+
atYear(year: number | Year): LocalDate;
|
|
35
|
+
compareTo(other: DayOfYear): number;
|
|
36
|
+
equals(obj: any): boolean;
|
|
37
|
+
get(field: TemporalField): number;
|
|
38
|
+
getLong(field: TemporalField): number;
|
|
39
|
+
value(): number;
|
|
40
|
+
hashCode(): number;
|
|
41
|
+
isSupported(field: TemporalField): boolean;
|
|
42
|
+
isValidYear(year: number): boolean;
|
|
43
|
+
query<R>(query: TemporalQuery<R>): R | null;
|
|
44
|
+
range(field: TemporalField): ValueRange;
|
|
45
|
+
toString(): string;
|
|
46
|
+
}
|
|
2
47
|
|
|
3
48
|
export class Interval {
|
|
4
49
|
static of(startInclusive: Instant, endExclusive: Instant): Interval;
|