@fr0st/datetime 5.1.6 → 6.0.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.
- package/README.md +1001 -103
- package/dist/frost-datetime.js +1231 -433
- package/dist/frost-datetime.js.map +1 -1
- package/dist/frost-datetime.min.js +1 -1
- package/dist/frost-datetime.min.js.map +1 -1
- package/package.json +9 -9
- package/src/formatter/format.js +18 -1
- package/src/helpers.js +100 -56
- package/src/index.js +103 -6
- package/src/prototype/attributes-get.js +1 -1
- package/src/prototype/comparisons.js +605 -0
- package/src/prototype/manipulate.js +368 -69
- package/src/prototype/utility.js +0 -227
- package/src/vars.js +10 -0
package/dist/frost-datetime.js
CHANGED
|
@@ -113,6 +113,16 @@
|
|
|
113
113
|
['minutes', 'seconds', 'milliseconds'],
|
|
114
114
|
];
|
|
115
115
|
|
|
116
|
+
const diffMethods = {
|
|
117
|
+
year: 'diffInYears',
|
|
118
|
+
month: 'diffInMonths',
|
|
119
|
+
week: 'diffInWeeks',
|
|
120
|
+
day: 'diffInDays',
|
|
121
|
+
hour: 'diffInHours',
|
|
122
|
+
minute: 'diffInMinutes',
|
|
123
|
+
second: 'diffInSeconds',
|
|
124
|
+
};
|
|
125
|
+
|
|
116
126
|
const thresholds = {
|
|
117
127
|
month: 12,
|
|
118
128
|
week: null,
|
|
@@ -126,6 +136,98 @@
|
|
|
126
136
|
* DateTime Helpers
|
|
127
137
|
*/
|
|
128
138
|
|
|
139
|
+
function calculateDiff(date, other, timeUnit, relative = true) {
|
|
140
|
+
other = other.setTimeZone(date.getTimeZone());
|
|
141
|
+
|
|
142
|
+
switch (timeUnit) {
|
|
143
|
+
case 'year':
|
|
144
|
+
return compensateDiff(
|
|
145
|
+
date,
|
|
146
|
+
other.setYear(
|
|
147
|
+
date.getYear(),
|
|
148
|
+
),
|
|
149
|
+
date.getYear() - other.getYear(),
|
|
150
|
+
!relative,
|
|
151
|
+
-1,
|
|
152
|
+
);
|
|
153
|
+
case 'month':
|
|
154
|
+
return compensateDiff(
|
|
155
|
+
date,
|
|
156
|
+
other.setYear(
|
|
157
|
+
date.getYear(),
|
|
158
|
+
date.getMonth(),
|
|
159
|
+
),
|
|
160
|
+
(date.getYear() - other.getYear()) * 12 + date.getMonth() - other.getMonth(),
|
|
161
|
+
!relative,
|
|
162
|
+
-1,
|
|
163
|
+
);
|
|
164
|
+
case 'week':
|
|
165
|
+
return compensateDiff(
|
|
166
|
+
date,
|
|
167
|
+
other.setWeekYear(
|
|
168
|
+
date.getWeekYear(),
|
|
169
|
+
date.getWeek(),
|
|
170
|
+
),
|
|
171
|
+
(date - other) / 604800000,
|
|
172
|
+
relative,
|
|
173
|
+
);
|
|
174
|
+
case 'day':
|
|
175
|
+
return compensateDiff(
|
|
176
|
+
date,
|
|
177
|
+
other.setYear(
|
|
178
|
+
date.getYear(),
|
|
179
|
+
date.getMonth(),
|
|
180
|
+
date.getDate(),
|
|
181
|
+
),
|
|
182
|
+
(date - other) / 86400000,
|
|
183
|
+
relative,
|
|
184
|
+
);
|
|
185
|
+
case 'hour':
|
|
186
|
+
return compensateDiff(
|
|
187
|
+
date,
|
|
188
|
+
other.setYear(
|
|
189
|
+
date.getYear(),
|
|
190
|
+
date.getMonth(),
|
|
191
|
+
date.getDate(),
|
|
192
|
+
).setHours(
|
|
193
|
+
date.getHours(),
|
|
194
|
+
),
|
|
195
|
+
(date - other) / 3600000,
|
|
196
|
+
relative,
|
|
197
|
+
);
|
|
198
|
+
case 'minute':
|
|
199
|
+
return compensateDiff(
|
|
200
|
+
date,
|
|
201
|
+
other.setYear(
|
|
202
|
+
date.getYear(),
|
|
203
|
+
date.getMonth(),
|
|
204
|
+
date.getDate(),
|
|
205
|
+
).setHours(
|
|
206
|
+
date.getHours(),
|
|
207
|
+
date.getMinutes(),
|
|
208
|
+
),
|
|
209
|
+
(date - other) / 60000,
|
|
210
|
+
relative,
|
|
211
|
+
);
|
|
212
|
+
case 'second':
|
|
213
|
+
return compensateDiff(
|
|
214
|
+
date,
|
|
215
|
+
other.setYear(
|
|
216
|
+
date.getYear(),
|
|
217
|
+
date.getMonth(),
|
|
218
|
+
date.getDate(),
|
|
219
|
+
).setHours(
|
|
220
|
+
date.getHours(),
|
|
221
|
+
date.getMinutes(),
|
|
222
|
+
date.getSeconds(),
|
|
223
|
+
),
|
|
224
|
+
(date - other) / 1000,
|
|
225
|
+
relative,
|
|
226
|
+
);
|
|
227
|
+
default:
|
|
228
|
+
throw new Error('Invalid time unit supplied');
|
|
229
|
+
}
|
|
230
|
+
}
|
|
129
231
|
/**
|
|
130
232
|
* Compensate the difference between two dates.
|
|
131
233
|
* @param {DateTime} date The DateTime.
|
|
@@ -160,13 +262,15 @@
|
|
|
160
262
|
*/
|
|
161
263
|
function getBiggestDiff(date, other) {
|
|
162
264
|
let lastResult;
|
|
163
|
-
for (const timeUnit
|
|
164
|
-
const relativeDiff = date
|
|
265
|
+
for (const [timeUnit, diffMethod] of Object.entries(diffMethods)) {
|
|
266
|
+
const relativeDiff = date[diffMethod](other);
|
|
267
|
+
|
|
165
268
|
if (lastResult && thresholds[timeUnit] && Math.abs(relativeDiff) >= thresholds[timeUnit]) {
|
|
166
269
|
return lastResult;
|
|
167
270
|
}
|
|
168
271
|
|
|
169
|
-
const actualDiff = date
|
|
272
|
+
const actualDiff = date[diffMethod](other, { relative: false });
|
|
273
|
+
|
|
170
274
|
if (actualDiff) {
|
|
171
275
|
return [relativeDiff, timeUnit];
|
|
172
276
|
}
|
|
@@ -207,56 +311,6 @@
|
|
|
207
311
|
function getOffsetTime(date) {
|
|
208
312
|
return date.getTime() - (date.getTimeZoneOffset() * 60000);
|
|
209
313
|
}
|
|
210
|
-
/**
|
|
211
|
-
* Modify a DateTime by a duration.
|
|
212
|
-
* @param {DateTime} date The DateTime.
|
|
213
|
-
* @param {number} amount The amount to modify the date by.
|
|
214
|
-
* @param {string} [timeUnit] The unit of time.
|
|
215
|
-
* @return {DateTime} The DateTime object.
|
|
216
|
-
*/
|
|
217
|
-
function modify(date, amount, timeUnit) {
|
|
218
|
-
timeUnit = timeUnit.toLowerCase();
|
|
219
|
-
|
|
220
|
-
switch (timeUnit) {
|
|
221
|
-
case 'second':
|
|
222
|
-
case 'seconds':
|
|
223
|
-
return date.setTime(
|
|
224
|
-
date.getTime() + (amount * 1000),
|
|
225
|
-
);
|
|
226
|
-
case 'minute':
|
|
227
|
-
case 'minutes':
|
|
228
|
-
return date.setTime(
|
|
229
|
-
date.getTime() + (amount * 60000),
|
|
230
|
-
);
|
|
231
|
-
case 'hour':
|
|
232
|
-
case 'hours':
|
|
233
|
-
return date.setTime(
|
|
234
|
-
date.getTime() + (amount * 3600000),
|
|
235
|
-
);
|
|
236
|
-
case 'week':
|
|
237
|
-
case 'weeks':
|
|
238
|
-
return date.setDate(
|
|
239
|
-
date.getDate() + (amount * 7),
|
|
240
|
-
);
|
|
241
|
-
case 'day':
|
|
242
|
-
case 'days':
|
|
243
|
-
return date.setDate(
|
|
244
|
-
date.getDate() + amount,
|
|
245
|
-
);
|
|
246
|
-
case 'month':
|
|
247
|
-
case 'months':
|
|
248
|
-
return date.setMonth(
|
|
249
|
-
date.getMonth() + amount,
|
|
250
|
-
);
|
|
251
|
-
case 'year':
|
|
252
|
-
case 'years':
|
|
253
|
-
return date.setYear(
|
|
254
|
-
date.getYear() + amount,
|
|
255
|
-
);
|
|
256
|
-
default:
|
|
257
|
-
throw new Error('Invalid time unit supplied');
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
314
|
/**
|
|
261
315
|
* Compare a literal format string with a date string.
|
|
262
316
|
* @param {string} formatString The literal format string.
|
|
@@ -614,6 +668,22 @@
|
|
|
614
668
|
|
|
615
669
|
return `${sign}${hourString}${colon}${minuteString}`;
|
|
616
670
|
}
|
|
671
|
+
/**
|
|
672
|
+
* Format a relative duration as a locale string.
|
|
673
|
+
* @param {string} locale The locale.
|
|
674
|
+
* @param {number} amount The amount of duration.
|
|
675
|
+
* @param {string} unit The time unit.
|
|
676
|
+
* @returns {string} The relative duration.
|
|
677
|
+
*/
|
|
678
|
+
function formatRelative(locale, amount, unit) {
|
|
679
|
+
const relativeFormatter = getRelativeFormatter(locale);
|
|
680
|
+
|
|
681
|
+
if (!relativeFormatter) {
|
|
682
|
+
throw new Error('RelativeTimeFormat not supported');
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
return relativeFormatter.format(amount, unit);
|
|
686
|
+
}
|
|
617
687
|
/**
|
|
618
688
|
* Format a time zone as a locale string.
|
|
619
689
|
* @param {string} locale The locale.
|
|
@@ -2021,7 +2091,7 @@
|
|
|
2021
2091
|
* @return {number} The local week. (1, 53)
|
|
2022
2092
|
*/
|
|
2023
2093
|
function getWeek() {
|
|
2024
|
-
const thisWeek = this.
|
|
2094
|
+
const thisWeek = this.startOfDay().setWeekDay(1);
|
|
2025
2095
|
const firstWeek = thisWeek.setWeek(1, 1);
|
|
2026
2096
|
|
|
2027
2097
|
return 1 +
|
|
@@ -2345,423 +2415,1085 @@
|
|
|
2345
2415
|
}
|
|
2346
2416
|
|
|
2347
2417
|
/**
|
|
2348
|
-
* DateTime
|
|
2418
|
+
* DateTime Comparisons
|
|
2349
2419
|
*/
|
|
2350
2420
|
|
|
2351
2421
|
/**
|
|
2352
|
-
*
|
|
2353
|
-
* @param {
|
|
2354
|
-
* @
|
|
2355
|
-
* @return {DateTime} The DateTime object.
|
|
2422
|
+
* Get the difference between this and another Date in milliseconds.
|
|
2423
|
+
* @param {DateTime} other The date to compare to.
|
|
2424
|
+
* @return {number} The difference.
|
|
2356
2425
|
*/
|
|
2357
|
-
function
|
|
2358
|
-
return
|
|
2426
|
+
function diff(other) {
|
|
2427
|
+
return this - other;
|
|
2359
2428
|
}
|
|
2360
2429
|
/**
|
|
2361
|
-
*
|
|
2362
|
-
* @param {
|
|
2363
|
-
* @
|
|
2430
|
+
* Get the difference between this and another Date in days.
|
|
2431
|
+
* @param {DateTime} other The date to compare to.
|
|
2432
|
+
* @param {object} [options] The options for comparing the dates.
|
|
2433
|
+
* @param {Boolean} [options.relative=true] Whether to use the relative difference.
|
|
2434
|
+
* @return {number} The difference.
|
|
2364
2435
|
*/
|
|
2365
|
-
function
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
switch (timeUnit) {
|
|
2369
|
-
case 'second':
|
|
2370
|
-
return this.setMilliseconds(999);
|
|
2371
|
-
case 'minute':
|
|
2372
|
-
return this.setSeconds(59, 999);
|
|
2373
|
-
case 'hour':
|
|
2374
|
-
return this.setMinutes(59, 59, 999);
|
|
2375
|
-
case 'day':
|
|
2376
|
-
return this.setHours(23, 59, 59, 999);
|
|
2377
|
-
case 'week':
|
|
2378
|
-
return this.setWeekDay(7)
|
|
2379
|
-
.setHours(23, 59, 59, 999);
|
|
2380
|
-
case 'month':
|
|
2381
|
-
return this.setDate(this.daysInMonth())
|
|
2382
|
-
.setHours(23, 59, 59, 999);
|
|
2383
|
-
case 'quarter':
|
|
2384
|
-
const month = this.getQuarter() * 3;
|
|
2385
|
-
return this.setMonth(month, daysInMonth$1(this.getYear(), month))
|
|
2386
|
-
.setHours(23, 59, 59, 999);
|
|
2387
|
-
case 'year':
|
|
2388
|
-
return this.setMonth(12, 31)
|
|
2389
|
-
.setHours(23, 59, 59, 999);
|
|
2390
|
-
default:
|
|
2391
|
-
throw new Error('Invalid time unit supplied');
|
|
2392
|
-
}
|
|
2436
|
+
function diffInDays(other, { relative = true } = {}) {
|
|
2437
|
+
return calculateDiff(this, other, 'day', relative);
|
|
2393
2438
|
}
|
|
2394
2439
|
/**
|
|
2395
|
-
*
|
|
2396
|
-
* @param {
|
|
2397
|
-
* @
|
|
2440
|
+
* Get the difference between this and another Date in hours.
|
|
2441
|
+
* @param {DateTime} other The date to compare to.
|
|
2442
|
+
* @param {object} [options] The options for comparing the dates.
|
|
2443
|
+
* @param {Boolean} [options.relative=true] Whether to use the relative difference.
|
|
2444
|
+
* @return {number} The difference.
|
|
2398
2445
|
*/
|
|
2399
|
-
function
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
switch (timeUnit) {
|
|
2403
|
-
case 'second':
|
|
2404
|
-
return this.setMilliseconds(0);
|
|
2405
|
-
case 'minute':
|
|
2406
|
-
return this.setSeconds(0, 0);
|
|
2407
|
-
case 'hour':
|
|
2408
|
-
return this.setMinutes(0, 0, 0);
|
|
2409
|
-
case 'day':
|
|
2410
|
-
return this.setHours(0, 0, 0, 0);
|
|
2411
|
-
case 'week':
|
|
2412
|
-
return this.setWeekDay(1)
|
|
2413
|
-
.setHours(0, 0, 0, 0);
|
|
2414
|
-
case 'month':
|
|
2415
|
-
return this.setDate(1)
|
|
2416
|
-
.setHours(0, 0, 0, 0);
|
|
2417
|
-
case 'quarter':
|
|
2418
|
-
const month = this.getQuarter() * 3 - 2;
|
|
2419
|
-
return this.setMonth(month, 1)
|
|
2420
|
-
.setHours(0, 0, 0, 0);
|
|
2421
|
-
case 'year':
|
|
2422
|
-
return this.setMonth(1, 1)
|
|
2423
|
-
.setHours(0, 0, 0, 0);
|
|
2424
|
-
default:
|
|
2425
|
-
throw new Error('Invalid time unit supplied');
|
|
2426
|
-
}
|
|
2446
|
+
function diffInHours(other, { relative = true } = {}) {
|
|
2447
|
+
return calculateDiff(this, other, 'hour', relative);
|
|
2427
2448
|
}
|
|
2428
2449
|
/**
|
|
2429
|
-
*
|
|
2430
|
-
* @param {
|
|
2431
|
-
* @param {
|
|
2432
|
-
* @
|
|
2450
|
+
* Get the difference between this and another Date in minutes.
|
|
2451
|
+
* @param {DateTime} other The date to compare to.
|
|
2452
|
+
* @param {object} [options] The options for comparing the dates.
|
|
2453
|
+
* @param {Boolean} [options.relative=true] Whether to use the relative difference.
|
|
2454
|
+
* @return {number} The difference.
|
|
2433
2455
|
*/
|
|
2434
|
-
function
|
|
2435
|
-
return
|
|
2456
|
+
function diffInMinutes(other, { relative = true } = {}) {
|
|
2457
|
+
return calculateDiff(this, other, 'minute', relative);
|
|
2436
2458
|
}
|
|
2437
|
-
|
|
2438
2459
|
/**
|
|
2439
|
-
*
|
|
2460
|
+
* Get the difference between this and another Date in months.
|
|
2461
|
+
* @param {DateTime} other The date to compare to.
|
|
2462
|
+
* @param {object} [options] The options for comparing the dates.
|
|
2463
|
+
* @param {Boolean} [options.relative=true] Whether to use the relative difference.
|
|
2464
|
+
* @return {number} The difference.
|
|
2440
2465
|
*/
|
|
2441
|
-
|
|
2466
|
+
function diffInMonths(other, { relative = true } = {}) {
|
|
2467
|
+
return calculateDiff(this, other, 'month', relative);
|
|
2468
|
+
}
|
|
2442
2469
|
/**
|
|
2443
|
-
*
|
|
2444
|
-
* @param {
|
|
2445
|
-
* @
|
|
2470
|
+
* Get the difference between this and another Date in seconds.
|
|
2471
|
+
* @param {DateTime} other The date to compare to.
|
|
2472
|
+
* @param {object} [options] The options for comparing the dates.
|
|
2473
|
+
* @param {Boolean} [options.relative=true] Whether to use the relative difference.
|
|
2474
|
+
* @return {number} The difference.
|
|
2446
2475
|
*/
|
|
2447
|
-
function
|
|
2448
|
-
|
|
2449
|
-
let output = '';
|
|
2450
|
-
|
|
2451
|
-
while (formatString && (match = formatString.match(formatTokenRegExp))) {
|
|
2452
|
-
const token = match[1];
|
|
2453
|
-
const position = match.index;
|
|
2454
|
-
const length = match[0].length;
|
|
2455
|
-
|
|
2456
|
-
if (position) {
|
|
2457
|
-
output += formatString.substring(0, position);
|
|
2458
|
-
}
|
|
2459
|
-
|
|
2460
|
-
formatString = formatString.substring(position + length);
|
|
2461
|
-
|
|
2462
|
-
if (!token) {
|
|
2463
|
-
output += match[0].slice(1, -1);
|
|
2464
|
-
continue;
|
|
2465
|
-
}
|
|
2466
|
-
|
|
2467
|
-
if (!(token in tokens)) {
|
|
2468
|
-
throw new Error(`Invalid token in DateTime format: ${token}`);
|
|
2469
|
-
}
|
|
2470
|
-
|
|
2471
|
-
output += tokens[token].output(this, length);
|
|
2472
|
-
}
|
|
2473
|
-
|
|
2474
|
-
output += formatString;
|
|
2475
|
-
|
|
2476
|
-
return output;
|
|
2476
|
+
function diffInSeconds(other, { relative = true } = {}) {
|
|
2477
|
+
return calculateDiff(this, other, 'second', relative);
|
|
2477
2478
|
}
|
|
2478
2479
|
/**
|
|
2479
|
-
*
|
|
2480
|
-
* @
|
|
2480
|
+
* Get the difference between this and another Date in weeks.
|
|
2481
|
+
* @param {DateTime} other The date to compare to.
|
|
2482
|
+
* @param {object} [options] The options for comparing the dates.
|
|
2483
|
+
* @param {Boolean} [options.relative=true] Whether to use the relative difference.
|
|
2484
|
+
* @return {number} The difference.
|
|
2481
2485
|
*/
|
|
2482
|
-
function
|
|
2483
|
-
return this
|
|
2486
|
+
function diffInWeeks(other, { relative = true } = {}) {
|
|
2487
|
+
return calculateDiff(this, other, 'week', relative);
|
|
2484
2488
|
}
|
|
2485
2489
|
/**
|
|
2486
|
-
*
|
|
2487
|
-
* @
|
|
2490
|
+
* Get the difference between this and another Date in years.
|
|
2491
|
+
* @param {DateTime} other The date to compare to.
|
|
2492
|
+
* @param {object} [options] The options for comparing the dates.
|
|
2493
|
+
* @param {Boolean} [options.relative=true] Whether to use the relative difference.
|
|
2494
|
+
* @return {number} The difference.
|
|
2488
2495
|
*/
|
|
2489
|
-
function
|
|
2490
|
-
return this
|
|
2491
|
-
.setLocale('en')
|
|
2492
|
-
.setTimeZone('UTC')
|
|
2493
|
-
.format(formats.rfc3339_extended);
|
|
2496
|
+
function diffInYears(other, { relative = true } = {}) {
|
|
2497
|
+
return calculateDiff(this, other, 'year', relative);
|
|
2494
2498
|
}
|
|
2495
2499
|
/**
|
|
2496
|
-
*
|
|
2497
|
-
* @
|
|
2500
|
+
* Get the difference between this and another Date in human readable form.
|
|
2501
|
+
* @param {DateTime} other The date to compare to.
|
|
2502
|
+
* @return {string} The difference in human readable form.
|
|
2498
2503
|
*/
|
|
2499
|
-
function
|
|
2500
|
-
|
|
2504
|
+
function humanDiff(other) {
|
|
2505
|
+
const [amount, unit] = getBiggestDiff(this, other);
|
|
2506
|
+
return formatRelative(this.getLocale(), amount, unit);
|
|
2501
2507
|
}
|
|
2502
2508
|
/**
|
|
2503
|
-
*
|
|
2504
|
-
* @
|
|
2509
|
+
* Get the difference between this and another Date in days in human readable form.
|
|
2510
|
+
* @param {DateTime} other The date to compare to.
|
|
2511
|
+
* @return {string} The difference in days in human readable form.
|
|
2505
2512
|
*/
|
|
2506
|
-
function
|
|
2507
|
-
return this.
|
|
2513
|
+
function humanDiffInDays(other) {
|
|
2514
|
+
return formatRelative(this.getLocale(), this.diffInDays(other), 'day');
|
|
2508
2515
|
}
|
|
2509
2516
|
/**
|
|
2510
|
-
*
|
|
2511
|
-
* @
|
|
2517
|
+
* Get the difference between this and another Date in hours in human readable form.
|
|
2518
|
+
* @param {DateTime} other The date to compare to.
|
|
2519
|
+
* @return {string} The difference in hours in human readable form.
|
|
2512
2520
|
*/
|
|
2513
|
-
function
|
|
2514
|
-
return this
|
|
2515
|
-
.setLocale('en')
|
|
2516
|
-
.setTimeZone('UTC')
|
|
2517
|
-
.toString();
|
|
2521
|
+
function humanDiffInHours(other) {
|
|
2522
|
+
return formatRelative(this.getLocale(), this.diffInHours(other), 'hour');
|
|
2518
2523
|
}
|
|
2519
|
-
|
|
2520
2524
|
/**
|
|
2521
|
-
*
|
|
2525
|
+
* Get the difference between this and another Date in minutes in human readable form.
|
|
2526
|
+
* @param {DateTime} other The date to compare to.
|
|
2527
|
+
* @return {string} The difference in minutes in human readable form.
|
|
2522
2528
|
*/
|
|
2523
|
-
|
|
2529
|
+
function humanDiffInMinutes(other) {
|
|
2530
|
+
return formatRelative(this.getLocale(), this.diffInMinutes(other), 'minute');
|
|
2531
|
+
}
|
|
2524
2532
|
/**
|
|
2525
|
-
* Get the
|
|
2526
|
-
* @param {
|
|
2527
|
-
* @return {string} The
|
|
2533
|
+
* Get the difference between this and another Date in months in human readable form.
|
|
2534
|
+
* @param {DateTime} other The date to compare to.
|
|
2535
|
+
* @return {string} The difference in months in human readable form.
|
|
2528
2536
|
*/
|
|
2529
|
-
function
|
|
2530
|
-
return
|
|
2537
|
+
function humanDiffInMonths(other) {
|
|
2538
|
+
return formatRelative(this.getLocale(), this.diffInMonths(other), 'month');
|
|
2531
2539
|
}
|
|
2532
2540
|
/**
|
|
2533
|
-
* Get the
|
|
2534
|
-
* @param {
|
|
2535
|
-
* @return {string} The
|
|
2541
|
+
* Get the difference between this and another Date in seconds in human readable form.
|
|
2542
|
+
* @param {DateTime} other The date to compare to.
|
|
2543
|
+
* @return {string} The difference in seconds in human readable form.
|
|
2536
2544
|
*/
|
|
2537
|
-
function
|
|
2538
|
-
return
|
|
2539
|
-
this.getLocale(),
|
|
2540
|
-
this.getHours() < 12 ?
|
|
2541
|
-
0 :
|
|
2542
|
-
1,
|
|
2543
|
-
type,
|
|
2544
|
-
);
|
|
2545
|
+
function humanDiffInSeconds(other) {
|
|
2546
|
+
return formatRelative(this.getLocale(), this.diffInSeconds(other), 'second');
|
|
2545
2547
|
}
|
|
2546
2548
|
/**
|
|
2547
|
-
* Get the
|
|
2548
|
-
* @
|
|
2549
|
+
* Get the difference between this and another Date in weeks in human readable form.
|
|
2550
|
+
* @param {DateTime} other The date to compare to.
|
|
2551
|
+
* @return {string} The difference in weeks in human readable form.
|
|
2549
2552
|
*/
|
|
2550
|
-
function
|
|
2551
|
-
return
|
|
2552
|
-
this.getYear(),
|
|
2553
|
-
this.getMonth(),
|
|
2554
|
-
);
|
|
2553
|
+
function humanDiffInWeeks(other) {
|
|
2554
|
+
return formatRelative(this.getLocale(), this.diffInWeeks(other), 'week');
|
|
2555
2555
|
}
|
|
2556
2556
|
/**
|
|
2557
|
-
* Get the
|
|
2558
|
-
* @
|
|
2557
|
+
* Get the difference between this and another Date in years in human readable form.
|
|
2558
|
+
* @param {DateTime} other The date to compare to.
|
|
2559
|
+
* @return {string} The difference in years in human readable form.
|
|
2560
|
+
*/
|
|
2561
|
+
function humanDiffInYears(other) {
|
|
2562
|
+
return formatRelative(this.getLocale(), this.diffInYears(other), 'year');
|
|
2563
|
+
}
|
|
2564
|
+
/**
|
|
2565
|
+
* Determine whether this DateTime is after another date.
|
|
2566
|
+
* @param {DateTime} other The date to compare to.
|
|
2567
|
+
* @return {Boolean} TRUE if this DateTime is after the other date, otherwise FALSE.
|
|
2568
|
+
*/
|
|
2569
|
+
function isAfter(other) {
|
|
2570
|
+
return this.diff(other) > 0;
|
|
2571
|
+
}
|
|
2572
|
+
|
|
2573
|
+
/**
|
|
2574
|
+
* Determine whether this DateTime is after another date (comparing by day).
|
|
2575
|
+
* @param {DateTime} other The date to compare to.
|
|
2576
|
+
* @return {Boolean} TRUE if this DateTime is after the other date (comparing by day), otherwise FALSE.
|
|
2577
|
+
*/
|
|
2578
|
+
function isAfterDay(other) {
|
|
2579
|
+
return this.diffInDays(other) > 0;
|
|
2580
|
+
}
|
|
2581
|
+
|
|
2582
|
+
/**
|
|
2583
|
+
* Determine whether this DateTime is after another date (comparing by hour).
|
|
2584
|
+
* @param {DateTime} other The date to compare to.
|
|
2585
|
+
* @return {Boolean} TRUE if this DateTime is after the other date (comparing by hour), otherwise FALSE.
|
|
2586
|
+
*/
|
|
2587
|
+
function isAfterHour(other) {
|
|
2588
|
+
return this.diffInHours(other) > 0;
|
|
2589
|
+
}
|
|
2590
|
+
|
|
2591
|
+
/**
|
|
2592
|
+
* Determine whether this DateTime is after another date (comparing by minute).
|
|
2593
|
+
* @param {DateTime} other The date to compare to.
|
|
2594
|
+
* @return {Boolean} TRUE if this DateTime is after the other date (comparing by minute), otherwise FALSE.
|
|
2595
|
+
*/
|
|
2596
|
+
function isAfterMinute(other) {
|
|
2597
|
+
return this.diffInMinutes(other) > 0;
|
|
2598
|
+
}
|
|
2599
|
+
|
|
2600
|
+
/**
|
|
2601
|
+
* Determine whether this DateTime is after another date (comparing by month).
|
|
2602
|
+
* @param {DateTime} other The date to compare to.
|
|
2603
|
+
* @return {Boolean} TRUE if this DateTime is after the other date (comparing by month), otherwise FALSE.
|
|
2604
|
+
*/
|
|
2605
|
+
function isAfterMonth(other) {
|
|
2606
|
+
return this.diffInMonths(other) > 0;
|
|
2607
|
+
}
|
|
2608
|
+
|
|
2609
|
+
/**
|
|
2610
|
+
* Determine whether this DateTime is after another date (comparing by second).
|
|
2611
|
+
* @param {DateTime} other The date to compare to.
|
|
2612
|
+
* @return {Boolean} TRUE if this DateTime is after the other date (comparing by second), otherwise FALSE.
|
|
2613
|
+
*/
|
|
2614
|
+
function isAfterSecond(other) {
|
|
2615
|
+
return this.diffInSeconds(other) > 0;
|
|
2616
|
+
}
|
|
2617
|
+
|
|
2618
|
+
/**
|
|
2619
|
+
* Determine whether this DateTime is after another date (comparing by week).
|
|
2620
|
+
* @param {DateTime} other The date to compare to.
|
|
2621
|
+
* @return {Boolean} TRUE if this DateTime is after the other date (comparing by week), otherwise FALSE.
|
|
2622
|
+
*/
|
|
2623
|
+
function isAfterWeek(other) {
|
|
2624
|
+
return this.diffInWeeks(other) > 0;
|
|
2625
|
+
}
|
|
2626
|
+
|
|
2627
|
+
/**
|
|
2628
|
+
* Determine whether this DateTime is after another date (comparing by year).
|
|
2629
|
+
* @param {DateTime} other The date to compare to.
|
|
2630
|
+
* @return {Boolean} TRUE if this DateTime is after the other date (comparing by year), otherwise FALSE.
|
|
2631
|
+
*/
|
|
2632
|
+
function isAfterYear(other) {
|
|
2633
|
+
return this.diffInYears(other) > 0;
|
|
2634
|
+
}
|
|
2635
|
+
|
|
2636
|
+
/**
|
|
2637
|
+
* Determine whether this DateTime is before another date.
|
|
2638
|
+
* @param {DateTime} other The date to compare to.
|
|
2639
|
+
* @return {Boolean} TRUE if this DateTime is before the other date, otherwise FALSE.
|
|
2640
|
+
*/
|
|
2641
|
+
function isBefore(other) {
|
|
2642
|
+
return this.diff(other) < 0;
|
|
2643
|
+
}
|
|
2644
|
+
|
|
2645
|
+
/**
|
|
2646
|
+
* Determine whether this DateTime is before another date (comparing by day).
|
|
2647
|
+
* @param {DateTime} other The date to compare to.
|
|
2648
|
+
* @return {Boolean} TRUE if this DateTime is before the other date (comparing by day), otherwise FALSE.
|
|
2649
|
+
*/
|
|
2650
|
+
function isBeforeDay(other) {
|
|
2651
|
+
return this.diffInDays(other) < 0;
|
|
2652
|
+
}
|
|
2653
|
+
|
|
2654
|
+
/**
|
|
2655
|
+
* Determine whether this DateTime is before another date (comparing by hour).
|
|
2656
|
+
* @param {DateTime} other The date to compare to.
|
|
2657
|
+
* @return {Boolean} TRUE if this DateTime is before the other date (comparing by hour), otherwise FALSE.
|
|
2658
|
+
*/
|
|
2659
|
+
function isBeforeHour(other) {
|
|
2660
|
+
return this.diffInHours(other) < 0;
|
|
2661
|
+
}
|
|
2662
|
+
|
|
2663
|
+
/**
|
|
2664
|
+
* Determine whether this DateTime is before another date (comparing by minute).
|
|
2665
|
+
* @param {DateTime} other The date to compare to.
|
|
2666
|
+
* @return {Boolean} TRUE if this DateTime is before the other date (comparing by minute), otherwise FALSE.
|
|
2667
|
+
*/
|
|
2668
|
+
function isBeforeMinute(other) {
|
|
2669
|
+
return this.diffInMinutes(other) < 0;
|
|
2670
|
+
}
|
|
2671
|
+
|
|
2672
|
+
/**
|
|
2673
|
+
* Determine whether this DateTime is before another date (comparing by month).
|
|
2674
|
+
* @param {DateTime} other The date to compare to.
|
|
2675
|
+
* @return {Boolean} TRUE if this DateTime is before the other date (comparing by month), otherwise FALSE.
|
|
2676
|
+
*/
|
|
2677
|
+
function isBeforeMonth(other) {
|
|
2678
|
+
return this.diffInMonths(other) < 0;
|
|
2679
|
+
}
|
|
2680
|
+
|
|
2681
|
+
/**
|
|
2682
|
+
* Determine whether this DateTime is before another date (comparing by second).
|
|
2683
|
+
* @param {DateTime} other The date to compare to.
|
|
2684
|
+
* @return {Boolean} TRUE if this DateTime is before the other date (comparing by second), otherwise FALSE.
|
|
2685
|
+
*/
|
|
2686
|
+
function isBeforeSecond(other) {
|
|
2687
|
+
return this.diffInSeconds(other) < 0;
|
|
2688
|
+
}
|
|
2689
|
+
|
|
2690
|
+
/**
|
|
2691
|
+
* Determine whether this DateTime is before another date (comparing by week).
|
|
2692
|
+
* @param {DateTime} other The date to compare to.
|
|
2693
|
+
* @return {Boolean} TRUE if this DateTime is before the other date (comparing by week), otherwise FALSE.
|
|
2694
|
+
*/
|
|
2695
|
+
function isBeforeWeek(other) {
|
|
2696
|
+
return this.diffInWeeks(other) < 0;
|
|
2697
|
+
}
|
|
2698
|
+
|
|
2699
|
+
/**
|
|
2700
|
+
* Determine whether this DateTime is before another date (comparing by year).
|
|
2701
|
+
* @param {DateTime} other The date to compare to.
|
|
2702
|
+
* @return {Boolean} TRUE if this DateTime is before the other date (comparing by year), otherwise FALSE.
|
|
2703
|
+
*/
|
|
2704
|
+
function isBeforeYear(other) {
|
|
2705
|
+
return this.diffInYears(other) < 0;
|
|
2706
|
+
}
|
|
2707
|
+
|
|
2708
|
+
/**
|
|
2709
|
+
* Determine whether this DateTime is between two other dates.
|
|
2710
|
+
* @param {DateTime} start The first date to compare to.
|
|
2711
|
+
* @param {DateTime} end The second date to compare to.
|
|
2712
|
+
* @return {Boolean} TRUE if this DateTime is between two other dates, otherwise FALSE.
|
|
2713
|
+
*/
|
|
2714
|
+
function isBetween(start, end) {
|
|
2715
|
+
return this.isAfter(start) && this.isBefore(end);
|
|
2716
|
+
}
|
|
2717
|
+
|
|
2718
|
+
/**
|
|
2719
|
+
* Determine whether this DateTime is between two other dates (comparing by day).
|
|
2720
|
+
* @param {DateTime} start The first date to compare to.
|
|
2721
|
+
* @param {DateTime} end The second date to compare to.
|
|
2722
|
+
* @return {Boolean} TRUE if this DateTime is between two other dates (comparing by day), otherwise FALSE.
|
|
2723
|
+
*/
|
|
2724
|
+
function isBetweenDay(start, end) {
|
|
2725
|
+
return this.isAfterDay(start) && this.isBeforeDay(end);
|
|
2726
|
+
}
|
|
2727
|
+
|
|
2728
|
+
/**
|
|
2729
|
+
* Determine whether this DateTime is between two other dates (comparing by hour).
|
|
2730
|
+
* @param {DateTime} start The first date to compare to.
|
|
2731
|
+
* @param {DateTime} end The second date to compare to.
|
|
2732
|
+
* @return {Boolean} TRUE if this DateTime is between two other dates (comparing by hour), otherwise FALSE.
|
|
2733
|
+
*/
|
|
2734
|
+
function isBetweenHour(start, end) {
|
|
2735
|
+
return this.isAfterHour(start) && this.isBeforeHour(end);
|
|
2736
|
+
}
|
|
2737
|
+
|
|
2738
|
+
/**
|
|
2739
|
+
* Determine whether this DateTime is between two other dates (comparing by minute).
|
|
2740
|
+
* @param {DateTime} start The first date to compare to.
|
|
2741
|
+
* @param {DateTime} end The second date to compare to.
|
|
2742
|
+
* @return {Boolean} TRUE if this DateTime is between two other dates (comparing by minute), otherwise FALSE.
|
|
2743
|
+
*/
|
|
2744
|
+
function isBetweenMinute(start, end) {
|
|
2745
|
+
return this.isAfterMinute(start) && this.isBeforeMinute(end);
|
|
2746
|
+
}
|
|
2747
|
+
|
|
2748
|
+
/**
|
|
2749
|
+
* Determine whether this DateTime is between two other dates (comparing by month).
|
|
2750
|
+
* @param {DateTime} start The first date to compare to.
|
|
2751
|
+
* @param {DateTime} end The second date to compare to.
|
|
2752
|
+
* @return {Boolean} TRUE if this DateTime is between two other dates (comparing by month), otherwise FALSE.
|
|
2753
|
+
*/
|
|
2754
|
+
function isBetweenMonth(start, end) {
|
|
2755
|
+
return this.isAfterMonth(start) && this.isBeforeMonth(end);
|
|
2756
|
+
}
|
|
2757
|
+
|
|
2758
|
+
/**
|
|
2759
|
+
* Determine whether this DateTime is between two other dates (comparing by second).
|
|
2760
|
+
* @param {DateTime} start The first date to compare to.
|
|
2761
|
+
* @param {DateTime} end The second date to compare to.
|
|
2762
|
+
* @return {Boolean} TRUE if this DateTime is between two other dates (comparing by second), otherwise FALSE.
|
|
2763
|
+
*/
|
|
2764
|
+
function isBetweenSecond(start, end) {
|
|
2765
|
+
return this.isAfterSecond(start) && this.isBeforeSecond(end);
|
|
2766
|
+
}
|
|
2767
|
+
|
|
2768
|
+
/**
|
|
2769
|
+
* Determine whether this DateTime is between two other dates (comparing by week).
|
|
2770
|
+
* @param {DateTime} start The first date to compare to.
|
|
2771
|
+
* @param {DateTime} end The second date to compare to.
|
|
2772
|
+
* @return {Boolean} TRUE if this DateTime is between two other dates (comparing by week), otherwise FALSE.
|
|
2773
|
+
*/
|
|
2774
|
+
function isBetweenWeek(start, end) {
|
|
2775
|
+
return this.isAfterWeek(start) && this.isBeforeWeek(end);
|
|
2776
|
+
}
|
|
2777
|
+
|
|
2778
|
+
/**
|
|
2779
|
+
* Determine whether this DateTime is between two other dates (comparing by year).
|
|
2780
|
+
* @param {DateTime} start The first date to compare to.
|
|
2781
|
+
* @param {DateTime} end The second date to compare to.
|
|
2782
|
+
* @return {Boolean} TRUE if this DateTime is between two other dates (comparing by year), otherwise FALSE.
|
|
2783
|
+
*/
|
|
2784
|
+
function isBetweenYear(start, end) {
|
|
2785
|
+
return this.isAfterYear(start) && this.isBeforeYear(end);
|
|
2786
|
+
}
|
|
2787
|
+
|
|
2788
|
+
/**
|
|
2789
|
+
* Determine whether this DateTime is the same as another date.
|
|
2790
|
+
* @param {DateTime} other The date to compare to.
|
|
2791
|
+
* @return {Boolean} TRUE if this DateTime is the same as the other date, otherwise FALSE.
|
|
2792
|
+
*/
|
|
2793
|
+
function isSame(other) {
|
|
2794
|
+
return this.diff(other) === 0;
|
|
2795
|
+
}
|
|
2796
|
+
|
|
2797
|
+
/**
|
|
2798
|
+
* Determine whether this DateTime is the same as another date (comparing by day).
|
|
2799
|
+
* @param {DateTime} other The date to compare to.
|
|
2800
|
+
* @return {Boolean} TRUE if this DateTime is the same as the other date (comparing by day), otherwise FALSE.
|
|
2801
|
+
*/
|
|
2802
|
+
function isSameDay(other) {
|
|
2803
|
+
return this.diffInDays(other) === 0;
|
|
2804
|
+
}
|
|
2805
|
+
|
|
2806
|
+
/**
|
|
2807
|
+
* Determine whether this DateTime is the same as another date (comparing by hour).
|
|
2808
|
+
* @param {DateTime} other The date to compare to.
|
|
2809
|
+
* @return {Boolean} TRUE if this DateTime is the same as the other date (comparing by hour), otherwise FALSE.
|
|
2810
|
+
*/
|
|
2811
|
+
function isSameHour(other) {
|
|
2812
|
+
return this.diffInHours(other) === 0;
|
|
2813
|
+
}
|
|
2814
|
+
|
|
2815
|
+
/**
|
|
2816
|
+
* Determine whether this DateTime is the same as another date (comparing by minute).
|
|
2817
|
+
* @param {DateTime} other The date to compare to.
|
|
2818
|
+
* @return {Boolean} TRUE if this DateTime is the same as the other date (comparing by minute), otherwise FALSE.
|
|
2819
|
+
*/
|
|
2820
|
+
function isSameMinute(other) {
|
|
2821
|
+
return this.diffInMinutes(other) === 0;
|
|
2822
|
+
}
|
|
2823
|
+
|
|
2824
|
+
/**
|
|
2825
|
+
* Determine whether this DateTime is the same as another date (comparing by month).
|
|
2826
|
+
* @param {DateTime} other The date to compare to.
|
|
2827
|
+
* @return {Boolean} TRUE if this DateTime is the same as the other date (comparing by month), otherwise FALSE.
|
|
2828
|
+
*/
|
|
2829
|
+
function isSameMonth(other) {
|
|
2830
|
+
return this.diffInMonths(other) === 0;
|
|
2831
|
+
}
|
|
2832
|
+
|
|
2833
|
+
/**
|
|
2834
|
+
* Determine whether this DateTime is the same as another date (comparing by second).
|
|
2835
|
+
* @param {DateTime} other The date to compare to.
|
|
2836
|
+
* @return {Boolean} TRUE if this DateTime is the same as the other date (comparing by second), otherwise FALSE.
|
|
2837
|
+
*/
|
|
2838
|
+
function isSameSecond(other) {
|
|
2839
|
+
return this.diffInSeconds(other) === 0;
|
|
2840
|
+
}
|
|
2841
|
+
|
|
2842
|
+
/**
|
|
2843
|
+
* Determine whether this DateTime is the same as another date (comparing by week).
|
|
2844
|
+
* @param {DateTime} other The date to compare to.
|
|
2845
|
+
* @return {Boolean} TRUE if this DateTime is the same as the other date (comparing by week), otherwise FALSE.
|
|
2846
|
+
*/
|
|
2847
|
+
function isSameWeek(other) {
|
|
2848
|
+
return this.diffInWeeks(other) === 0;
|
|
2849
|
+
}
|
|
2850
|
+
|
|
2851
|
+
/**
|
|
2852
|
+
* Determine whether this DateTime is the same as another date (comparing by year).
|
|
2853
|
+
* @param {DateTime} other The date to compare to.
|
|
2854
|
+
* @return {Boolean} TRUE if this DateTime is the same as the other date (comparing by year), otherwise FALSE.
|
|
2855
|
+
*/
|
|
2856
|
+
function isSameYear(other) {
|
|
2857
|
+
return this.diffInYears(other) === 0;
|
|
2858
|
+
}
|
|
2859
|
+
|
|
2860
|
+
/**
|
|
2861
|
+
* Determine whether this DateTime is the same as or after another date.
|
|
2862
|
+
* @param {DateTime} other The date to compare to.
|
|
2863
|
+
* @return {Boolean} TRUE if this DateTime is the same as or after the other date, otherwise FALSE.
|
|
2864
|
+
*/
|
|
2865
|
+
function isSameOrAfter(other) {
|
|
2866
|
+
return this.diff(other) >= 0;
|
|
2867
|
+
}
|
|
2868
|
+
|
|
2869
|
+
/**
|
|
2870
|
+
* Determine whether this DateTime is the same as or after another date (comparing by day).
|
|
2871
|
+
* @param {DateTime} other The date to compare to.
|
|
2872
|
+
* @return {Boolean} TRUE if this DateTime is the same as or after the other date (comparing by day), otherwise FALSE.
|
|
2873
|
+
*/
|
|
2874
|
+
function isSameOrAfterDay(other) {
|
|
2875
|
+
return this.diffInDays(other) >= 0;
|
|
2876
|
+
}
|
|
2877
|
+
|
|
2878
|
+
/**
|
|
2879
|
+
* Determine whether this DateTime is the same as or after another date (comparing by hour).
|
|
2880
|
+
* @param {DateTime} other The date to compare to.
|
|
2881
|
+
* @return {Boolean} TRUE if this DateTime is the same as or after the other date (comparing by hour), otherwise FALSE.
|
|
2882
|
+
*/
|
|
2883
|
+
function isSameOrAfterHour(other) {
|
|
2884
|
+
return this.diffInHours(other) >= 0;
|
|
2885
|
+
}
|
|
2886
|
+
|
|
2887
|
+
/**
|
|
2888
|
+
* Determine whether this DateTime is the same as or after another date (comparing by minute).
|
|
2889
|
+
* @param {DateTime} other The date to compare to.
|
|
2890
|
+
* @return {Boolean} TRUE if this DateTime is the same as or after the other date (comparing by minute), otherwise FALSE.
|
|
2891
|
+
*/
|
|
2892
|
+
function isSameOrAfterMinute(other) {
|
|
2893
|
+
return this.diffInMinutes(other) >= 0;
|
|
2894
|
+
}
|
|
2895
|
+
|
|
2896
|
+
/**
|
|
2897
|
+
* Determine whether this DateTime is the same as or after another date (comparing by month).
|
|
2898
|
+
* @param {DateTime} other The date to compare to.
|
|
2899
|
+
* @return {Boolean} TRUE if this DateTime is the same as or after the other date (comparing by month), otherwise FALSE.
|
|
2900
|
+
*/
|
|
2901
|
+
function isSameOrAfterMonth(other) {
|
|
2902
|
+
return this.diffInMonths(other) >= 0;
|
|
2903
|
+
}
|
|
2904
|
+
|
|
2905
|
+
/**
|
|
2906
|
+
* Determine whether this DateTime is the same as or after another date (comparing by second).
|
|
2907
|
+
* @param {DateTime} other The date to compare to.
|
|
2908
|
+
* @return {Boolean} TRUE if this DateTime is the same as or after the other date (comparing by second), otherwise FALSE.
|
|
2909
|
+
*/
|
|
2910
|
+
function isSameOrAfterSecond(other) {
|
|
2911
|
+
return this.diffInSeconds(other) >= 0;
|
|
2912
|
+
}
|
|
2913
|
+
|
|
2914
|
+
/**
|
|
2915
|
+
* Determine whether this DateTime is the same as or after another date (comparing by week).
|
|
2916
|
+
* @param {DateTime} other The date to compare to.
|
|
2917
|
+
* @return {Boolean} TRUE if this DateTime is the same as or after the other date (comparing by week), otherwise FALSE.
|
|
2918
|
+
*/
|
|
2919
|
+
function isSameOrAfterWeek(other) {
|
|
2920
|
+
return this.diffInWeeks(other) >= 0;
|
|
2921
|
+
}
|
|
2922
|
+
|
|
2923
|
+
/**
|
|
2924
|
+
* Determine whether this DateTime is the same as or after another date (comparing by year).
|
|
2925
|
+
* @param {DateTime} other The date to compare to.
|
|
2926
|
+
* @return {Boolean} TRUE if this DateTime is the same as or after the other date (comparing by year), otherwise FALSE.
|
|
2927
|
+
*/
|
|
2928
|
+
function isSameOrAfterYear(other) {
|
|
2929
|
+
return this.diffInYears(other) >= 0;
|
|
2930
|
+
}
|
|
2931
|
+
|
|
2932
|
+
/**
|
|
2933
|
+
* Determine whether this DateTime is the same as or before another date.
|
|
2934
|
+
* @param {DateTime} other The date to compare to.
|
|
2935
|
+
* @return {Boolean} TRUE if this DateTime is the same as or before the other date, otherwise FALSE.
|
|
2936
|
+
*/
|
|
2937
|
+
function isSameOrBefore(other) {
|
|
2938
|
+
return this.diff(other) <= 0;
|
|
2939
|
+
}
|
|
2940
|
+
|
|
2941
|
+
/**
|
|
2942
|
+
* Determine whether this DateTime is the same as or before another date (comparing by day).
|
|
2943
|
+
* @param {DateTime} other The date to compare to.
|
|
2944
|
+
* @return {Boolean} TRUE if this DateTime is the same as or before the other date (comparing by day), otherwise FALSE.
|
|
2945
|
+
*/
|
|
2946
|
+
function isSameOrBeforeDay(other) {
|
|
2947
|
+
return this.diffInDays(other) <= 0;
|
|
2948
|
+
}
|
|
2949
|
+
|
|
2950
|
+
/**
|
|
2951
|
+
* Determine whether this DateTime is the same as or before another date (comparing by hour).
|
|
2952
|
+
* @param {DateTime} other The date to compare to.
|
|
2953
|
+
* @return {Boolean} TRUE if this DateTime is the same as or before the other date (comparing by hour), otherwise FALSE.
|
|
2954
|
+
*/
|
|
2955
|
+
function isSameOrBeforeHour(other) {
|
|
2956
|
+
return this.diffInHours(other) <= 0;
|
|
2957
|
+
}
|
|
2958
|
+
|
|
2959
|
+
/**
|
|
2960
|
+
* Determine whether this DateTime is the same as or before another date (comparing by minute).
|
|
2961
|
+
* @param {DateTime} other The date to compare to.
|
|
2962
|
+
* @return {Boolean} TRUE if this DateTime is the same as or before the other date (comparing by minute), otherwise FALSE.
|
|
2963
|
+
*/
|
|
2964
|
+
function isSameOrBeforeMinute(other) {
|
|
2965
|
+
return this.diffInMinutes(other) <= 0;
|
|
2966
|
+
}
|
|
2967
|
+
|
|
2968
|
+
/**
|
|
2969
|
+
* Determine whether this DateTime is the same as or before another date (comparing by month).
|
|
2970
|
+
* @param {DateTime} other The date to compare to.
|
|
2971
|
+
* @return {Boolean} TRUE if this DateTime is the same as or before the other date (comparing by month), otherwise FALSE.
|
|
2972
|
+
*/
|
|
2973
|
+
function isSameOrBeforeMonth(other) {
|
|
2974
|
+
return this.diffInMonths(other) <= 0;
|
|
2975
|
+
}
|
|
2976
|
+
|
|
2977
|
+
/**
|
|
2978
|
+
* Determine whether this DateTime is the same as or before another date (comparing by second).
|
|
2979
|
+
* @param {DateTime} other The date to compare to.
|
|
2980
|
+
* @return {Boolean} TRUE if this DateTime is the same as or before the other date (comparing by second), otherwise FALSE.
|
|
2981
|
+
*/
|
|
2982
|
+
function isSameOrBeforeSecond(other) {
|
|
2983
|
+
return this.diffInSeconds(other) <= 0;
|
|
2984
|
+
}
|
|
2985
|
+
|
|
2986
|
+
/**
|
|
2987
|
+
* Determine whether this DateTime is the same as or before another date (comparing by week).
|
|
2988
|
+
* @param {DateTime} other The date to compare to.
|
|
2989
|
+
* @return {Boolean} TRUE if this DateTime is the same as or before the other date (comparing by week), otherwise FALSE.
|
|
2990
|
+
*/
|
|
2991
|
+
function isSameOrBeforeWeek(other) {
|
|
2992
|
+
return this.diffInWeeks(other) <= 0;
|
|
2993
|
+
}
|
|
2994
|
+
|
|
2995
|
+
/**
|
|
2996
|
+
* Determine whether this DateTime is the same as or before another date (comparing by year).
|
|
2997
|
+
* @param {DateTime} other The date to compare to.
|
|
2998
|
+
* @return {Boolean} TRUE if this DateTime is the same as or before the other date (comparing by year), otherwise FALSE.
|
|
2999
|
+
*/
|
|
3000
|
+
function isSameOrBeforeYear(other) {
|
|
3001
|
+
return this.diffInYears(other) <= 0;
|
|
3002
|
+
}
|
|
3003
|
+
|
|
3004
|
+
/**
|
|
3005
|
+
* DateTime Manipulation
|
|
3006
|
+
*/
|
|
3007
|
+
|
|
3008
|
+
/**
|
|
3009
|
+
* Add a day to the current DateTime.
|
|
3010
|
+
* @return {DateTime} The DateTime object.
|
|
3011
|
+
*/
|
|
3012
|
+
function addDay() {
|
|
3013
|
+
return this.addDays(1);
|
|
3014
|
+
}
|
|
3015
|
+
/**
|
|
3016
|
+
* Add days to the current DateTime.
|
|
3017
|
+
* @param {number} amount The number of days to add.
|
|
3018
|
+
* @return {DateTime} The DateTime object.
|
|
3019
|
+
*/
|
|
3020
|
+
function addDays(amount) {
|
|
3021
|
+
return this.setDate(
|
|
3022
|
+
this.getDate() + amount,
|
|
3023
|
+
);
|
|
3024
|
+
}
|
|
3025
|
+
/**
|
|
3026
|
+
* Add an hour to the current DateTime.
|
|
3027
|
+
* @return {DateTime} The DateTime object.
|
|
3028
|
+
*/
|
|
3029
|
+
function addHour() {
|
|
3030
|
+
return this.addHours(1);
|
|
3031
|
+
}
|
|
3032
|
+
/**
|
|
3033
|
+
* Add hours to the current DateTime.
|
|
3034
|
+
* @param {number} amount The number of hours to add.
|
|
3035
|
+
* @return {DateTime} The DateTime object.
|
|
3036
|
+
*/
|
|
3037
|
+
function addHours(amount) {
|
|
3038
|
+
return this.setTime(
|
|
3039
|
+
this.getTime() + (amount * 3600000),
|
|
3040
|
+
);
|
|
3041
|
+
}
|
|
3042
|
+
/**
|
|
3043
|
+
* Add a minute to the current DateTime.
|
|
3044
|
+
* @return {DateTime} The DateTime object.
|
|
3045
|
+
*/
|
|
3046
|
+
function addMinute() {
|
|
3047
|
+
return this.addMinutes(1);
|
|
3048
|
+
}
|
|
3049
|
+
/**
|
|
3050
|
+
* Add minutes to the current DateTime.
|
|
3051
|
+
* @param {number} amount The number of minutes to add.
|
|
3052
|
+
* @return {DateTime} The DateTime object.
|
|
3053
|
+
*/
|
|
3054
|
+
function addMinutes(amount) {
|
|
3055
|
+
return this.setTime(
|
|
3056
|
+
this.getTime() + (amount * 60000),
|
|
3057
|
+
);
|
|
3058
|
+
}
|
|
3059
|
+
/**
|
|
3060
|
+
* Add a month to the current DateTime.
|
|
3061
|
+
* @return {DateTime} The DateTime object.
|
|
3062
|
+
*/
|
|
3063
|
+
function addMonth() {
|
|
3064
|
+
return this.addMonths(1);
|
|
3065
|
+
}
|
|
3066
|
+
/**
|
|
3067
|
+
* Add months to the current DateTime.
|
|
3068
|
+
* @param {number} amount The number of months to add.
|
|
3069
|
+
* @return {DateTime} The DateTime object.
|
|
3070
|
+
*/
|
|
3071
|
+
function addMonths(amount) {
|
|
3072
|
+
return this.setMonth(
|
|
3073
|
+
this.getMonth() + amount,
|
|
3074
|
+
);
|
|
3075
|
+
}
|
|
3076
|
+
/**
|
|
3077
|
+
* Add a second to the current DateTime.
|
|
3078
|
+
* @return {DateTime} The DateTime object.
|
|
3079
|
+
*/
|
|
3080
|
+
function addSecond() {
|
|
3081
|
+
return this.addSeconds(1);
|
|
3082
|
+
}
|
|
3083
|
+
/**
|
|
3084
|
+
* Add seconds to the current DateTime.
|
|
3085
|
+
* @param {number} amount The number of seconds to add.
|
|
3086
|
+
* @return {DateTime} The DateTime object.
|
|
3087
|
+
*/
|
|
3088
|
+
function addSeconds(amount) {
|
|
3089
|
+
return this.setTime(
|
|
3090
|
+
this.getTime() + (amount * 1000),
|
|
3091
|
+
);
|
|
3092
|
+
}
|
|
3093
|
+
/**
|
|
3094
|
+
* Add a week to the current DateTime.
|
|
3095
|
+
* @return {DateTime} The DateTime object.
|
|
3096
|
+
*/
|
|
3097
|
+
function addWeek() {
|
|
3098
|
+
return this.addWeeks(1);
|
|
3099
|
+
}
|
|
3100
|
+
/**
|
|
3101
|
+
* Add weeks to the current DateTime.
|
|
3102
|
+
* @param {number} amount The number of weeks to add.
|
|
3103
|
+
* @return {DateTime} The DateTime object.
|
|
3104
|
+
*/
|
|
3105
|
+
function addWeeks(amount) {
|
|
3106
|
+
return this.setDate(
|
|
3107
|
+
this.getDate() + (amount * 7),
|
|
3108
|
+
);
|
|
3109
|
+
}
|
|
3110
|
+
/**
|
|
3111
|
+
* Add a year to the current DateTime.
|
|
3112
|
+
* @return {DateTime} The DateTime object.
|
|
3113
|
+
*/
|
|
3114
|
+
function addYear() {
|
|
3115
|
+
return this.addYears(1);
|
|
3116
|
+
}
|
|
3117
|
+
/**
|
|
3118
|
+
* Add years to the current DateTime.
|
|
3119
|
+
* @param {number} amount The number of years to add.
|
|
3120
|
+
* @return {DateTime} The DateTime object.
|
|
3121
|
+
*/
|
|
3122
|
+
function addYears(amount) {
|
|
3123
|
+
return this.setYear(
|
|
3124
|
+
this.getYear() + amount,
|
|
3125
|
+
);
|
|
3126
|
+
}
|
|
3127
|
+
/**
|
|
3128
|
+
* Set the DateTime to the end of the day.
|
|
3129
|
+
* @return {DateTime} The DateTime object.
|
|
3130
|
+
*/
|
|
3131
|
+
function endOfDay() {
|
|
3132
|
+
return this.setHours(23, 59, 59, 999);
|
|
3133
|
+
}
|
|
3134
|
+
/**
|
|
3135
|
+
* Set the DateTime to the end of the hour.
|
|
3136
|
+
* @return {DateTime} The DateTime object.
|
|
3137
|
+
*/
|
|
3138
|
+
function endOfHour() {
|
|
3139
|
+
return this.setMinutes(59, 59, 999);
|
|
3140
|
+
}
|
|
3141
|
+
/**
|
|
3142
|
+
* Set the DateTime to the end of the minute.
|
|
3143
|
+
* @return {DateTime} The DateTime object.
|
|
3144
|
+
*/
|
|
3145
|
+
function endOfMinute() {
|
|
3146
|
+
return this.setSeconds(59, 999);
|
|
3147
|
+
}
|
|
3148
|
+
/**
|
|
3149
|
+
* Set the DateTime to the end of the month.
|
|
3150
|
+
* @return {DateTime} The DateTime object.
|
|
3151
|
+
*/
|
|
3152
|
+
function endOfMonth() {
|
|
3153
|
+
return this.setDate(this.daysInMonth())
|
|
3154
|
+
.endOfDay();
|
|
3155
|
+
}
|
|
3156
|
+
|
|
3157
|
+
/**
|
|
3158
|
+
* Set the DateTime to the end of the quarter.
|
|
3159
|
+
* @return {DateTime} The DateTime object.
|
|
3160
|
+
*/
|
|
3161
|
+
function endOfQuarter() {
|
|
3162
|
+
const month = this.getQuarter() * 3;
|
|
3163
|
+
return this.setMonth(month, daysInMonth$1(this.getYear(), month))
|
|
3164
|
+
.endOfDay();
|
|
3165
|
+
}
|
|
3166
|
+
/**
|
|
3167
|
+
* Set the DateTime to the end of the second.
|
|
3168
|
+
* @return {DateTime} The DateTime object.
|
|
3169
|
+
*/
|
|
3170
|
+
function endOfSecond() {
|
|
3171
|
+
return this.setMilliseconds(999);
|
|
3172
|
+
}
|
|
3173
|
+
/**
|
|
3174
|
+
* Set the DateTime to the end of the week.
|
|
3175
|
+
* @return {DateTime} The DateTime object.
|
|
3176
|
+
*/
|
|
3177
|
+
function endOfWeek() {
|
|
3178
|
+
return this.setWeekDay(7)
|
|
3179
|
+
.endOfDay();
|
|
3180
|
+
}
|
|
3181
|
+
/**
|
|
3182
|
+
* Set the DateTime to the end of the year.
|
|
3183
|
+
* @return {DateTime} The DateTime object.
|
|
3184
|
+
*/
|
|
3185
|
+
function endOfYear() {
|
|
3186
|
+
return this.setMonth(12, 31)
|
|
3187
|
+
.endOfDay();
|
|
3188
|
+
}
|
|
3189
|
+
/**
|
|
3190
|
+
* Set the DateTime to the start of the day.
|
|
3191
|
+
* @return {DateTime} The DateTime object.
|
|
3192
|
+
*/
|
|
3193
|
+
function startOfDay() {
|
|
3194
|
+
return this.setHours(0, 0, 0, 0);
|
|
3195
|
+
}
|
|
3196
|
+
/**
|
|
3197
|
+
* Set the DateTime to the start of the hour.
|
|
3198
|
+
* @return {DateTime} The DateTime object.
|
|
3199
|
+
*/
|
|
3200
|
+
function startOfHour() {
|
|
3201
|
+
return this.setMinutes(0, 0, 0);
|
|
3202
|
+
}
|
|
3203
|
+
/**
|
|
3204
|
+
* Set the DateTime to the start of the minute.
|
|
3205
|
+
* @return {DateTime} The DateTime object.
|
|
3206
|
+
*/
|
|
3207
|
+
function startOfMinute() {
|
|
3208
|
+
return this.setSeconds(0, 0);
|
|
3209
|
+
}
|
|
3210
|
+
/**
|
|
3211
|
+
* Set the DateTime to the start of the month.
|
|
3212
|
+
* @return {DateTime} The DateTime object.
|
|
3213
|
+
*/
|
|
3214
|
+
function startOfMonth() {
|
|
3215
|
+
return this.setDate(1)
|
|
3216
|
+
.startOfDay();
|
|
3217
|
+
}
|
|
3218
|
+
|
|
3219
|
+
/**
|
|
3220
|
+
* Set the DateTime to the start of the quarter.
|
|
3221
|
+
* @return {DateTime} The DateTime object.
|
|
3222
|
+
*/
|
|
3223
|
+
function startOfQuarter() {
|
|
3224
|
+
const month = this.getQuarter() * 3 - 2;
|
|
3225
|
+
return this.setMonth(month, 1)
|
|
3226
|
+
.startOfDay();
|
|
3227
|
+
}
|
|
3228
|
+
/**
|
|
3229
|
+
* Set the DateTime to the start of the second.
|
|
3230
|
+
* @return {DateTime} The DateTime object.
|
|
3231
|
+
*/
|
|
3232
|
+
function startOfSecond() {
|
|
3233
|
+
return this.setMilliseconds(0);
|
|
3234
|
+
}
|
|
3235
|
+
/**
|
|
3236
|
+
* Set the DateTime to the start of the week.
|
|
3237
|
+
* @return {DateTime} The DateTime object.
|
|
3238
|
+
*/
|
|
3239
|
+
function startOfWeek() {
|
|
3240
|
+
return this.setWeekDay(1)
|
|
3241
|
+
.startOfDay();
|
|
3242
|
+
}
|
|
3243
|
+
/**
|
|
3244
|
+
* Set the DateTime to the start of the year.
|
|
3245
|
+
* @return {DateTime} The DateTime object.
|
|
3246
|
+
*/
|
|
3247
|
+
function startOfYear() {
|
|
3248
|
+
return this.setMonth(1, 1)
|
|
3249
|
+
.startOfDay();
|
|
3250
|
+
}
|
|
3251
|
+
/**
|
|
3252
|
+
* Subtract a day from the current DateTime.
|
|
3253
|
+
* @return {DateTime} The DateTime object.
|
|
3254
|
+
*/
|
|
3255
|
+
function subDay() {
|
|
3256
|
+
return this.addDays(-1);
|
|
3257
|
+
}
|
|
3258
|
+
/**
|
|
3259
|
+
* Subtract days from the current DateTime.
|
|
3260
|
+
* @param {number} amount The number of days to subtract.
|
|
3261
|
+
* @return {DateTime} The DateTime object.
|
|
3262
|
+
*/
|
|
3263
|
+
function subDays(amount) {
|
|
3264
|
+
return this.addDays(-amount);
|
|
3265
|
+
}
|
|
3266
|
+
/**
|
|
3267
|
+
* Subtract an hour from the current DateTime.
|
|
3268
|
+
* @return {DateTime} The DateTime object.
|
|
3269
|
+
*/
|
|
3270
|
+
function subHour() {
|
|
3271
|
+
return this.addHours(-1);
|
|
3272
|
+
}
|
|
3273
|
+
/**
|
|
3274
|
+
* Subtract hours from the current DateTime.
|
|
3275
|
+
* @param {number} amount The number of hours to subtract.
|
|
3276
|
+
* @return {DateTime} The DateTime object.
|
|
3277
|
+
*/
|
|
3278
|
+
function subHours(amount) {
|
|
3279
|
+
return this.addHours(-amount);
|
|
3280
|
+
}
|
|
3281
|
+
/**
|
|
3282
|
+
* Subtract a minute from the current DateTime.
|
|
3283
|
+
* @return {DateTime} The DateTime object.
|
|
3284
|
+
*/
|
|
3285
|
+
function subMinute() {
|
|
3286
|
+
return this.addMinutes(-1);
|
|
3287
|
+
}
|
|
3288
|
+
/**
|
|
3289
|
+
* Subtract minutes from the current DateTime.
|
|
3290
|
+
* @param {number} amount The number of minutes to subtract.
|
|
3291
|
+
* @return {DateTime} The DateTime object.
|
|
2559
3292
|
*/
|
|
2560
|
-
function
|
|
2561
|
-
return
|
|
2562
|
-
this.getYear(),
|
|
2563
|
-
);
|
|
3293
|
+
function subMinutes(amount) {
|
|
3294
|
+
return this.addMinutes(-amount);
|
|
2564
3295
|
}
|
|
2565
3296
|
/**
|
|
2566
|
-
*
|
|
2567
|
-
* @
|
|
2568
|
-
* @param {object} [options] The options for comparing the dates.
|
|
2569
|
-
* @param {string} [options.timeUnit] The unit of time.
|
|
2570
|
-
* @param {Boolean} [options.relative=true] Whether to use the relative difference.
|
|
2571
|
-
* @return {number} The difference.
|
|
3297
|
+
* Subtract a month from the current DateTime.
|
|
3298
|
+
* @return {DateTime} The DateTime object.
|
|
2572
3299
|
*/
|
|
2573
|
-
function
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
3300
|
+
function subMonth() {
|
|
3301
|
+
return this.addMonths(-1);
|
|
3302
|
+
}
|
|
3303
|
+
/**
|
|
3304
|
+
* Subtract months from the current DateTime.
|
|
3305
|
+
* @param {number} amount The number of months to subtract.
|
|
3306
|
+
* @return {DateTime} The DateTime object.
|
|
3307
|
+
*/
|
|
3308
|
+
function subMonths(amount) {
|
|
3309
|
+
return this.addMonths(-amount);
|
|
3310
|
+
}
|
|
3311
|
+
/**
|
|
3312
|
+
* Subtract a second from the current DateTime.
|
|
3313
|
+
* @return {DateTime} The DateTime object.
|
|
3314
|
+
*/
|
|
3315
|
+
function subSecond() {
|
|
3316
|
+
return this.addSeconds(-1);
|
|
3317
|
+
}
|
|
3318
|
+
/**
|
|
3319
|
+
* Subtract seconds from the current DateTime.
|
|
3320
|
+
* @param {number} amount The number of seconds to subtract.
|
|
3321
|
+
* @return {DateTime} The DateTime object.
|
|
3322
|
+
*/
|
|
3323
|
+
function subSeconds(amount) {
|
|
3324
|
+
return this.addSeconds(-amount);
|
|
3325
|
+
}
|
|
3326
|
+
/**
|
|
3327
|
+
* Subtract a week from the current DateTime.
|
|
3328
|
+
* @return {DateTime} The DateTime object.
|
|
3329
|
+
*/
|
|
3330
|
+
function subWeek() {
|
|
3331
|
+
return this.addWeeks(-1);
|
|
3332
|
+
}
|
|
3333
|
+
/**
|
|
3334
|
+
* Subtract weeks from the current DateTime.
|
|
3335
|
+
* @param {number} amount The number of weeks to subtract.
|
|
3336
|
+
* @return {DateTime} The DateTime object.
|
|
3337
|
+
*/
|
|
3338
|
+
function subWeeks(amount) {
|
|
3339
|
+
return this.addWeeks(-amount);
|
|
3340
|
+
}
|
|
3341
|
+
/**
|
|
3342
|
+
* Subtract a year from the current DateTime.
|
|
3343
|
+
* @return {DateTime} The DateTime object.
|
|
3344
|
+
*/
|
|
3345
|
+
function subYear() {
|
|
3346
|
+
return this.addYears(-1);
|
|
3347
|
+
}
|
|
3348
|
+
/**
|
|
3349
|
+
* Subtract years from the current DateTime.
|
|
3350
|
+
* @param {number} amount The number of years to subtract.
|
|
3351
|
+
* @return {DateTime} The DateTime object.
|
|
3352
|
+
*/
|
|
3353
|
+
function subYears(amount) {
|
|
3354
|
+
return this.addYears(-amount);
|
|
3355
|
+
}
|
|
2577
3356
|
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
3357
|
+
/**
|
|
3358
|
+
* DateTime Output
|
|
3359
|
+
*/
|
|
2581
3360
|
|
|
2582
|
-
|
|
2583
|
-
|
|
2584
|
-
|
|
3361
|
+
/**
|
|
3362
|
+
* Format the current date using a format string.
|
|
3363
|
+
* @param {string} formatString The format string.
|
|
3364
|
+
* @return {string} The formatted date string.
|
|
3365
|
+
*/
|
|
3366
|
+
function format(formatString) {
|
|
3367
|
+
let match;
|
|
3368
|
+
let output = '';
|
|
2585
3369
|
|
|
2586
|
-
|
|
3370
|
+
while (formatString && (match = formatString.match(formatTokenRegExp))) {
|
|
3371
|
+
const token = match[1];
|
|
3372
|
+
const position = match.index;
|
|
3373
|
+
const length = match[0].length;
|
|
2587
3374
|
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
);
|
|
2601
|
-
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
12 +
|
|
2605
|
-
this.getMonth() -
|
|
2606
|
-
other.getMonth();
|
|
2607
|
-
return compensateDiff(
|
|
2608
|
-
this,
|
|
2609
|
-
other.setYear(
|
|
2610
|
-
this.getYear(),
|
|
2611
|
-
this.getMonth(),
|
|
2612
|
-
),
|
|
2613
|
-
monthDiff,
|
|
2614
|
-
!relative,
|
|
2615
|
-
-1,
|
|
2616
|
-
);
|
|
2617
|
-
case 'week':
|
|
2618
|
-
case 'weeks':
|
|
2619
|
-
const weekDiff = (this - other) / 604800000;
|
|
2620
|
-
return compensateDiff(
|
|
2621
|
-
this,
|
|
2622
|
-
other.setWeekYear(
|
|
2623
|
-
this.getWeekYear(),
|
|
2624
|
-
this.getWeek(),
|
|
2625
|
-
),
|
|
2626
|
-
weekDiff,
|
|
2627
|
-
relative,
|
|
2628
|
-
);
|
|
2629
|
-
case 'day':
|
|
2630
|
-
case 'days':
|
|
2631
|
-
const dayDiff = (this - other) / 86400000;
|
|
2632
|
-
return compensateDiff(
|
|
2633
|
-
this,
|
|
2634
|
-
other.setYear(
|
|
2635
|
-
this.getYear(),
|
|
2636
|
-
this.getMonth(),
|
|
2637
|
-
this.getDate(),
|
|
2638
|
-
),
|
|
2639
|
-
dayDiff,
|
|
2640
|
-
relative,
|
|
2641
|
-
);
|
|
2642
|
-
case 'hour':
|
|
2643
|
-
case 'hours':
|
|
2644
|
-
const hourDiff = (this - other) / 3600000;
|
|
2645
|
-
return compensateDiff(
|
|
2646
|
-
this,
|
|
2647
|
-
other.setYear(
|
|
2648
|
-
this.getYear(),
|
|
2649
|
-
this.getMonth(),
|
|
2650
|
-
this.getDate(),
|
|
2651
|
-
).setHours(
|
|
2652
|
-
this.getHours(),
|
|
2653
|
-
),
|
|
2654
|
-
hourDiff,
|
|
2655
|
-
relative,
|
|
2656
|
-
);
|
|
2657
|
-
case 'minute':
|
|
2658
|
-
case 'minutes':
|
|
2659
|
-
const minuteDiff = (this - other) / 60000;
|
|
2660
|
-
return compensateDiff(
|
|
2661
|
-
this,
|
|
2662
|
-
other.setYear(
|
|
2663
|
-
this.getYear(),
|
|
2664
|
-
this.getMonth(),
|
|
2665
|
-
this.getDate(),
|
|
2666
|
-
).setHours(
|
|
2667
|
-
this.getHours(),
|
|
2668
|
-
this.getMinutes(),
|
|
2669
|
-
),
|
|
2670
|
-
minuteDiff,
|
|
2671
|
-
relative,
|
|
2672
|
-
);
|
|
2673
|
-
case 'second':
|
|
2674
|
-
case 'seconds':
|
|
2675
|
-
const secondDiff = (this - other) / 1000;
|
|
2676
|
-
return compensateDiff(
|
|
2677
|
-
this,
|
|
2678
|
-
other.setYear(
|
|
2679
|
-
this.getYear(),
|
|
2680
|
-
this.getMonth(),
|
|
2681
|
-
this.getDate(),
|
|
2682
|
-
).setHours(
|
|
2683
|
-
this.getHours(),
|
|
2684
|
-
this.getMinutes(),
|
|
2685
|
-
this.getSeconds(),
|
|
2686
|
-
),
|
|
2687
|
-
secondDiff,
|
|
2688
|
-
relative,
|
|
2689
|
-
);
|
|
2690
|
-
default:
|
|
2691
|
-
throw new Error('Invalid time unit supplied');
|
|
3375
|
+
if (position) {
|
|
3376
|
+
output += formatString.substring(0, position);
|
|
3377
|
+
}
|
|
3378
|
+
|
|
3379
|
+
formatString = formatString.substring(position + length);
|
|
3380
|
+
|
|
3381
|
+
if (!token) {
|
|
3382
|
+
output += match[0].slice(1, -1);
|
|
3383
|
+
continue;
|
|
3384
|
+
}
|
|
3385
|
+
|
|
3386
|
+
if (!(token in tokens)) {
|
|
3387
|
+
throw new Error(`Invalid token in DateTime format: ${token}`);
|
|
3388
|
+
}
|
|
3389
|
+
|
|
3390
|
+
output += tokens[token].output(this, length);
|
|
2692
3391
|
}
|
|
3392
|
+
|
|
3393
|
+
output += formatString;
|
|
3394
|
+
|
|
3395
|
+
return output;
|
|
2693
3396
|
}
|
|
2694
3397
|
/**
|
|
2695
|
-
*
|
|
2696
|
-
* @
|
|
2697
|
-
* @return {string} The era.
|
|
3398
|
+
* Format the current date using "eee MMM dd yyyy".
|
|
3399
|
+
* @return {string} The formatted date string.
|
|
2698
3400
|
*/
|
|
2699
|
-
function
|
|
2700
|
-
return
|
|
2701
|
-
this.getLocale(),
|
|
2702
|
-
this.getYear() < 0 ?
|
|
2703
|
-
0 :
|
|
2704
|
-
1,
|
|
2705
|
-
type,
|
|
2706
|
-
);
|
|
3401
|
+
function toDateString() {
|
|
3402
|
+
return this.format(formats.date);
|
|
2707
3403
|
}
|
|
2708
3404
|
/**
|
|
2709
|
-
*
|
|
2710
|
-
* @
|
|
2711
|
-
* @param {object} [options] The options for comparing the dates.
|
|
2712
|
-
* @param {string} [options.timeUnit] The unit of time.
|
|
2713
|
-
* @return {string} The difference in human readable form.
|
|
3405
|
+
* Format the current date using "yyyy-MM-dd'THH:mm:ss.SSSSSSxxx".
|
|
3406
|
+
* @return {string} The formatted date string.
|
|
2714
3407
|
*/
|
|
2715
|
-
function
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
3408
|
+
function toISOString() {
|
|
3409
|
+
return this
|
|
3410
|
+
.setLocale('en')
|
|
3411
|
+
.setTimeZone('UTC')
|
|
3412
|
+
.format(formats.rfc3339_extended);
|
|
3413
|
+
}
|
|
3414
|
+
/**
|
|
3415
|
+
* Format the current date using "eee MMM dd yyyy HH:mm:ss xx (VV)".
|
|
3416
|
+
* @return {string} The formatted date string.
|
|
3417
|
+
*/
|
|
3418
|
+
function toString() {
|
|
3419
|
+
return this.format(formats.string);
|
|
3420
|
+
}
|
|
3421
|
+
/**
|
|
3422
|
+
* Format the current date using "HH:mm:ss xx (VV)".
|
|
3423
|
+
* @return {string} The formatted date string.
|
|
3424
|
+
*/
|
|
3425
|
+
function toTimeString() {
|
|
3426
|
+
return this.format(formats.time);
|
|
3427
|
+
}
|
|
3428
|
+
/**
|
|
3429
|
+
* Format the current date in UTC timeZone using "eee MMM dd yyyy HH:mm:ss xx (VV)".
|
|
3430
|
+
* @return {string} The formatted date string.
|
|
3431
|
+
*/
|
|
3432
|
+
function toUTCString() {
|
|
3433
|
+
return this
|
|
3434
|
+
.setLocale('en')
|
|
3435
|
+
.setTimeZone('UTC')
|
|
3436
|
+
.toString();
|
|
3437
|
+
}
|
|
2725
3438
|
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
} else {
|
|
2730
|
-
[amount, timeUnit] = getBiggestDiff(this, other);
|
|
2731
|
-
}
|
|
3439
|
+
/**
|
|
3440
|
+
* DateTime Utility
|
|
3441
|
+
*/
|
|
2732
3442
|
|
|
2733
|
-
|
|
3443
|
+
/**
|
|
3444
|
+
* Get the name of the day of the week in current timeZone.
|
|
3445
|
+
* @param {string} [type=long] The type of day name to return.
|
|
3446
|
+
* @return {string} The name of the day of the week.
|
|
3447
|
+
*/
|
|
3448
|
+
function dayName(type = 'long') {
|
|
3449
|
+
return formatDay(this.getLocale(), this.getDay(), type);
|
|
2734
3450
|
}
|
|
2735
3451
|
/**
|
|
2736
|
-
*
|
|
2737
|
-
* @param {
|
|
2738
|
-
* @
|
|
2739
|
-
* @param {string} [options.granularity] The level of granularity to use for comparison.
|
|
2740
|
-
* @return {Boolean} TRUE if this DateTime is after the other date, otherwise FALSE.
|
|
3452
|
+
* Get the day period in current timeZone.
|
|
3453
|
+
* @param {string} [type=long] The type of day period to return.
|
|
3454
|
+
* @return {string} The day period.
|
|
2741
3455
|
*/
|
|
2742
|
-
function
|
|
2743
|
-
return
|
|
3456
|
+
function dayPeriod(type = 'long') {
|
|
3457
|
+
return formatDayPeriod(
|
|
3458
|
+
this.getLocale(),
|
|
3459
|
+
this.getHours() < 12 ?
|
|
3460
|
+
0 :
|
|
3461
|
+
1,
|
|
3462
|
+
type,
|
|
3463
|
+
);
|
|
2744
3464
|
}
|
|
2745
3465
|
/**
|
|
2746
|
-
*
|
|
2747
|
-
* @
|
|
2748
|
-
* @param {object} [options] The options for comparing the dates.
|
|
2749
|
-
* @param {string} [options.granularity] The level of granularity to use for comparison.
|
|
2750
|
-
* @return {Boolean} TRUE if this DateTime is before the other date, otherwise FALSE.
|
|
3466
|
+
* Get the number of days in the current month.
|
|
3467
|
+
* @return {number} The number of days in the current month.
|
|
2751
3468
|
*/
|
|
2752
|
-
function
|
|
2753
|
-
return
|
|
3469
|
+
function daysInMonth() {
|
|
3470
|
+
return daysInMonth$1(
|
|
3471
|
+
this.getYear(),
|
|
3472
|
+
this.getMonth(),
|
|
3473
|
+
);
|
|
2754
3474
|
}
|
|
2755
3475
|
/**
|
|
2756
|
-
*
|
|
2757
|
-
* @
|
|
2758
|
-
* @param {DateTime} [end] The second date to compare to.
|
|
2759
|
-
* @param {object} [options] The options for comparing the dates.
|
|
2760
|
-
* @param {string} [options.granularity] The level of granularity to use for comparison.
|
|
2761
|
-
* @return {Boolean} TRUE if this DateTime is between the other dates, otherwise FALSE.
|
|
3476
|
+
* Get the number of days in the current year.
|
|
3477
|
+
* @return {number} The number of days in the current year.
|
|
2762
3478
|
*/
|
|
2763
|
-
function
|
|
2764
|
-
return
|
|
3479
|
+
function daysInYear() {
|
|
3480
|
+
return daysInYear$1(
|
|
3481
|
+
this.getYear(),
|
|
3482
|
+
);
|
|
3483
|
+
}
|
|
3484
|
+
/**
|
|
3485
|
+
* Get the era in current timeZone.
|
|
3486
|
+
* @param {string} [type=long] The type of era to return.
|
|
3487
|
+
* @return {string} The era.
|
|
3488
|
+
*/
|
|
3489
|
+
function era(type = 'long') {
|
|
3490
|
+
return formatEra(
|
|
3491
|
+
this.getLocale(),
|
|
3492
|
+
this.getYear() < 0 ?
|
|
3493
|
+
0 :
|
|
3494
|
+
1,
|
|
3495
|
+
type,
|
|
3496
|
+
);
|
|
2765
3497
|
}
|
|
2766
3498
|
/**
|
|
2767
3499
|
* Return true if the DateTime is in daylight savings.
|
|
@@ -2791,36 +3523,6 @@
|
|
|
2791
3523
|
this.getYear(),
|
|
2792
3524
|
);
|
|
2793
3525
|
}
|
|
2794
|
-
/**
|
|
2795
|
-
* Determine whether this DateTime is the same as another date (optionally to a granularity).
|
|
2796
|
-
* @param {DateTime} [other] The date to compare to.
|
|
2797
|
-
* @param {object} [options] The options for comparing the dates.
|
|
2798
|
-
* @param {string} [options.granularity] The level of granularity to use for comparison.
|
|
2799
|
-
* @return {Boolean} TRUE if this DateTime is the same as the other date, otherwise FALSE.
|
|
2800
|
-
*/
|
|
2801
|
-
function isSame(other, { granularity } = {}) {
|
|
2802
|
-
return this.diff(other, { timeUnit: granularity }) === 0;
|
|
2803
|
-
}
|
|
2804
|
-
/**
|
|
2805
|
-
* Determine whether this DateTime is the same or after another date (optionally to a granularity).
|
|
2806
|
-
* @param {DateTime} [other] The date to compare to.
|
|
2807
|
-
* @param {object} [options] The options for comparing the dates.
|
|
2808
|
-
* @param {string} [options.granularity] The level of granularity to use for comparison.
|
|
2809
|
-
* @return {Boolean} TRUE if this DateTime is the same or after the other date, otherwise FALSE.
|
|
2810
|
-
*/
|
|
2811
|
-
function isSameOrAfter(other, { granularity } = {}) {
|
|
2812
|
-
return this.diff(other, { timeUnit: granularity }) >= 0;
|
|
2813
|
-
}
|
|
2814
|
-
/**
|
|
2815
|
-
* Determine whether this DateTime is the same or before another date.
|
|
2816
|
-
* @param {DateTime} other The date to compare to.
|
|
2817
|
-
* @param {object} [options] The options for comparing the dates.
|
|
2818
|
-
* @param {string} [options.granularity] The level of granularity to use for comparison.
|
|
2819
|
-
* @return {Boolean} TRUE if this DateTime is the same or before the other date, otherwise FALSE.
|
|
2820
|
-
*/
|
|
2821
|
-
function isSameOrBefore(other, { granularity } = {}) {
|
|
2822
|
-
return this.diff(other, { timeUnit: granularity }) <= 0;
|
|
2823
|
-
}
|
|
2824
3526
|
/**
|
|
2825
3527
|
* Get the name of the month in current timeZone.
|
|
2826
3528
|
* @param {string} [type=long] The type of month name to return.
|
|
@@ -2866,13 +3568,40 @@
|
|
|
2866
3568
|
|
|
2867
3569
|
const proto = DateTime.prototype;
|
|
2868
3570
|
|
|
2869
|
-
proto.
|
|
3571
|
+
proto.addDay = addDay;
|
|
3572
|
+
proto.addDays = addDays;
|
|
3573
|
+
proto.addHour = addHour;
|
|
3574
|
+
proto.addHours = addHours;
|
|
3575
|
+
proto.addMinute = addMinute;
|
|
3576
|
+
proto.addMinutes = addMinutes;
|
|
3577
|
+
proto.addMonth = addMonth;
|
|
3578
|
+
proto.addMonths = addMonths;
|
|
3579
|
+
proto.addSecond = addSecond;
|
|
3580
|
+
proto.addSeconds = addSeconds;
|
|
3581
|
+
proto.addWeek = addWeek;
|
|
3582
|
+
proto.addWeeks = addWeeks;
|
|
3583
|
+
proto.addYear = addYear;
|
|
3584
|
+
proto.addYears = addYears;
|
|
2870
3585
|
proto.dayName = dayName;
|
|
2871
3586
|
proto.dayPeriod = dayPeriod;
|
|
2872
3587
|
proto.daysInMonth = daysInMonth;
|
|
2873
3588
|
proto.daysInYear = daysInYear;
|
|
2874
3589
|
proto.diff = diff;
|
|
2875
|
-
proto.
|
|
3590
|
+
proto.diffInDays = diffInDays;
|
|
3591
|
+
proto.diffInHours = diffInHours;
|
|
3592
|
+
proto.diffInMinutes = diffInMinutes;
|
|
3593
|
+
proto.diffInMonths = diffInMonths;
|
|
3594
|
+
proto.diffInSeconds = diffInSeconds;
|
|
3595
|
+
proto.diffInWeeks = diffInWeeks;
|
|
3596
|
+
proto.diffInYears = diffInYears;
|
|
3597
|
+
proto.endOfDay = endOfDay;
|
|
3598
|
+
proto.endOfHour = endOfHour;
|
|
3599
|
+
proto.endOfMinute = endOfMinute;
|
|
3600
|
+
proto.endOfMonth = endOfMonth;
|
|
3601
|
+
proto.endOfQuarter = endOfQuarter;
|
|
3602
|
+
proto.endOfSecond = endOfSecond;
|
|
3603
|
+
proto.endOfWeek = endOfWeek;
|
|
3604
|
+
proto.endOfYear = endOfYear;
|
|
2876
3605
|
proto.era = era;
|
|
2877
3606
|
proto.format = format;
|
|
2878
3607
|
proto.getDate = getDate;
|
|
@@ -2892,14 +3621,63 @@
|
|
|
2892
3621
|
proto.getWeekYear = getWeekYear;
|
|
2893
3622
|
proto.getYear = getYear;
|
|
2894
3623
|
proto.humanDiff = humanDiff;
|
|
3624
|
+
proto.humanDiffInDays = humanDiffInDays;
|
|
3625
|
+
proto.humanDiffInHours = humanDiffInHours;
|
|
3626
|
+
proto.humanDiffInMinutes = humanDiffInMinutes;
|
|
3627
|
+
proto.humanDiffInMonths = humanDiffInMonths;
|
|
3628
|
+
proto.humanDiffInSeconds = humanDiffInSeconds;
|
|
3629
|
+
proto.humanDiffInWeeks = humanDiffInWeeks;
|
|
3630
|
+
proto.humanDiffInYears = humanDiffInYears;
|
|
2895
3631
|
proto.isAfter = isAfter;
|
|
3632
|
+
proto.isAfterDay = isAfterDay;
|
|
3633
|
+
proto.isAfterHour = isAfterHour;
|
|
3634
|
+
proto.isAfterMinute = isAfterMinute;
|
|
3635
|
+
proto.isAfterMonth = isAfterMonth;
|
|
3636
|
+
proto.isAfterSecond = isAfterSecond;
|
|
3637
|
+
proto.isAfterWeek = isAfterWeek;
|
|
3638
|
+
proto.isAfterYear = isAfterYear;
|
|
2896
3639
|
proto.isBefore = isBefore;
|
|
3640
|
+
proto.isBeforeDay = isBeforeDay;
|
|
3641
|
+
proto.isBeforeHour = isBeforeHour;
|
|
3642
|
+
proto.isBeforeMinute = isBeforeMinute;
|
|
3643
|
+
proto.isBeforeMonth = isBeforeMonth;
|
|
3644
|
+
proto.isBeforeSecond = isBeforeSecond;
|
|
3645
|
+
proto.isBeforeWeek = isBeforeWeek;
|
|
3646
|
+
proto.isBeforeYear = isBeforeYear;
|
|
2897
3647
|
proto.isBetween = isBetween;
|
|
3648
|
+
proto.isBetweenDay = isBetweenDay;
|
|
3649
|
+
proto.isBetweenHour = isBetweenHour;
|
|
3650
|
+
proto.isBetweenMinute = isBetweenMinute;
|
|
3651
|
+
proto.isBetweenMonth = isBetweenMonth;
|
|
3652
|
+
proto.isBetweenSecond = isBetweenSecond;
|
|
3653
|
+
proto.isBetweenWeek = isBetweenWeek;
|
|
3654
|
+
proto.isBetweenYear = isBetweenYear;
|
|
2898
3655
|
proto.isDST = isDST;
|
|
2899
3656
|
proto.isLeapYear = isLeapYear;
|
|
2900
3657
|
proto.isSame = isSame;
|
|
3658
|
+
proto.isSameDay = isSameDay;
|
|
3659
|
+
proto.isSameHour = isSameHour;
|
|
3660
|
+
proto.isSameMinute = isSameMinute;
|
|
3661
|
+
proto.isSameMonth = isSameMonth;
|
|
3662
|
+
proto.isSameSecond = isSameSecond;
|
|
3663
|
+
proto.isSameWeek = isSameWeek;
|
|
3664
|
+
proto.isSameYear = isSameYear;
|
|
2901
3665
|
proto.isSameOrAfter = isSameOrAfter;
|
|
3666
|
+
proto.isSameOrAfterDay = isSameOrAfterDay;
|
|
3667
|
+
proto.isSameOrAfterHour = isSameOrAfterHour;
|
|
3668
|
+
proto.isSameOrAfterMinute = isSameOrAfterMinute;
|
|
3669
|
+
proto.isSameOrAfterMonth = isSameOrAfterMonth;
|
|
3670
|
+
proto.isSameOrAfterSecond = isSameOrAfterSecond;
|
|
3671
|
+
proto.isSameOrAfterWeek = isSameOrAfterWeek;
|
|
3672
|
+
proto.isSameOrAfterYear = isSameOrAfterYear;
|
|
2902
3673
|
proto.isSameOrBefore = isSameOrBefore;
|
|
3674
|
+
proto.isSameOrBeforeDay = isSameOrBeforeDay;
|
|
3675
|
+
proto.isSameOrBeforeHour = isSameOrBeforeHour;
|
|
3676
|
+
proto.isSameOrBeforeMinute = isSameOrBeforeMinute;
|
|
3677
|
+
proto.isSameOrBeforeMonth = isSameOrBeforeMonth;
|
|
3678
|
+
proto.isSameOrBeforeSecond = isSameOrBeforeSecond;
|
|
3679
|
+
proto.isSameOrBeforeWeek = isSameOrBeforeWeek;
|
|
3680
|
+
proto.isSameOrBeforeYear = isSameOrBeforeYear;
|
|
2903
3681
|
proto.monthName = monthName;
|
|
2904
3682
|
proto.setDate = setDate;
|
|
2905
3683
|
proto.setDay = setDay;
|
|
@@ -2917,8 +3695,28 @@
|
|
|
2917
3695
|
proto.setWeekOfMonth = setWeekOfMonth;
|
|
2918
3696
|
proto.setWeekYear = setWeekYear;
|
|
2919
3697
|
proto.setYear = setYear;
|
|
2920
|
-
proto.
|
|
2921
|
-
proto.
|
|
3698
|
+
proto.startOfDay = startOfDay;
|
|
3699
|
+
proto.startOfHour = startOfHour;
|
|
3700
|
+
proto.startOfMinute = startOfMinute;
|
|
3701
|
+
proto.startOfMonth = startOfMonth;
|
|
3702
|
+
proto.startOfQuarter = startOfQuarter;
|
|
3703
|
+
proto.startOfSecond = startOfSecond;
|
|
3704
|
+
proto.startOfWeek = startOfWeek;
|
|
3705
|
+
proto.startOfYear = startOfYear;
|
|
3706
|
+
proto.subDay = subDay;
|
|
3707
|
+
proto.subDays = subDays;
|
|
3708
|
+
proto.subHour = subHour;
|
|
3709
|
+
proto.subHours = subHours;
|
|
3710
|
+
proto.subMinute = subMinute;
|
|
3711
|
+
proto.subMinutes = subMinutes;
|
|
3712
|
+
proto.subMonth = subMonth;
|
|
3713
|
+
proto.subMonths = subMonths;
|
|
3714
|
+
proto.subSecond = subSecond;
|
|
3715
|
+
proto.subSeconds = subSeconds;
|
|
3716
|
+
proto.subWeek = subWeek;
|
|
3717
|
+
proto.subWeeks = subWeeks;
|
|
3718
|
+
proto.subYear = subYear;
|
|
3719
|
+
proto.subYears = subYears;
|
|
2922
3720
|
proto.timeZoneName = timeZoneName;
|
|
2923
3721
|
proto.toDateString = toDateString;
|
|
2924
3722
|
proto.toISOString = toISOString;
|