@fr0st/datetime 6.1.1 → 8.0.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/Formats.md +454 -0
- package/LICENSE +0 -0
- package/README.md +407 -1868
- package/dist/frost-datetime.js +2526 -2376
- package/dist/frost-datetime.js.map +1 -1
- package/dist/frost-datetime.min.js +2 -1
- package/dist/frost-datetime.min.js.map +1 -1
- package/package.json +32 -19
- package/src/date-time.js +2094 -90
- package/src/factory.js +29 -19
- package/src/formatter/format.js +38 -29
- package/src/formatter/locale.js +80 -0
- package/src/formatter/locales.js +2 -2
- package/src/formatter/parse.js +26 -12
- package/src/formatter/tokens.js +113 -123
- package/src/formatter/utility.js +38 -64
- package/src/formatter/values.js +26 -22
- package/src/helpers.js +178 -52
- package/src/index.js +1 -186
- package/src/vars.js +4 -4
- package/src/prototype/attributes-get.js +0 -163
- package/src/prototype/attributes-set.js +0 -281
- package/src/prototype/comparisons.js +0 -605
- package/src/prototype/manipulate.js +0 -395
- package/src/prototype/output.js +0 -89
- package/src/prototype/utility.js +0 -127
- package/src/static/create.js +0 -222
- package/src/static/utility.js +0 -103
|
@@ -1,395 +0,0 @@
|
|
|
1
|
-
import { daysInMonth } from './../static/utility.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* DateTime Manipulation
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Add a day to the current DateTime.
|
|
9
|
-
* @return {DateTime} The DateTime object.
|
|
10
|
-
*/
|
|
11
|
-
export function addDay() {
|
|
12
|
-
return this.addDays(1);
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Add days to the current DateTime.
|
|
17
|
-
* @param {number} amount The number of days to add.
|
|
18
|
-
* @return {DateTime} The DateTime object.
|
|
19
|
-
*/
|
|
20
|
-
export function addDays(amount) {
|
|
21
|
-
return this.setDate(
|
|
22
|
-
this.getDate() + amount,
|
|
23
|
-
);
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Add an hour to the current DateTime.
|
|
28
|
-
* @return {DateTime} The DateTime object.
|
|
29
|
-
*/
|
|
30
|
-
export function addHour() {
|
|
31
|
-
return this.addHours(1);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Add hours to the current DateTime.
|
|
36
|
-
* @param {number} amount The number of hours to add.
|
|
37
|
-
* @return {DateTime} The DateTime object.
|
|
38
|
-
*/
|
|
39
|
-
export function addHours(amount) {
|
|
40
|
-
return this.setTime(
|
|
41
|
-
this.getTime() + (amount * 3600000),
|
|
42
|
-
);
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Add a minute to the current DateTime.
|
|
47
|
-
* @return {DateTime} The DateTime object.
|
|
48
|
-
*/
|
|
49
|
-
export function addMinute() {
|
|
50
|
-
return this.addMinutes(1);
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Add minutes to the current DateTime.
|
|
55
|
-
* @param {number} amount The number of minutes to add.
|
|
56
|
-
* @return {DateTime} The DateTime object.
|
|
57
|
-
*/
|
|
58
|
-
export function addMinutes(amount) {
|
|
59
|
-
return this.setTime(
|
|
60
|
-
this.getTime() + (amount * 60000),
|
|
61
|
-
);
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Add a month to the current DateTime.
|
|
66
|
-
* @return {DateTime} The DateTime object.
|
|
67
|
-
*/
|
|
68
|
-
export function addMonth() {
|
|
69
|
-
return this.addMonths(1);
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Add months to the current DateTime.
|
|
74
|
-
* @param {number} amount The number of months to add.
|
|
75
|
-
* @return {DateTime} The DateTime object.
|
|
76
|
-
*/
|
|
77
|
-
export function addMonths(amount) {
|
|
78
|
-
return this.setMonth(
|
|
79
|
-
this.getMonth() + amount,
|
|
80
|
-
);
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Add a second to the current DateTime.
|
|
85
|
-
* @return {DateTime} The DateTime object.
|
|
86
|
-
*/
|
|
87
|
-
export function addSecond() {
|
|
88
|
-
return this.addSeconds(1);
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Add seconds to the current DateTime.
|
|
93
|
-
* @param {number} amount The number of seconds to add.
|
|
94
|
-
* @return {DateTime} The DateTime object.
|
|
95
|
-
*/
|
|
96
|
-
export function addSeconds(amount) {
|
|
97
|
-
return this.setTime(
|
|
98
|
-
this.getTime() + (amount * 1000),
|
|
99
|
-
);
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Add a week to the current DateTime.
|
|
104
|
-
* @return {DateTime} The DateTime object.
|
|
105
|
-
*/
|
|
106
|
-
export function addWeek() {
|
|
107
|
-
return this.addWeeks(1);
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Add weeks to the current DateTime.
|
|
112
|
-
* @param {number} amount The number of weeks to add.
|
|
113
|
-
* @return {DateTime} The DateTime object.
|
|
114
|
-
*/
|
|
115
|
-
export function addWeeks(amount) {
|
|
116
|
-
return this.setDate(
|
|
117
|
-
this.getDate() + (amount * 7),
|
|
118
|
-
);
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Add a year to the current DateTime.
|
|
123
|
-
* @return {DateTime} The DateTime object.
|
|
124
|
-
*/
|
|
125
|
-
export function addYear() {
|
|
126
|
-
return this.addYears(1);
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Add years to the current DateTime.
|
|
131
|
-
* @param {number} amount The number of years to add.
|
|
132
|
-
* @return {DateTime} The DateTime object.
|
|
133
|
-
*/
|
|
134
|
-
export function addYears(amount) {
|
|
135
|
-
return this.setYear(
|
|
136
|
-
this.getYear() + amount,
|
|
137
|
-
);
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Set the DateTime to the end of the day.
|
|
142
|
-
* @return {DateTime} The DateTime object.
|
|
143
|
-
*/
|
|
144
|
-
export function endOfDay() {
|
|
145
|
-
return this.setHours(23, 59, 59, 999);
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Set the DateTime to the end of the hour.
|
|
150
|
-
* @return {DateTime} The DateTime object.
|
|
151
|
-
*/
|
|
152
|
-
export function endOfHour() {
|
|
153
|
-
return this.setMinutes(59, 59, 999);
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Set the DateTime to the end of the minute.
|
|
158
|
-
* @return {DateTime} The DateTime object.
|
|
159
|
-
*/
|
|
160
|
-
export function endOfMinute() {
|
|
161
|
-
return this.setSeconds(59, 999);
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Set the DateTime to the end of the month.
|
|
166
|
-
* @return {DateTime} The DateTime object.
|
|
167
|
-
*/
|
|
168
|
-
export function endOfMonth() {
|
|
169
|
-
return this.setDate(this.daysInMonth())
|
|
170
|
-
.endOfDay();
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* Set the DateTime to the end of the quarter.
|
|
175
|
-
* @return {DateTime} The DateTime object.
|
|
176
|
-
*/
|
|
177
|
-
export function endOfQuarter() {
|
|
178
|
-
const month = this.getQuarter() * 3;
|
|
179
|
-
return this.setMonth(month, daysInMonth(this.getYear(), month))
|
|
180
|
-
.endOfDay();
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Set the DateTime to the end of the second.
|
|
185
|
-
* @return {DateTime} The DateTime object.
|
|
186
|
-
*/
|
|
187
|
-
export function endOfSecond() {
|
|
188
|
-
return this.setMilliseconds(999);
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* Set the DateTime to the end of the week.
|
|
193
|
-
* @return {DateTime} The DateTime object.
|
|
194
|
-
*/
|
|
195
|
-
export function endOfWeek() {
|
|
196
|
-
return this.setWeekDay(7)
|
|
197
|
-
.endOfDay();
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* Set the DateTime to the end of the year.
|
|
202
|
-
* @return {DateTime} The DateTime object.
|
|
203
|
-
*/
|
|
204
|
-
export function endOfYear() {
|
|
205
|
-
return this.setMonth(12, 31)
|
|
206
|
-
.endOfDay();
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* Set the DateTime to the start of the day.
|
|
211
|
-
* @return {DateTime} The DateTime object.
|
|
212
|
-
*/
|
|
213
|
-
export function startOfDay() {
|
|
214
|
-
return this.setHours(0, 0, 0, 0);
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Set the DateTime to the start of the hour.
|
|
219
|
-
* @return {DateTime} The DateTime object.
|
|
220
|
-
*/
|
|
221
|
-
export function startOfHour() {
|
|
222
|
-
return this.setMinutes(0, 0, 0);
|
|
223
|
-
};
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Set the DateTime to the start of the minute.
|
|
227
|
-
* @return {DateTime} The DateTime object.
|
|
228
|
-
*/
|
|
229
|
-
export function startOfMinute() {
|
|
230
|
-
return this.setSeconds(0, 0);
|
|
231
|
-
};
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* Set the DateTime to the start of the month.
|
|
235
|
-
* @return {DateTime} The DateTime object.
|
|
236
|
-
*/
|
|
237
|
-
export function startOfMonth() {
|
|
238
|
-
return this.setDate(1)
|
|
239
|
-
.startOfDay();
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Set the DateTime to the start of the quarter.
|
|
244
|
-
* @return {DateTime} The DateTime object.
|
|
245
|
-
*/
|
|
246
|
-
export function startOfQuarter() {
|
|
247
|
-
const month = this.getQuarter() * 3 - 2;
|
|
248
|
-
return this.setMonth(month, 1)
|
|
249
|
-
.startOfDay();
|
|
250
|
-
};
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* Set the DateTime to the start of the second.
|
|
254
|
-
* @return {DateTime} The DateTime object.
|
|
255
|
-
*/
|
|
256
|
-
export function startOfSecond() {
|
|
257
|
-
return this.setMilliseconds(0);
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* Set the DateTime to the start of the week.
|
|
262
|
-
* @return {DateTime} The DateTime object.
|
|
263
|
-
*/
|
|
264
|
-
export function startOfWeek() {
|
|
265
|
-
return this.setWeekDay(1)
|
|
266
|
-
.startOfDay();
|
|
267
|
-
};
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
* Set the DateTime to the start of the year.
|
|
271
|
-
* @return {DateTime} The DateTime object.
|
|
272
|
-
*/
|
|
273
|
-
export function startOfYear() {
|
|
274
|
-
return this.setMonth(1, 1)
|
|
275
|
-
.startOfDay();
|
|
276
|
-
};
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* Subtract a day from the current DateTime.
|
|
280
|
-
* @return {DateTime} The DateTime object.
|
|
281
|
-
*/
|
|
282
|
-
export function subDay() {
|
|
283
|
-
return this.addDays(-1);
|
|
284
|
-
};
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* Subtract days from the current DateTime.
|
|
288
|
-
* @param {number} amount The number of days to subtract.
|
|
289
|
-
* @return {DateTime} The DateTime object.
|
|
290
|
-
*/
|
|
291
|
-
export function subDays(amount) {
|
|
292
|
-
return this.addDays(-amount);
|
|
293
|
-
};
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
* Subtract an hour from the current DateTime.
|
|
297
|
-
* @return {DateTime} The DateTime object.
|
|
298
|
-
*/
|
|
299
|
-
export function subHour() {
|
|
300
|
-
return this.addHours(-1);
|
|
301
|
-
};
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* Subtract hours from the current DateTime.
|
|
305
|
-
* @param {number} amount The number of hours to subtract.
|
|
306
|
-
* @return {DateTime} The DateTime object.
|
|
307
|
-
*/
|
|
308
|
-
export function subHours(amount) {
|
|
309
|
-
return this.addHours(-amount);
|
|
310
|
-
};
|
|
311
|
-
|
|
312
|
-
/**
|
|
313
|
-
* Subtract a minute from the current DateTime.
|
|
314
|
-
* @return {DateTime} The DateTime object.
|
|
315
|
-
*/
|
|
316
|
-
export function subMinute() {
|
|
317
|
-
return this.addMinutes(-1);
|
|
318
|
-
};
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
* Subtract minutes from the current DateTime.
|
|
322
|
-
* @param {number} amount The number of minutes to subtract.
|
|
323
|
-
* @return {DateTime} The DateTime object.
|
|
324
|
-
*/
|
|
325
|
-
export function subMinutes(amount) {
|
|
326
|
-
return this.addMinutes(-amount);
|
|
327
|
-
};
|
|
328
|
-
|
|
329
|
-
/**
|
|
330
|
-
* Subtract a month from the current DateTime.
|
|
331
|
-
* @return {DateTime} The DateTime object.
|
|
332
|
-
*/
|
|
333
|
-
export function subMonth() {
|
|
334
|
-
return this.addMonths(-1);
|
|
335
|
-
};
|
|
336
|
-
|
|
337
|
-
/**
|
|
338
|
-
* Subtract months from the current DateTime.
|
|
339
|
-
* @param {number} amount The number of months to subtract.
|
|
340
|
-
* @return {DateTime} The DateTime object.
|
|
341
|
-
*/
|
|
342
|
-
export function subMonths(amount) {
|
|
343
|
-
return this.addMonths(-amount);
|
|
344
|
-
};
|
|
345
|
-
|
|
346
|
-
/**
|
|
347
|
-
* Subtract a second from the current DateTime.
|
|
348
|
-
* @return {DateTime} The DateTime object.
|
|
349
|
-
*/
|
|
350
|
-
export function subSecond() {
|
|
351
|
-
return this.addSeconds(-1);
|
|
352
|
-
};
|
|
353
|
-
|
|
354
|
-
/**
|
|
355
|
-
* Subtract seconds from the current DateTime.
|
|
356
|
-
* @param {number} amount The number of seconds to subtract.
|
|
357
|
-
* @return {DateTime} The DateTime object.
|
|
358
|
-
*/
|
|
359
|
-
export function subSeconds(amount) {
|
|
360
|
-
return this.addSeconds(-amount);
|
|
361
|
-
};
|
|
362
|
-
|
|
363
|
-
/**
|
|
364
|
-
* Subtract a week from the current DateTime.
|
|
365
|
-
* @return {DateTime} The DateTime object.
|
|
366
|
-
*/
|
|
367
|
-
export function subWeek() {
|
|
368
|
-
return this.addWeeks(-1);
|
|
369
|
-
};
|
|
370
|
-
|
|
371
|
-
/**
|
|
372
|
-
* Subtract weeks from the current DateTime.
|
|
373
|
-
* @param {number} amount The number of weeks to subtract.
|
|
374
|
-
* @return {DateTime} The DateTime object.
|
|
375
|
-
*/
|
|
376
|
-
export function subWeeks(amount) {
|
|
377
|
-
return this.addWeeks(-amount);
|
|
378
|
-
};
|
|
379
|
-
|
|
380
|
-
/**
|
|
381
|
-
* Subtract a year from the current DateTime.
|
|
382
|
-
* @return {DateTime} The DateTime object.
|
|
383
|
-
*/
|
|
384
|
-
export function subYear() {
|
|
385
|
-
return this.addYears(-1);
|
|
386
|
-
};
|
|
387
|
-
|
|
388
|
-
/**
|
|
389
|
-
* Subtract years from the current DateTime.
|
|
390
|
-
* @param {number} amount The number of years to subtract.
|
|
391
|
-
* @return {DateTime} The DateTime object.
|
|
392
|
-
*/
|
|
393
|
-
export function subYears(amount) {
|
|
394
|
-
return this.addYears(-amount);
|
|
395
|
-
};
|
package/src/prototype/output.js
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { formats, formatTokenRegExp } from './../vars.js';
|
|
2
|
-
import tokens from './../formatter/tokens.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* DateTime Output
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Format the current date using a format string.
|
|
10
|
-
* @param {string} formatString The format string.
|
|
11
|
-
* @return {string} The formatted date string.
|
|
12
|
-
*/
|
|
13
|
-
export function format(formatString) {
|
|
14
|
-
let match;
|
|
15
|
-
let output = '';
|
|
16
|
-
|
|
17
|
-
while (formatString && (match = formatString.match(formatTokenRegExp))) {
|
|
18
|
-
const token = match[1];
|
|
19
|
-
const position = match.index;
|
|
20
|
-
const length = match[0].length;
|
|
21
|
-
|
|
22
|
-
if (position) {
|
|
23
|
-
output += formatString.substring(0, position);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
formatString = formatString.substring(position + length);
|
|
27
|
-
|
|
28
|
-
if (!token) {
|
|
29
|
-
output += match[0].slice(1, -1);
|
|
30
|
-
continue;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (!(token in tokens)) {
|
|
34
|
-
throw new Error(`Invalid token in DateTime format: ${token}`);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
output += tokens[token].output(this, length);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
output += formatString;
|
|
41
|
-
|
|
42
|
-
return output;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Format the current date using "eee MMM dd yyyy".
|
|
47
|
-
* @return {string} The formatted date string.
|
|
48
|
-
*/
|
|
49
|
-
export function toDateString() {
|
|
50
|
-
return this.format(formats.date);
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Format the current date using "yyyy-MM-dd'THH:mm:ss.SSSSSSxxx".
|
|
55
|
-
* @return {string} The formatted date string.
|
|
56
|
-
*/
|
|
57
|
-
export function toISOString() {
|
|
58
|
-
return this
|
|
59
|
-
.setLocale('en')
|
|
60
|
-
.setTimeZone('UTC')
|
|
61
|
-
.format(formats.rfc3339_extended);
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Format the current date using "eee MMM dd yyyy HH:mm:ss xx (VV)".
|
|
66
|
-
* @return {string} The formatted date string.
|
|
67
|
-
*/
|
|
68
|
-
export function toString() {
|
|
69
|
-
return this.format(formats.string);
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Format the current date using "HH:mm:ss xx (VV)".
|
|
74
|
-
* @return {string} The formatted date string.
|
|
75
|
-
*/
|
|
76
|
-
export function toTimeString() {
|
|
77
|
-
return this.format(formats.time);
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Format the current date in UTC timeZone using "eee MMM dd yyyy HH:mm:ss xx (VV)".
|
|
82
|
-
* @return {string} The formatted date string.
|
|
83
|
-
*/
|
|
84
|
-
export function toUTCString() {
|
|
85
|
-
return this
|
|
86
|
-
.setLocale('en')
|
|
87
|
-
.setTimeZone('UTC')
|
|
88
|
-
.toString();
|
|
89
|
-
};
|
package/src/prototype/utility.js
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import DateTime from './../date-time.js';
|
|
2
|
-
import { formatDay, formatDayPeriod, formatEra, formatMonth, formatOffset, formatTimeZoneName } from './../formatter/format.js';
|
|
3
|
-
import { minimumDays } from './../formatter/utility.js';
|
|
4
|
-
import { daysInMonth as _daysInMonth, daysInYear as _daysInYear, isLeapYear as _isLeapYear } from './../static/utility.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* DateTime Utility
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Get the name of the day of the week in current timeZone.
|
|
12
|
-
* @param {string} [type=long] The type of day name to return.
|
|
13
|
-
* @return {string} The name of the day of the week.
|
|
14
|
-
*/
|
|
15
|
-
export function dayName(type = 'long') {
|
|
16
|
-
return formatDay(this.getLocale(), this.getDay(), type);
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Get the day period in current timeZone.
|
|
21
|
-
* @param {string} [type=long] The type of day period to return.
|
|
22
|
-
* @return {string} The day period.
|
|
23
|
-
*/
|
|
24
|
-
export function dayPeriod(type = 'long') {
|
|
25
|
-
return formatDayPeriod(
|
|
26
|
-
this.getLocale(),
|
|
27
|
-
this.getHours() < 12 ?
|
|
28
|
-
0 :
|
|
29
|
-
1,
|
|
30
|
-
type,
|
|
31
|
-
);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Get the number of days in the current month.
|
|
36
|
-
* @return {number} The number of days in the current month.
|
|
37
|
-
*/
|
|
38
|
-
export function daysInMonth() {
|
|
39
|
-
return _daysInMonth(
|
|
40
|
-
this.getYear(),
|
|
41
|
-
this.getMonth(),
|
|
42
|
-
);
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Get the number of days in the current year.
|
|
47
|
-
* @return {number} The number of days in the current year.
|
|
48
|
-
*/
|
|
49
|
-
export function daysInYear() {
|
|
50
|
-
return _daysInYear(
|
|
51
|
-
this.getYear(),
|
|
52
|
-
);
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Get the era in current timeZone.
|
|
57
|
-
* @param {string} [type=long] The type of era to return.
|
|
58
|
-
* @return {string} The era.
|
|
59
|
-
*/
|
|
60
|
-
export function era(type = 'long') {
|
|
61
|
-
return formatEra(
|
|
62
|
-
this.getLocale(),
|
|
63
|
-
this.getYear() < 0 ?
|
|
64
|
-
0 :
|
|
65
|
-
1,
|
|
66
|
-
type,
|
|
67
|
-
);
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Return true if the DateTime is in daylight savings.
|
|
72
|
-
* @return {Boolean} TRUE if the current time is in daylight savings, otherwise FALSE.
|
|
73
|
-
*/
|
|
74
|
-
export function isDST() {
|
|
75
|
-
if (!this._dynamicTz) {
|
|
76
|
-
return false;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const year = this.getYear();
|
|
80
|
-
const dateA = DateTime.fromArray([year, 1, 1], {
|
|
81
|
-
timeZone: this.getTimeZone(),
|
|
82
|
-
});
|
|
83
|
-
const dateB = DateTime.fromArray([year, 6, 1], {
|
|
84
|
-
timeZone: this.getTimeZone(),
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
return this.getTimeZoneOffset() < Math.max(dateA.getTimeZoneOffset(), dateB.getTimeZoneOffset());
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Return true if the year is a leap year.
|
|
92
|
-
* @return {Boolean} TRUE if the current year is a leap year, otherwise FALSE.
|
|
93
|
-
*/
|
|
94
|
-
export function isLeapYear() {
|
|
95
|
-
return _isLeapYear(
|
|
96
|
-
this.getYear(),
|
|
97
|
-
);
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Get the name of the month in current timeZone.
|
|
102
|
-
* @param {string} [type=long] The type of month name to return.
|
|
103
|
-
* @return {string} The name of the month.
|
|
104
|
-
*/
|
|
105
|
-
export function monthName(type = 'long') {
|
|
106
|
-
return formatMonth(this.getLocale(), this.getMonth(), type);
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Get the name of the current timeZone.
|
|
111
|
-
* @param {string} [type=long] The formatting type.
|
|
112
|
-
* @return {string} The name of the time zone.
|
|
113
|
-
*/
|
|
114
|
-
export function timeZoneName(type = 'long') {
|
|
115
|
-
return this._dynamicTz ?
|
|
116
|
-
formatTimeZoneName(this.getLocale(), this.getTime(), this.getTimeZone(), type) :
|
|
117
|
-
'GMT' + formatOffset(this.getTimeZoneOffset(), true, type === 'short');
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Get the number of weeks in the current year.
|
|
122
|
-
* @return {number} The number of weeks in the current year.
|
|
123
|
-
*/
|
|
124
|
-
export function weeksInYear() {
|
|
125
|
-
const minDays = minimumDays(this.getLocale());
|
|
126
|
-
return this.setMonth(12, 24 + minDays).getWeek();
|
|
127
|
-
};
|