1 | import {
|
2 | CalendarSystem,
|
3 | DateTimeFormatOptions,
|
4 | NumberingSystem,
|
5 | StringUnitLength,
|
6 | ToISOFormat,
|
7 | ToISOTimeDurationOptions,
|
8 | ZoneOptions,
|
9 | } from "../index";
|
10 | import { CanBeInvalid, DefaultValidity, IfValid, Invalid, Valid } from "./_util";
|
11 | import { Duration, DurationLike, DurationUnits } from "./duration";
|
12 | import { Interval } from "./interval";
|
13 | import { Zone } from "./zone";
|
14 |
|
15 | export type DateTimeUnit = "year" | "quarter" | "month" | "week" | "day" | "hour" | "minute" | "second" | "millisecond";
|
16 | export type ToRelativeUnit = "years" | "quarters" | "months" | "weeks" | "days" | "hours" | "minutes" | "seconds";
|
17 |
|
18 | export type MonthNumbers = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
|
19 | export type WeekdayNumbers = 1 | 2 | 3 | 4 | 5 | 6 | 7;
|
20 |
|
21 | export type DayNumbers =
|
22 | | 1
|
23 | | 2
|
24 | | 3
|
25 | | 4
|
26 | | 5
|
27 | | 6
|
28 | | 7
|
29 | | 8
|
30 | | 9
|
31 | | 10
|
32 | | 11
|
33 | | 12
|
34 | | 13
|
35 | | 14
|
36 | | 15
|
37 | | 16
|
38 | | 17
|
39 | | 18
|
40 | | 19
|
41 | | 20
|
42 | | 21
|
43 | | 22
|
44 | | 23
|
45 | | 24
|
46 | | 25
|
47 | | 26
|
48 | | 27
|
49 | | 28
|
50 | | 29
|
51 | | 30
|
52 | | 31;
|
53 |
|
54 | export type SecondNumbers =
|
55 | | 0
|
56 | | 1
|
57 | | 2
|
58 | | 3
|
59 | | 4
|
60 | | 5
|
61 | | 6
|
62 | | 7
|
63 | | 8
|
64 | | 9
|
65 | | 10
|
66 | | 11
|
67 | | 12
|
68 | | 13
|
69 | | 14
|
70 | | 15
|
71 | | 16
|
72 | | 17
|
73 | | 18
|
74 | | 19
|
75 | | 20
|
76 | | 21
|
77 | | 22
|
78 | | 23
|
79 | | 24
|
80 | | 25
|
81 | | 26
|
82 | | 27
|
83 | | 28
|
84 | | 29
|
85 | | 30
|
86 | | 31
|
87 | | 32
|
88 | | 33
|
89 | | 34
|
90 | | 35
|
91 | | 36
|
92 | | 37
|
93 | | 38
|
94 | | 39
|
95 | | 40
|
96 | | 41
|
97 | | 42
|
98 | | 43
|
99 | | 44
|
100 | | 45
|
101 | | 46
|
102 | | 47
|
103 | | 48
|
104 | | 49
|
105 | | 50
|
106 | | 51
|
107 | | 52
|
108 | | 53
|
109 | | 54
|
110 | | 55
|
111 | | 56
|
112 | | 57
|
113 | | 58
|
114 | | 59;
|
115 |
|
116 | export type MinuteNumbers = SecondNumbers;
|
117 |
|
118 | export type HourNumbers =
|
119 | | 0
|
120 | | 1
|
121 | | 2
|
122 | | 3
|
123 | | 4
|
124 | | 5
|
125 | | 6
|
126 | | 7
|
127 | | 8
|
128 | | 9
|
129 | | 10
|
130 | | 11
|
131 | | 12
|
132 | | 13
|
133 | | 14
|
134 | | 15
|
135 | | 16
|
136 | | 17
|
137 | | 18
|
138 | | 19
|
139 | | 20
|
140 | | 21
|
141 | | 22
|
142 | | 23;
|
143 |
|
144 | export type WeekNumbers =
|
145 | | 1
|
146 | | 2
|
147 | | 3
|
148 | | 4
|
149 | | 5
|
150 | | 6
|
151 | | 7
|
152 | | 8
|
153 | | 9
|
154 | | 10
|
155 | | 11
|
156 | | 12
|
157 | | 13
|
158 | | 14
|
159 | | 15
|
160 | | 16
|
161 | | 17
|
162 | | 18
|
163 | | 19
|
164 | | 20
|
165 | | 21
|
166 | | 22
|
167 | | 23
|
168 | | 24
|
169 | | 25
|
170 | | 26
|
171 | | 27
|
172 | | 28
|
173 | | 29
|
174 | | 30
|
175 | | 31
|
176 | | 32
|
177 | | 33
|
178 | | 34
|
179 | | 35
|
180 | | 36
|
181 | | 37
|
182 | | 38
|
183 | | 39
|
184 | | 40
|
185 | | 41
|
186 | | 42
|
187 | | 43
|
188 | | 44
|
189 | | 45
|
190 | | 46
|
191 | | 47
|
192 | | 48
|
193 | | 49
|
194 | | 50
|
195 | | 51
|
196 | | 52
|
197 | | 53;
|
198 |
|
199 | export type QuarterNumbers = 1 | 2 | 3 | 4;
|
200 |
|
201 | export type PossibleDaysInMonth = 28 | 29 | 30 | 31;
|
202 | export type PossibleDaysInYear = 365 | 366;
|
203 | export type PossibleWeeksInYear = 52 | 53;
|
204 |
|
205 | export type ToObjectOutput<
|
206 | IncludeConfig extends boolean | undefined = undefined,
|
207 | IsValid extends boolean | undefined = undefined,
|
208 | > = IsValid extends true ? _ToObjectOutput<IncludeConfig>
|
209 | : CanBeInvalid extends false ? _ToObjectOutput<IncludeConfig>
|
210 | : Partial<_ToObjectOutput<IncludeConfig>>;
|
211 | /** @internal */
|
212 | export type _ToObjectOutput<IncludeConfig extends boolean | undefined = undefined> =
|
213 | & Record<_ToObjectUnit, number>
|
214 | & (IncludeConfig extends true ? LocaleOptions : unknown);
|
215 | /** @internal */
|
216 | export type _ToObjectUnit = Exclude<DateTimeUnit, "quarter" | "week">;
|
217 |
|
218 | export interface ToRelativeOptions extends Omit<ToRelativeCalendarOptions, "unit"> {
|
219 | /**
|
220 | * @default long
|
221 | */
|
222 | style?: StringUnitLength | undefined;
|
223 | /** @default true */
|
224 | round?: boolean | undefined;
|
225 | /**
|
226 | * Padding in milliseconds. This allows you to round up the result if it fits inside the threshold.
|
227 | * Do not use this in combination with `{round: false}` because the decimal output will include the padding.
|
228 | * @default 0
|
229 | */
|
230 | padding?: number | undefined;
|
231 | /**
|
232 | * A single unit or an array of units. If an array is supplied, the method will pick the best one
|
233 | * to use from the array. If omitted, the method will pick the unit from a default set.
|
234 | */
|
235 | unit?: ToRelativeUnit | ToRelativeUnit[] | undefined;
|
236 | }
|
237 |
|
238 | export interface ToRelativeCalendarOptions {
|
239 | /**
|
240 | * The DateTime to use as the basis to which this time is compared
|
241 | * @default now
|
242 | */
|
243 | base?: DateTime | undefined;
|
244 | /**
|
245 | * Override the locale of this DateTime
|
246 | */
|
247 | locale?: string | undefined;
|
248 | /** If omitted, the method will pick the unit. */
|
249 | unit?: ToRelativeUnit | undefined;
|
250 | /**
|
251 | * Override the numberingSystem of this DateTime.
|
252 | * The Intl system may choose not to honor this.
|
253 | */
|
254 | numberingSystem?: NumberingSystem | undefined;
|
255 | }
|
256 |
|
257 | export interface ToSQLOptions {
|
258 | /**
|
259 | * Include the offset, such as 'Z' or '-04:00'
|
260 | * @default true
|
261 | */
|
262 | includeOffset?: boolean | undefined;
|
263 | /**
|
264 | * Include the zone, such as 'America/New_York'. Overrides includeOffset.
|
265 | * @default false
|
266 | */
|
267 | includeZone?: boolean | undefined;
|
268 | /**
|
269 | * include the space between the time and the offset, such as '05:15:16.345 -04:00'
|
270 | * @default true
|
271 | */
|
272 | includeOffsetSpace?: boolean;
|
273 | }
|
274 |
|
275 | export interface ToISODateOptions {
|
276 | /**
|
277 | * Choose between the basic and extended format
|
278 | * @default 'extended'
|
279 | */
|
280 | format?: ToISOFormat | undefined;
|
281 | }
|
282 |
|
283 | export interface ToISOTimeOptions extends ToISOTimeDurationOptions {
|
284 | /**
|
285 | * Include the offset, such as 'Z' or '-04:00'
|
286 | * @default true
|
287 | */
|
288 | includeOffset?: boolean | undefined;
|
289 |
|
290 | /**
|
291 | * add the time zone format extension
|
292 | * @default false
|
293 | */
|
294 | extendedZone?: boolean | undefined;
|
295 | }
|
296 |
|
297 | /** @deprecated alias for backwards compatibility */
|
298 | export type ISOTimeOptions = ToISOTimeOptions;
|
299 |
|
300 | export interface LocaleOptions {
|
301 | /**
|
302 | * @default system's locale
|
303 | */
|
304 | locale?: string | undefined;
|
305 | outputCalendar?: CalendarSystem | undefined;
|
306 | numberingSystem?: NumberingSystem | undefined;
|
307 | }
|
308 |
|
309 | export type ResolvedLocaleOptions = Required<LocaleOptions>;
|
310 |
|
311 | export interface DateTimeOptions extends LocaleOptions {
|
312 | /**
|
313 | * Use this zone if no offset is specified in the input string itself. Will also convert the time to this zone.
|
314 | * @default local
|
315 | */
|
316 | zone?: string | Zone | undefined;
|
317 | /**
|
318 | * Override the zone with a fixed-offset zone specified in the string itself, if it specifies one.
|
319 | * @default false
|
320 | */
|
321 | setZone?: boolean | undefined;
|
322 | }
|
323 |
|
324 | export type DateTimeJSOptions = Omit<DateTimeOptions, "setZone">;
|
325 |
|
326 | /**
|
327 | * Note that ISO weekday and local weekday fields are mutually exclusive
|
328 | */
|
329 | export interface DateObjectUnits {
|
330 | // a year, such as 1987
|
331 | year?: number | undefined;
|
332 | // a month, 1-12
|
333 | month?: number | undefined;
|
334 | // a day of the month, 1-31, depending on the month
|
335 | day?: number | undefined;
|
336 | // day of the year, 1-365 or 366
|
337 | ordinal?: number | undefined;
|
338 | // an ISO week year
|
339 | weekYear?: number | undefined;
|
340 | // a week year, according to the locale
|
341 | localWeekYear?: number | undefined;
|
342 | // an ISO week number, between 1 and 52 or 53, depending on the year
|
343 | weekNumber?: number | undefined;
|
344 | // a week number, between 1 and 52 or 53, depending on the year, according to the locale
|
345 | localWeekNumber?: number | undefined;
|
346 | // an ISO weekday, 1-7, where 1 is Monday and 7 is Sunday
|
347 | weekday?: WeekdayNumbers | undefined;
|
348 | // a weekday, 1-7, where 1 is the first day of the week, and 7 is the last, according to the locale
|
349 | localWeekday?: WeekdayNumbers | undefined;
|
350 | // hour of the day, 0-23
|
351 | hour?: number | undefined;
|
352 | // minute of the hour, 0-59
|
353 | minute?: number | undefined;
|
354 | // second of the minute, 0-59
|
355 | second?: number | undefined;
|
356 | // millisecond of the second, 0-999
|
357 | millisecond?: number | undefined;
|
358 | }
|
359 |
|
360 | export type ConversionAccuracy = "casual" | "longterm";
|
361 |
|
362 | /**
|
363 | * @deprecated You should use `Intl.DateTimeFormatOptions` fields and values instead.
|
364 | */
|
365 | export type DateTimeFormatPresetValue = "numeric" | "short" | "long";
|
366 | /**
|
367 | * @deprecated Use `Intl.DateTimeFormatOptions` instead.
|
368 | */
|
369 | export type DateTimeFormatPreset = Intl.DateTimeFormatOptions;
|
370 |
|
371 | export interface DiffOptions {
|
372 | /**
|
373 | * @default 'casual'
|
374 | */
|
375 | conversionAccuracy?: ConversionAccuracy | undefined;
|
376 | }
|
377 |
|
378 | export interface _UseLocaleWeekOption {
|
379 | /** If true, use weeks based on the locale, i.e., use the locale-dependent start of the week */
|
380 | useLocaleWeeks?: boolean;
|
381 | }
|
382 |
|
383 | export type HasSameOptions = _UseLocaleWeekOption;
|
384 | export type StartOfOptions = _UseLocaleWeekOption;
|
385 | export type EndOfOptions = _UseLocaleWeekOption;
|
386 |
|
387 | export interface ExplainedFormat {
|
388 | input: string;
|
389 | tokens: Array<{ literal: boolean; val: string }>;
|
390 | regex?: RegExp | undefined;
|
391 | rawMatches?: RegExpMatchArray | null | undefined;
|
392 | matches?: { [k: string]: any } | undefined;
|
393 | result?: { [k: string]: any } | null | undefined;
|
394 | zone?: Zone | null | undefined;
|
395 | invalidReason?: string | undefined;
|
396 | }
|
397 |
|
398 | export type DateTimeMaybeValid = CanBeInvalid extends true ? (DateTime<Valid> | DateTime<Invalid>) : DateTime;
|
399 |
|
400 | /**
|
401 | * A DateTime is an immutable data structure representing a specific date and time and accompanying methods.
|
402 | * It contains class and instance methods for creating, parsing, interrogating, transforming, and formatting them.
|
403 | *
|
404 | * A DateTime consists of the following parts:
|
405 | * * A timestamp. Each DateTime instance refers to a specific millisecond of the Unix epoch.
|
406 | * * A time zone. Each instance is considered in the context of a specific zone (by default, the local system's zone).
|
407 | * * Configuration properties that affect how output strings are formatted, such as `locale`, `numberingSystem`, and `outputCalendar`.
|
408 | *
|
409 | * Here is a brief overview of the most commonly used functionality it provides:
|
410 | *
|
411 | * * **Creation**: To create a DateTime from its components, use one of its factory class methods: {@link DateTime.local}, {@link DateTime.utc}, and (most flexibly) {@link DateTime.fromObject}.
|
412 | * To create one from a standard string format, use {@link DateTime.fromISO}, {@link DateTime.fromHTTP}, and {@link DateTime.fromRFC2822}.
|
413 | * To create one from a custom string format, use {@link DateTime.fromFormat}. To create one from a native JS date, use {@link DateTime.fromJSDate}.
|
414 | * * **Gregorian calendar and time**: To examine the Gregorian properties of a DateTime individually (i.e. as opposed to collectively through {@link DateTime#toObject}), use the {@link DateTime#year},
|
415 | * {@link DateTime#month}, {@link DateTime#day}, {@link DateTime#hour}, {@link DateTime#minute}, {@link DateTime#second}, {@link DateTime#millisecond} accessors.
|
416 | * * **Week calendar**: For ISO week calendar attributes, see the {@link DateTime#weekYear}, {@link DateTime#weekNumber}, and {@link DateTime#weekday} accessors.
|
417 | * * **Configuration** See the {@link DateTime#locale} and {@link DateTime#numberingSystem} accessors.
|
418 | * * **Transformation**: To transform the DateTime into other DateTimes, use {@link DateTime#set}, {@link DateTime#reconfigure}, {@link DateTime#setZone}, {@link DateTime#setLocale},
|
419 | * {@link DateTime.plus}, {@link DateTime#minus}, {@link DateTime#endOf}, {@link DateTime#startOf}, {@link DateTime#toUTC}, and {@link DateTime#toLocal}.
|
420 | * * **Output**: To convert the DateTime to other representations, use the {@link DateTime#toRelative}, {@link DateTime#toRelativeCalendar}, {@link DateTime#toJSON}, {@link DateTime#toISO},
|
421 | * {@link DateTime#toHTTP}, {@link DateTime#toObject}, {@link DateTime#toRFC2822}, {@link DateTime#toString}, {@link DateTime#toLocaleString}, {@link DateTime#toFormat},
|
422 | * {@link DateTime#toMillis} and {@link DateTime#toJSDate}.
|
423 | *
|
424 | * There's plenty others documented below. In addition, for more information on subtler topics
|
425 | * like internationalization, time zones, alternative calendars, validity, and so on, see the external documentation.
|
426 | */
|
427 | export class DateTime<IsValid extends boolean = DefaultValidity> {
|
428 | /**
|
429 | * Create a DateTime for the current instant, in the system's time zone.
|
430 | *
|
431 | * Use Settings to override these default values if needed.
|
432 | * @example
|
433 | * DateTime.now().toISO() //~> now in the ISO format
|
434 | */
|
435 | static now(): DateTime<Valid>;
|
436 |
|
437 | /**
|
438 | * Create a local DateTime
|
439 | *
|
440 | * @param year - The calendar year. If omitted (as in, call `local()` with no arguments), the current time will be used
|
441 | * @param month - The month, 1-indexed
|
442 | * @param day - The day of the month, 1-indexed
|
443 | * @param hour - The hour of the day, in 24-hour time
|
444 | * @param minute - The minute of the hour, meaning a number between 0 and 59
|
445 | * @param second - The second of the minute, meaning a number between 0 and 59
|
446 | * @param millisecond - The millisecond of the second, meaning a number between 0 and 999
|
447 | * @param opts
|
448 | *
|
449 | * @example
|
450 | * DateTime.local() //~> now
|
451 | * @example
|
452 | * DateTime.local({ zone: "America/New_York" }) //~> now, in US east coast time
|
453 | * @example
|
454 | * DateTime.local(2017) //~> 2017-01-01T00:00:00
|
455 | * @example
|
456 | * DateTime.local(2017, 3) //~> 2017-03-01T00:00:00
|
457 | * @example
|
458 | * DateTime.local(2017, 3, 12, { locale: "fr") //~> 2017-03-12T00:00:00, with a French locale
|
459 | * @example
|
460 | * DateTime.local(2017, 3, 12, 5) //~> 2017-03-12T05:00:00
|
461 | * @example
|
462 | * DateTime.local(2017, 3, 12, 5, { zone: "utc" }) //~> 2017-03-12T05:00:00, in UTC
|
463 | * @example
|
464 | * DateTime.local(2017, 3, 12, 5, 45) //~> 2017-03-12T05:45:00
|
465 | * @example
|
466 | * DateTime.local(2017, 3, 12, 5, 45, 10) //~> 2017-03-12T05:45:10
|
467 | * @example
|
468 | * DateTime.local(2017, 3, 12, 5, 45, 10, 765) //~> 2017-03-12T05:45:10.765
|
469 | */
|
470 | static local(
|
471 | year: number,
|
472 | month: number,
|
473 | day: number,
|
474 | hour: number,
|
475 | minute: number,
|
476 | second: number,
|
477 | millisecond: number,
|
478 | opts?: DateTimeJSOptions,
|
479 | ): DateTimeMaybeValid;
|
480 | static local(
|
481 | year: number,
|
482 | month: number,
|
483 | day: number,
|
484 | hour: number,
|
485 | minute: number,
|
486 | second: number,
|
487 | opts?: DateTimeJSOptions,
|
488 | ): DateTimeMaybeValid;
|
489 | static local(
|
490 | year: number,
|
491 | month: number,
|
492 | day: number,
|
493 | hour: number,
|
494 | minute: number,
|
495 | opts?: DateTimeJSOptions,
|
496 | ): DateTimeMaybeValid;
|
497 | static local(year: number, month: number, day: number, hour: number, opts?: DateTimeJSOptions): DateTimeMaybeValid;
|
498 | static local(year: number, month: number, day: number, opts?: DateTimeJSOptions): DateTimeMaybeValid;
|
499 | static local(year: number, month: number, opts?: DateTimeJSOptions): DateTimeMaybeValid;
|
500 | static local(year: number, opts?: DateTimeJSOptions): DateTimeMaybeValid;
|
501 | static local(opts?: DateTimeJSOptions): DateTime<Valid>;
|
502 |
|
503 | /**
|
504 | * Create a DateTime in UTC
|
505 | *
|
506 | * @param year - The calendar year. If omitted (as in, call `utc()` with no arguments), the current time will be used
|
507 | * @param month - The month, 1-indexed
|
508 | * @param day - The day of the month
|
509 | * @param hour - The hour of the day, in 24-hour time
|
510 | * @param minute - The minute of the hour, meaning a number between 0 and 59
|
511 | * @param second - The second of the minute, meaning a number between 0 and 59
|
512 | * @param millisecond - The millisecond of the second, meaning a number between 0 and 999
|
513 | * @param options - configuration options for the DateTime
|
514 | * @param options.locale - a locale to set on the resulting DateTime instance
|
515 | * @param options.outputCalendar - the output calendar to set on the resulting DateTime instance
|
516 | * @param options.numberingSystem - the numbering system to set on the resulting DateTime instance
|
517 | *
|
518 | * @example
|
519 | * DateTime.utc() //~> now
|
520 | * @example
|
521 | * DateTime.utc(2017) //~> 2017-01-01T00:00:00Z
|
522 | * @example
|
523 | * DateTime.utc(2017, 3) //~> 2017-03-01T00:00:00Z
|
524 | * @example
|
525 | * DateTime.utc(2017, 3, 12) //~> 2017-03-12T00:00:00Z
|
526 | * @example
|
527 | * DateTime.utc(2017, 3, 12, 5) //~> 2017-03-12T05:00:00Z
|
528 | * @example
|
529 | * DateTime.utc(2017, 3, 12, 5, 45) //~> 2017-03-12T05:45:00Z
|
530 | * @example
|
531 | * DateTime.utc(2017, 3, 12, 5, 45, { locale: "fr" } ) //~> 2017-03-12T05:45:00Z with a French locale
|
532 | * @example
|
533 | * DateTime.utc(2017, 3, 12, 5, 45, 10) //~> 2017-03-12T05:45:10Z
|
534 | * @example
|
535 | * DateTime.utc(2017, 3, 12, 5, 45, 10, 765, { locale: "fr") //~> 2017-03-12T05:45:10.765Z with a French locale
|
536 | */
|
537 | static utc(
|
538 | year: number,
|
539 | month: number,
|
540 | day: number,
|
541 | hour: number,
|
542 | minute: number,
|
543 | second: number,
|
544 | millisecond: number,
|
545 | options?: LocaleOptions,
|
546 | ): DateTimeMaybeValid;
|
547 | static utc(
|
548 | year: number,
|
549 | month: number,
|
550 | day: number,
|
551 | hour: number,
|
552 | minute: number,
|
553 | second: number,
|
554 | options?: LocaleOptions,
|
555 | ): DateTimeMaybeValid;
|
556 | static utc(
|
557 | year: number,
|
558 | month: number,
|
559 | day: number,
|
560 | hour: number,
|
561 | minute: number,
|
562 | options?: LocaleOptions,
|
563 | ): DateTimeMaybeValid;
|
564 | static utc(year: number, month: number, day: number, hour: number, options?: LocaleOptions): DateTimeMaybeValid;
|
565 | static utc(year: number, month: number, day: number, options?: LocaleOptions): DateTimeMaybeValid;
|
566 | static utc(year: number, month: number, options?: LocaleOptions): DateTimeMaybeValid;
|
567 | static utc(year: number, options?: LocaleOptions): DateTimeMaybeValid;
|
568 | static utc(options?: LocaleOptions): DateTime<Valid>;
|
569 |
|
570 | /**
|
571 | * Create a DateTime from a JavaScript Date object. Uses the default zone.
|
572 | *
|
573 | * @param date - a JavaScript Date object
|
574 | * @param options - configuration options for the DateTime
|
575 | * @param options.zone - the zone to place the DateTime into
|
576 | */
|
577 | static fromJSDate(date: Date, options?: { zone?: string | Zone }): DateTimeMaybeValid;
|
578 |
|
579 | /**
|
580 | * Create a DateTime from a number of milliseconds since the epoch (meaning since 1 January 1970 00:00:00 UTC). Uses the default zone.
|
581 | *
|
582 | * @param milliseconds - a number of milliseconds since 1970 UTC
|
583 | * @param options - configuration options for the DateTime
|
584 | * @param options.zone - the zone to place the DateTime into. Defaults to 'local'.
|
585 | * @param options.locale - a locale to set on the resulting DateTime instance
|
586 | * @param options.outputCalendar - the output calendar to set on the resulting DateTime instance
|
587 | * @param options.numberingSystem - the numbering system to set on the resulting DateTime instance
|
588 | */
|
589 | static fromMillis(milliseconds: number, options?: DateTimeJSOptions): DateTimeMaybeValid;
|
590 |
|
591 | /**
|
592 | * Create a DateTime from a number of seconds since the epoch (meaning since 1 January 1970 00:00:00 UTC). Uses the default zone.
|
593 | *
|
594 | * @param seconds - a number of seconds since 1970 UTC
|
595 | * @param options - configuration options for the DateTime
|
596 | * @param options.zone - the zone to place the DateTime into. Defaults to 'local'.
|
597 | * @param options.locale - a locale to set on the resulting DateTime instance
|
598 | * @param options.outputCalendar - the output calendar to set on the resulting DateTime instance
|
599 | * @param options.numberingSystem - the numbering system to set on the resulting DateTime instance
|
600 | */
|
601 | static fromSeconds(seconds: number, options?: DateTimeJSOptions): DateTime<Valid>;
|
602 |
|
603 | /**
|
604 | * Create a DateTime from a JavaScript object with keys like 'year' and 'hour' with reasonable defaults.
|
605 | *
|
606 | * @param obj - the object to create the DateTime from
|
607 | * @param obj.year - a year, such as 1987
|
608 | * @param obj.month - a month, 1-12
|
609 | * @param obj.day - a day of the month, 1-31, depending on the month
|
610 | * @param obj.ordinal - day of the year, 1-365 or 366
|
611 | * @param obj.weekYear - an ISO week year
|
612 | * @param obj.weekNumber - an ISO week number, between 1 and 52 or 53, depending on the year
|
613 | * @param obj.weekday - an ISO weekday, 1-7, where 1 is Monday and 7 is Sunday
|
614 | * @param obj.hour - hour of the day, 0-23
|
615 | * @param obj.minute - minute of the hour, 0-59
|
616 | * @param obj.second - second of the minute, 0-59
|
617 | * @param obj.millisecond - millisecond of the second, 0-999
|
618 | * @param opts - options for creating this DateTime
|
619 | * @param opts.zone - interpret the numbers in the context of a particular zone. Can take any value taken as the first argument to setZone(). Defaults to 'local'.
|
620 | * @param opts.locale - a locale to set on the resulting DateTime instance. Defaults to 'system's locale'.
|
621 | * @param opts.outputCalendar - the output calendar to set on the resulting DateTime instance
|
622 | * @param opts.numberingSystem - the numbering system to set on the resulting DateTime instance
|
623 | *
|
624 | * @example
|
625 | * DateTime.fromObject({ year: 1982, month: 5, day: 25}).toISODate() //=> '1982-05-25'
|
626 | * @example
|
627 | * DateTime.fromObject({ year: 1982 }).toISODate() //=> '1982-01-01'
|
628 | * @example
|
629 | * DateTime.fromObject({ hour: 10, minute: 26, second: 6 }) //=> today at 10:26:06
|
630 | * @example
|
631 | * DateTime.fromObject({ hour: 10, minute: 26, second: 6 }, { zone: 'utc' })
|
632 | * @example
|
633 | * DateTime.fromObject({ hour: 10, minute: 26, second: 6 }, { zone: 'local' })
|
634 | * @example
|
635 | * DateTime.fromObject({ hour: 10, minute: 26, second: 6 }, { zone: 'America/New_York' })
|
636 | * @example
|
637 | * DateTime.fromObject({ weekYear: 2016, weekNumber: 2, weekday: 3 }).toISODate() //=> '2016-01-13'
|
638 | * @example
|
639 | * DateTime.fromObject({ localWeekYear: 2022, localWeekNumber: 1, localWeekday: 1 }, { locale: 'en-US' }).toISODate() //=> '2021-12-26'
|
640 | */
|
641 | static fromObject(obj: DateObjectUnits, opts?: DateTimeJSOptions): DateTimeMaybeValid;
|
642 |
|
643 | /**
|
644 | * Create a DateTime from an ISO 8601 string
|
645 | *
|
646 | * @param text - the ISO string
|
647 | * @param opts - options to affect the creation
|
648 | * @param opts.zone - use this zone if no offset is specified in the input string itself. Will also convert the time to this zone. Defaults to 'local'.
|
649 | * @param opts.setZone - override the zone with a fixed-offset zone specified in the string itself, if it specifies one. Defaults to false.
|
650 | * @param opts.locale - a locale to set on the resulting DateTime instance. Defaults to 'system's locale'.
|
651 | * @param opts.outputCalendar - the output calendar to set on the resulting DateTime instance
|
652 | * @param opts.numberingSystem - the numbering system to set on the resulting DateTime instance
|
653 | *
|
654 | * @example
|
655 | * DateTime.fromISO('2016-05-25T09:08:34.123')
|
656 | * @example
|
657 | * DateTime.fromISO('2016-05-25T09:08:34.123+06:00')
|
658 | * @example
|
659 | * DateTime.fromISO('2016-05-25T09:08:34.123+06:00', {setZone: true})
|
660 | * @example
|
661 | * DateTime.fromISO('2016-05-25T09:08:34.123', {zone: 'utc'})
|
662 | * @example
|
663 | * DateTime.fromISO('2016-W05-4')
|
664 | */
|
665 | static fromISO(text: string, opts?: DateTimeOptions): DateTimeMaybeValid;
|
666 |
|
667 | /**
|
668 | * Create a DateTime from an RFC 2822 string
|
669 | *
|
670 | * @param text - the RFC 2822 string
|
671 | * @param opts - options to affect the creation
|
672 | * @param opts.zone - convert the time to this zone. Since the offset is always specified in the string itself,
|
673 | * this has no effect on the interpretation of string, merely the zone the resulting DateTime is expressed in. Defaults to 'local'
|
674 | * @param opts.setZone - override the zone with a fixed-offset zone specified in the string itself, if it specifies one. Defaults to false.
|
675 | * @param opts.locale - a locale to set on the resulting DateTime instance. Defaults to 'system's locale'.
|
676 | * @param opts.outputCalendar - the output calendar to set on the resulting DateTime instance
|
677 | * @param opts.numberingSystem - the numbering system to set on the resulting DateTime instance
|
678 | *
|
679 | * @example
|
680 | * DateTime.fromRFC2822('25 Nov 2016 13:23:12 GMT')
|
681 | * @example
|
682 | * DateTime.fromRFC2822('Fri, 25 Nov 2016 13:23:12 +0600')
|
683 | * @example
|
684 | * DateTime.fromRFC2822('25 Nov 2016 13:23 Z')
|
685 | */
|
686 | static fromRFC2822(text: string, opts?: DateTimeOptions): DateTimeMaybeValid;
|
687 |
|
688 | /**
|
689 | * Create a DateTime from an HTTP header date
|
690 | *
|
691 | * @see https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1
|
692 | *
|
693 | * @param text - the HTTP header date
|
694 | * @param opts - options to affect the creation
|
695 | * @param opts.zone - convert the time to this zone. Since HTTP dates are always in UTC,
|
696 | * this has no effect on the interpretation of string,merely the zone the resulting DateTime is expressed in. Defaults to 'local'.
|
697 | * @param opts.setZone - override the zone with the fixed-offset zone specified in the string. For HTTP dates, this is always UTC,
|
698 | * so this option is equivalent to setting the `zone` option to 'utc', but this option is included for consistency with similar methods. Defaults to false.
|
699 | * @param opts.locale - a locale to set on the resulting DateTime instance. Defaults to 'system's locale'.
|
700 | * @param opts.outputCalendar - the output calendar to set on the resulting DateTime instance
|
701 | * @param opts.numberingSystem - the numbering system to set on the resulting DateTime instance
|
702 | *
|
703 | * @example
|
704 | * DateTime.fromHTTP('Sun, 06 Nov 1994 08:49:37 GMT')
|
705 | * @example
|
706 | * DateTime.fromHTTP('Sunday, 06-Nov-94 08:49:37 GMT')
|
707 | * @example
|
708 | * DateTime.fromHTTP('Sun Nov 6 08:49:37 1994')
|
709 | */
|
710 | static fromHTTP(text: string, opts?: DateTimeOptions): DateTimeMaybeValid;
|
711 |
|
712 | /**
|
713 | * Create a DateTime from an input string and format string.
|
714 | * Defaults to en-US if no locale has been specified, regardless of the system's locale. For a table of tokens and their interpretations,
|
715 | * see [here](https://moment.github.io/luxon/#/parsing?id=table-of-tokens).
|
716 | *
|
717 | * @param text - the string to parse
|
718 | * @param fmt - the format the string is expected to be in (see the link below for the formats)
|
719 | * @param opts - options to affect the creation
|
720 | * @param opts.zone - use this zone if no offset is specified in the input string itself. Will also convert the DateTime to this zone. Defaults to 'local'.
|
721 | * @param opts.setZone - override the zone with a zone specified in the string itself, if it specifies one. Defaults to false.
|
722 | * @param opts.locale - a locale string to use when parsing. Will also set the DateTime to this locale. Defaults to 'en-US'.
|
723 | * @param opts.numberingSystem - the numbering system to use when parsing. Will also set the resulting DateTime to this numbering system
|
724 | * @param opts.outputCalendar - the output calendar to set on the resulting DateTime instance
|
725 | */
|
726 | static fromFormat(text: string, fmt: string, opts?: DateTimeOptions): DateTimeMaybeValid;
|
727 |
|
728 | /**
|
729 | * @deprecated use fromFormat instead
|
730 | */
|
731 | static fromString(text: string, format: string, options?: DateTimeOptions): DateTimeMaybeValid;
|
732 |
|
733 | /**
|
734 | * Create a DateTime from a SQL date, time, or datetime
|
735 | * Defaults to en-US if no locale has been specified, regardless of the system's locale
|
736 | *
|
737 | * @param text - the string to parse
|
738 | * @param opts - options to affect the creation
|
739 | * @param opts.zone - use this zone if no offset is specified in the input string itself. Will also convert the DateTime to this zone. Defaults to 'local'.
|
740 | * @param opts.setZone - override the zone with a zone specified in the string itself, if it specifies one. Defaults to false.
|
741 | * @param opts.locale - a locale string to use when parsing. Will also set the DateTime to this locale. Defaults to 'en-US'.
|
742 | * @param opts.numberingSystem - the numbering system to use when parsing. Will also set the resulting DateTime to this numbering system
|
743 | * @param opts.outputCalendar - the output calendar to set on the resulting DateTime instance
|
744 | *
|
745 | * @example
|
746 | * DateTime.fromSQL('2017-05-15')
|
747 | * @example
|
748 | * DateTime.fromSQL('2017-05-15 09:12:34')
|
749 | * @example
|
750 | * DateTime.fromSQL('2017-05-15 09:12:34.342')
|
751 | * @example
|
752 | * DateTime.fromSQL('2017-05-15 09:12:34.342+06:00')
|
753 | * @example
|
754 | * DateTime.fromSQL('2017-05-15 09:12:34.342 America/Los_Angeles')
|
755 | * @example
|
756 | * DateTime.fromSQL('2017-05-15 09:12:34.342 America/Los_Angeles', { setZone: true })
|
757 | * @example
|
758 | * DateTime.fromSQL('2017-05-15 09:12:34.342', { zone: 'America/Los_Angeles' })
|
759 | * @example
|
760 | * DateTime.fromSQL('09:12:34.342')
|
761 | */
|
762 | static fromSQL(text: string, opts?: DateTimeOptions): DateTimeMaybeValid;
|
763 |
|
764 | /**
|
765 | * Create an invalid DateTime.
|
766 | *
|
767 | * @param reason - simple string of why this DateTime is invalid. Should not contain parameters or anything else data-dependent
|
768 | * @param explanation - longer explanation, may include parameters and other useful debugging information. Defaults to null.
|
769 | */
|
770 | static invalid(reason: string, explanation?: string): DateTime<Invalid>;
|
771 |
|
772 | /**
|
773 | * Check if an object is a DateTime. Works across context boundaries
|
774 | *
|
775 | * @param o
|
776 | */
|
777 | static isDateTime(o: unknown): o is DateTimeMaybeValid;
|
778 |
|
779 | /**
|
780 | * Produce the format string for a set of options
|
781 | *
|
782 | * @param formatOpts - Intl.DateTimeFormat constructor options and configuration options
|
783 | * @param localeOpts - Opts to override the configuration options on this DateTime
|
784 | *
|
785 | * @example
|
786 | * DateTime.parseFormatForOpts(DateTime.DATETIME_FULL); //=> "MMMM d, yyyyy, h:m a ZZZ"
|
787 | */
|
788 | static parseFormatForOpts(formatOpts?: DateTimeFormatOptions, localeOpts?: LocaleOptions): string | null;
|
789 |
|
790 | /**
|
791 | * Produce the fully expanded format token for the locale
|
792 | * Does NOT quote characters, so quoted tokens will not round trip correctly
|
793 | * @param fmt - the format string
|
794 | * @param localeOpts - Opts to override the configuration options on this DateTime
|
795 | */
|
796 | static expandFormat(fmt: string, localeOpts?: LocaleOptions): string;
|
797 |
|
798 | private constructor(config: unknown);
|
799 |
|
800 | // INFO
|
801 |
|
802 | /**
|
803 | * Get the value of unit.
|
804 | *
|
805 | * @param unit - a unit such as 'minute' or 'day'
|
806 | *
|
807 | * @example
|
808 | * DateTime.local(2017, 7, 4).get('month'); //=> 7
|
809 | * @example
|
810 | * DateTime.local(2017, 7, 4).get('day'); //=> 4
|
811 | */
|
812 | get(unit: keyof DateTime): number;
|
813 |
|
814 | /**
|
815 | * Get those DateTimes which have the same local time as this DateTime, but a different offset from UTC in this DateTime's zone.
|
816 | * During DST changes local time can be ambiguous, for example 2023-10-29T02:30:00 in Europe/Berlin can have offset +01:00 or +02:00.
|
817 | * This method will return both possible DateTimes if this DateTime's local time is ambiguous.
|
818 | */
|
819 | getPossibleOffsets(): this[];
|
820 |
|
821 | /**
|
822 | * Returns whether the DateTime is valid. Invalid DateTimes occur when:
|
823 | * * The DateTime was created from invalid calendar information, such as the 13th month or February 30
|
824 | * * The DateTime was created by an operation on another invalid date
|
825 | */
|
826 | get isValid(): IfValid<true, false, IsValid>;
|
827 |
|
828 | /**
|
829 | * Returns an error code if this DateTime is invalid, or null if the DateTime is valid
|
830 | */
|
831 | get invalidReason(): IfValid<null, string, IsValid>;
|
832 |
|
833 | /**
|
834 | * Returns an explanation of why this DateTime became invalid, or null if the DateTime is valid
|
835 | */
|
836 | get invalidExplanation(): IfValid<null, string | null, IsValid>;
|
837 |
|
838 | /**
|
839 | * Get the locale of a DateTime, such as 'en-GB'. The locale is used when formatting the DateTime
|
840 | */
|
841 | get locale(): IfValid<string, null, IsValid>;
|
842 |
|
843 | /**
|
844 | * Get the numbering system of a DateTime, such as 'beng'. The numbering system is used when formatting the DateTime
|
845 | */
|
846 | get numberingSystem(): IfValid<string, null, IsValid>;
|
847 |
|
848 | /**
|
849 | * Get the output calendar of a DateTime, such as 'islamic'. The output calendar is used when formatting the DateTime
|
850 | */
|
851 | get outputCalendar(): IfValid<string, null, IsValid>;
|
852 |
|
853 | /**
|
854 | * Get the time zone associated with this DateTime.
|
855 | */
|
856 | get zone(): Zone<IsValid>;
|
857 |
|
858 | /**
|
859 | * Get the name of the time zone.
|
860 | */
|
861 | get zoneName(): IfValid<string, null, IsValid>;
|
862 |
|
863 | /**
|
864 | * Get the year
|
865 | *
|
866 | * @example DateTime.local(2017, 5, 25).year //=> 2017
|
867 | */
|
868 | get year(): IfValid<number, typeof NaN, IsValid>;
|
869 |
|
870 | /**
|
871 | * Get the quarter
|
872 | *
|
873 | * @example DateTime.local(2017, 5, 25).quarter //=> 2
|
874 | */
|
875 | get quarter(): IfValid<QuarterNumbers, typeof NaN, IsValid>;
|
876 |
|
877 | /**
|
878 | * Get the month (1-12).
|
879 | *
|
880 | * @example DateTime.local(2017, 5, 25).month //=> 5
|
881 | */
|
882 | get month(): IfValid<MonthNumbers, typeof NaN, IsValid>;
|
883 |
|
884 | /**
|
885 | * Get the day of the month (1-30ish).
|
886 | *
|
887 | * @example DateTime.local(2017, 5, 25).day //=> 25
|
888 | */
|
889 | get day(): IfValid<DayNumbers, typeof NaN, IsValid>;
|
890 |
|
891 | /**
|
892 | * Get the hour of the day (0-23).
|
893 | *
|
894 | * @example DateTime.local(2017, 5, 25, 9).hour //=> 9
|
895 | */
|
896 | get hour(): IfValid<HourNumbers, typeof NaN, IsValid>;
|
897 |
|
898 | /**
|
899 | * Get the minute of the hour (0-59).
|
900 | *
|
901 | * @example
|
902 | * DateTime.local(2017, 5, 25, 9, 30).minute //=> 30
|
903 | */
|
904 | get minute(): IfValid<MinuteNumbers, typeof NaN, IsValid>;
|
905 |
|
906 | /**
|
907 | * Get the second of the minute (0-59).
|
908 | *
|
909 | * @example
|
910 | * DateTime.local(2017, 5, 25, 9, 30, 52).second //=> 52
|
911 | */
|
912 | get second(): IfValid<SecondNumbers, typeof NaN, IsValid>;
|
913 |
|
914 | /**
|
915 | * Get the millisecond of the second (0-999).
|
916 | *
|
917 | * @example
|
918 | * DateTime.local(2017, 5, 25, 9, 30, 52, 654).millisecond //=> 654
|
919 | */
|
920 | get millisecond(): IfValid<number, typeof NaN, IsValid>;
|
921 |
|
922 | /**
|
923 | * Get the week year
|
924 | * @see https://en.wikipedia.org/wiki/ISO_week_date
|
925 | *
|
926 | * @example
|
927 | * DateTime.local(2014, 12, 31).weekYear //=> 2015
|
928 | */
|
929 | get weekYear(): IfValid<number, typeof NaN, IsValid>;
|
930 |
|
931 | /**
|
932 | * Get the week number of the week year (1-52ish).
|
933 | * @see https://en.wikipedia.org/wiki/ISO_week_date
|
934 | *
|
935 | * @example
|
936 | * DateTime.local(2017, 5, 25).weekNumber //=> 21
|
937 | */
|
938 | get weekNumber(): IfValid<WeekNumbers, typeof NaN, IsValid>;
|
939 |
|
940 | /**
|
941 | * Get the day of the week.
|
942 | * 1 is Monday and 7 is Sunday
|
943 | * @see https://en.wikipedia.org/wiki/ISO_week_date
|
944 | *
|
945 | * @example
|
946 | * DateTime.local(2014, 11, 31).weekday //=> 4
|
947 | */
|
948 | get weekday(): IfValid<WeekdayNumbers, typeof NaN, IsValid>;
|
949 |
|
950 | /**
|
951 | * Returns true if this date is on a weekend, according to the locale, false otherwise
|
952 | */
|
953 | get isWeekend(): IfValid<boolean, false, IsValid>;
|
954 |
|
955 | /**
|
956 | * Get the day of the week, according to the locale.
|
957 | * 1 is the first day of the week, and 7 is the last day of the week.
|
958 | * If the locale assigns Sunday as the first day of the week, then a date which is a Sunday will return 1.
|
959 | */
|
960 | get localWeekday(): IfValid<WeekdayNumbers, typeof NaN, IsValid>;
|
961 |
|
962 | /**
|
963 | * Get the week number of the week year, according to the locale.
|
964 | * Different locales assign week numbers differently.
|
965 | * The week can start on different days of the week (see {),
localWeekday} |
966 | * and because a different number of days is required for a week to count as the first week of a year.
|
967 | */
|
968 | get localWeekNumber(): IfValid<number, typeof NaN, IsValid>;
|
969 |
|
970 | /**
|
971 | * Get the week year, according to the locale.
|
972 | * Different locales assign week numbers (and therefore week years) differently, see { localWeekNumber}.
|
973 | */
|
974 | get localWeekYear(): IfValid<number, typeof NaN, IsValid>;
|
975 |
|
976 | /**
|
977 | * Get the ordinal (meaning the day of the year)
|
978 | *
|
979 | * @example
|
980 | * DateTime.local(2017, 5, 25).ordinal //=> 145
|
981 | */
|
982 | get ordinal(): IfValid<number, typeof NaN, IsValid>;
|
983 |
|
984 | /**
|
985 | * Get the human readable short month name, such as 'Oct'.
|
986 | * Defaults to the system's locale if no locale has been specified
|
987 | *
|
988 | * @example
|
989 | * DateTime.local(2017, 10, 30).monthShort //=> Oct
|
990 | */
|
991 | get monthShort(): IfValid<string, null, IsValid>;
|
992 |
|
993 | /**
|
994 | * Get the human readable long month name, such as 'October'.
|
995 | * Defaults to the system's locale if no locale has been specified
|
996 | *
|
997 | * @example
|
998 | * DateTime.local(2017, 10, 30).monthLong //=> October
|
999 | */
|
1000 | get monthLong(): IfValid<string, null, IsValid>;
|
1001 |
|
1002 | /**
|
1003 | * Get the human readable short weekday, such as 'Mon'.
|
1004 | * Defaults to the system's locale if no locale has been specified
|
1005 | *
|
1006 | * @example
|
1007 | * DateTime.local(2017, 10, 30).weekdayShort //=> Mon
|
1008 | */
|
1009 | get weekdayShort(): IfValid<string, null, IsValid>;
|
1010 |
|
1011 | /**
|
1012 | * Get the human readable long weekday, such as 'Monday'.
|
1013 | * Defaults to the system's locale if no locale has been specified
|
1014 | *
|
1015 | * @example
|
1016 | * DateTime.local(2017, 10, 30).weekdayLong //=> Monday
|
1017 | */
|
1018 | get weekdayLong(): IfValid<string, null, IsValid>;
|
1019 |
|
1020 | /**
|
1021 | * Get the UTC offset of this DateTime in minutes
|
1022 | *
|
1023 | * @example
|
1024 | * DateTime.now().offset //=> -240
|
1025 | * @example
|
1026 | * DateTime.utc().offset //=> 0
|
1027 | */
|
1028 | get offset(): IfValid<number, typeof NaN, IsValid>;
|
1029 |
|
1030 | /**
|
1031 | * Get the short human name for the zone's current offset, for example "EST" or "EDT".
|
1032 | * Defaults to the system's locale if no locale has been specified
|
1033 | */
|
1034 | get offsetNameShort(): IfValid<string, null, IsValid>;
|
1035 |
|
1036 | /**
|
1037 | * Get the long human name for the zone's current offset, for example "Eastern Standard Time" or "Eastern Daylight Time".
|
1038 | * Defaults to the system's locale if no locale has been specified
|
1039 | */
|
1040 | get offsetNameLong(): IfValid<string, null, IsValid>;
|
1041 |
|
1042 | /**
|
1043 | * Get whether this zone's offset ever changes, as in a DST.
|
1044 | */
|
1045 | get isOffsetFixed(): IfValid<boolean, null, IsValid>;
|
1046 |
|
1047 | /**
|
1048 | * Get whether the DateTime is in a DST.
|
1049 | */
|
1050 | get isInDST(): IfValid<boolean, false, IsValid>;
|
1051 |
|
1052 | /**
|
1053 | * Returns true if this DateTime is in a leap year, false otherwise
|
1054 | *
|
1055 | * @example
|
1056 | * DateTime.local(2016).isInLeapYear //=> true
|
1057 | * @example
|
1058 | * DateTime.local(2013).isInLeapYear //=> false
|
1059 | */
|
1060 | get isInLeapYear(): boolean;
|
1061 |
|
1062 | /**
|
1063 | * Returns the number of days in this DateTime's month
|
1064 | *
|
1065 | * @example
|
1066 | * DateTime.local(2016, 2).daysInMonth //=> 29
|
1067 | * @example
|
1068 | * DateTime.local(2016, 3).daysInMonth //=> 31
|
1069 | */
|
1070 | get daysInMonth(): IfValid<PossibleDaysInMonth, undefined, IsValid>;
|
1071 |
|
1072 | /**
|
1073 | * Returns the number of days in this DateTime's year
|
1074 | *
|
1075 | * @example
|
1076 | * DateTime.local(2016).daysInYear //=> 366
|
1077 | * @example
|
1078 | * DateTime.local(2013).daysInYear //=> 365
|
1079 | */
|
1080 | get daysInYear(): IfValid<PossibleDaysInYear, typeof NaN, IsValid>;
|
1081 |
|
1082 | /**
|
1083 | * Returns the number of weeks in this DateTime's year
|
1084 | * @see https://en.wikipedia.org/wiki/ISO_week_date
|
1085 | *
|
1086 | * @example
|
1087 | * DateTime.local(2004).weeksInWeekYear //=> 53
|
1088 | * @example
|
1089 | * DateTime.local(2013).weeksInWeekYear //=> 52
|
1090 | */
|
1091 | get weeksInWeekYear(): IfValid<PossibleWeeksInYear, typeof NaN, IsValid>;
|
1092 |
|
1093 | /**
|
1094 | * Returns the number of weeks in this DateTime's local week year
|
1095 | *
|
1096 | * @example
|
1097 | * DateTime.local(2020, 6, {locale: 'en-US'}).weeksInLocalWeekYear //=> 52
|
1098 | * @example
|
1099 | * DateTime.local(2020, 6, {locale: 'de-DE'}).weeksInLocalWeekYear //=> 53
|
1100 | */
|
1101 | get weeksInLocalWeekYear(): IfValid<PossibleWeeksInYear, typeof NaN, IsValid>;
|
1102 |
|
1103 | /**
|
1104 | * Returns the resolved Intl options for this DateTime.
|
1105 | * This is useful in understanding the behavior of formatting methods
|
1106 | *
|
1107 | * @param opts - the same options as toLocaleString
|
1108 | */
|
1109 | resolvedLocaleOptions(opts?: LocaleOptions | DateTimeFormatOptions): ResolvedLocaleOptions;
|
1110 |
|
1111 | // TRANSFORM
|
1112 |
|
1113 | /**
|
1114 | * "Set" the DateTime's zone to UTC. Returns a newly-constructed DateTime.
|
1115 | *
|
1116 | * Equivalent to {@link DateTime.setZone}('utc')
|
1117 | *
|
1118 | * @param offset - optionally, an offset from UTC in minutes. Defaults to 0.
|
1119 | * @param opts - options to pass to `setZone()`. Defaults to {}.
|
1120 | */
|
1121 | toUTC(offset?: number, opts?: ZoneOptions): this;
|
1122 |
|
1123 | /**
|
1124 | * "Set" the DateTime's zone to the host's local zone. Returns a newly-constructed DateTime.
|
1125 | *
|
1126 | * Equivalent to `setZone('local')`
|
1127 | */
|
1128 | toLocal(): this;
|
1129 |
|
1130 | /**
|
1131 | * "Set" the DateTime's zone to specified zone. Returns a newly-constructed DateTime.
|
1132 | *
|
1133 | * By default, the setter keeps the underlying time the same (as in, the same timestamp), but the new instance will report different local times and consider DSTs when making computations,
|
1134 | * as with {@link DateTime.plus}. You may wish to use {@link DateTime.toLocal} and {@link DateTime.toUTC} which provide simple convenience wrappers for commonly used zones.
|
1135 | *
|
1136 | * @param zone - a zone identifier. As a string, that can be any IANA zone supported by the host environment, or a fixed-offset name of the form 'UTC+3', or the strings 'local' or 'utc'.
|
1137 | * You may also supply an instance of a {@link Zone} class. Defaults to 'local'.
|
1138 | * @param opts - options
|
1139 | * @param opts.keepLocalTime - If true, adjust the underlying time so that the local time stays the same, but in the target zone. You should rarely need this. Defaults to false.
|
1140 | */
|
1141 | setZone(zone?: string | Zone, opts?: ZoneOptions): DateTimeMaybeValid;
|
1142 |
|
1143 | /**
|
1144 | * "Set" the locale, numberingSystem, or outputCalendar. Returns a newly-constructed DateTime.
|
1145 | *
|
1146 | * @param properties - the properties to set
|
1147 | *
|
1148 | * @example
|
1149 | * DateTime.local(2017, 5, 25).reconfigure({ locale: 'en-GB' })
|
1150 | */
|
1151 | reconfigure(properties: LocaleOptions): this;
|
1152 |
|
1153 | /**
|
1154 | * "Set" the locale. Returns a newly-constructed DateTime.
|
1155 | * Just a convenient alias for reconfigure({ locale })
|
1156 | *
|
1157 | * @example
|
1158 | * DateTime.local(2017, 5, 25).setLocale('en-GB')
|
1159 | */
|
1160 | setLocale(locale: string): this;
|
1161 |
|
1162 | /**
|
1163 | * "Set" the values of specified units. Returns a newly-constructed DateTime.
|
1164 | * You can only set units with this method; for "setting" metadata, see {@link DateTime.reconfigure} and {@link DateTime.setZone}.
|
1165 | *
|
1166 | * This method also supports setting locale-based week units, i.e. `localWeekday`, `localWeekNumber` and `localWeekYear`.
|
1167 | * They cannot be mixed with ISO-week units like `weekday`.
|
1168 | *
|
1169 | * @example
|
1170 | * dt.set({ year: 2017 })
|
1171 | * @example
|
1172 | * dt.set({ hour: 8, minute: 30 })
|
1173 | * @example
|
1174 | * dt.set({ weekday: 5 })
|
1175 | * @example
|
1176 | * dt.set({ year: 2005, ordinal: 234 })
|
1177 | */
|
1178 | set(values: DateObjectUnits): this;
|
1179 |
|
1180 | /**
|
1181 | * Adding hours, minutes, seconds, or milliseconds increases the timestamp by the right number of milliseconds. Adding days, months, or years shifts the calendar,
|
1182 | * accounting for DSTs and leap years along the way. Thus, `dt.plus({ hours: 24 })` may result in a different time than `dt.plus({ days: 1 })` if there's a DST shift in between.
|
1183 | *
|
1184 | * @param duration - The amount to add. Either a Luxon Duration, a number of milliseconds, the object argument to Duration.fromObject()
|
1185 | *
|
1186 | * @example
|
1187 | * DateTime.now().plus(123) //~> in 123 milliseconds
|
1188 | * @example
|
1189 | * DateTime.now().plus({ minutes: 15 }) //~> in 15 minutes
|
1190 | * @example
|
1191 | * DateTime.now().plus({ days: 1 }) //~> this time tomorrow
|
1192 | * @example
|
1193 | * DateTime.now().plus({ days: -1 }) //~> this time yesterday
|
1194 | * @example
|
1195 | * DateTime.now().plus({ hours: 3, minutes: 13 }) //~> in 3 hr, 13 min
|
1196 | * @example
|
1197 | * DateTime.now().plus(Duration.fromObject({ hours: 3, minutes: 13 })) //~> in 3 hr, 13 min
|
1198 | */
|
1199 | plus(duration: DurationLike): this;
|
1200 |
|
1201 | /**
|
1202 | * See {@link DateTime.plus}
|
1203 | *
|
1204 | * @param duration - The amount to subtract. Either a Luxon Duration, a number of milliseconds, the object argument to Duration.fromObject()
|
1205 | */
|
1206 | minus(duration: DurationLike): this;
|
1207 |
|
1208 | /**
|
1209 | * "Set" this DateTime to the beginning of the given unit.
|
1210 | *
|
1211 | * @param unit - The unit to go to the beginning of. Can be 'year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second', or 'millisecond'.
|
1212 | * @param opts - options
|
1213 | *
|
1214 | * @example
|
1215 | * DateTime.local(2014, 3, 3).startOf('month').toISODate(); //=> '2014-03-01'
|
1216 | * @example
|
1217 | * DateTime.local(2014, 3, 3).startOf('year').toISODate(); //=> '2014-01-01'
|
1218 | * @example
|
1219 | * DateTime.local(2014, 3, 3).startOf('week').toISODate(); //=> '2014-03-03', weeks always start on Mondays
|
1220 | * @example
|
1221 | * DateTime.local(2014, 3, 3, 5, 30).startOf('day').toISOTime(); //=> '00:00.000-05:00'
|
1222 | * @example
|
1223 | * DateTime.local(2014, 3, 3, 5, 30).startOf('hour').toISOTime(); //=> '05:00:00.000-05:00'
|
1224 | */
|
1225 | startOf(unit: DateTimeUnit, opts?: StartOfOptions): this;
|
1226 |
|
1227 | /**
|
1228 | * "Set" this DateTime to the end (meaning the last millisecond) of a unit of time
|
1229 | *
|
1230 | * @param unit - The unit to go to the end of. Can be 'year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second', or 'millisecond'.
|
1231 | * @param opts - options
|
1232 | *
|
1233 | * @example
|
1234 | * DateTime.local(2014, 3, 3).endOf('month').toISO(); //=> '2014-03-31T23:59:59.999-05:00'
|
1235 | * @example
|
1236 | * DateTime.local(2014, 3, 3).endOf('year').toISO(); //=> '2014-12-31T23:59:59.999-05:00'
|
1237 | * @example
|
1238 | * DateTime.local(2014, 3, 3).endOf('week').toISO(); // => '2014-03-09T23:59:59.999-05:00', weeks start on Mondays
|
1239 | * @example
|
1240 | * DateTime.local(2014, 3, 3, 5, 30).endOf('day').toISO(); //=> '2014-03-03T23:59:59.999-05:00'
|
1241 | * @example
|
1242 | * DateTime.local(2014, 3, 3, 5, 30).endOf('hour').toISO(); //=> '2014-03-03T05:59:59.999-05:00'
|
1243 | */
|
1244 | endOf(unit: DateTimeUnit, opts?: EndOfOptions): this;
|
1245 |
|
1246 | // OUTPUT
|
1247 |
|
1248 | /**
|
1249 | * Returns a string representation of this DateTime formatted according to the specified format string.
|
1250 | * **You may not want this.** See {@link DateTime.toLocaleString} for a more flexible formatting tool. For a table of tokens and their interpretations,
|
1251 | * see [here](https://moment.github.io/luxon/#/formatting?id=table-of-tokens).
|
1252 | * Defaults to en-US if no locale has been specified, regardless of the system's locale.
|
1253 | *
|
1254 | * @param fmt - the format string
|
1255 | * @param opts - opts to override the configuration options on this DateTime
|
1256 | *
|
1257 | * @example
|
1258 | * DateTime.now().toFormat('yyyy LLL dd') //=> '2017 Apr 22'
|
1259 | * @example
|
1260 | * DateTime.now().setLocale('fr').toFormat('yyyy LLL dd') //=> '2017 avr. 22'
|
1261 | * @example
|
1262 | * DateTime.now().toFormat('yyyy LLL dd', { locale: "fr" }) //=> '2017 avr. 22'
|
1263 | * @example
|
1264 | * DateTime.now().toFormat("HH 'hours and' mm 'minutes'") //=> '20 hours and 55 minutes'
|
1265 | */
|
1266 | toFormat(fmt: string, opts?: LocaleOptions): IfValid<string, "Invalid DateTime", IsValid>;
|
1267 |
|
1268 | /**
|
1269 | * Returns a localized string representing this date. Accepts the same options as the Intl.DateTimeFormat constructor and any presets defined by Luxon,
|
1270 | * such as `DateTime.DATE_FULL` or `DateTime.TIME_SIMPLE` of the DateTime in the assigned locale.
|
1271 | * Defaults to the system's locale if no locale has been specified
|
1272 | * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
|
1273 | *
|
1274 | * @param formatOpts - Intl.DateTimeFormat constructor options and configuration options
|
1275 | * @param opts - opts to override the configuration options on this DateTime
|
1276 | *
|
1277 | * @example
|
1278 | * DateTime.now().toLocaleString(); //=> 4/20/2017
|
1279 | * @example
|
1280 | * DateTime.now().setLocale('en-gb').toLocaleString(); //=> '20/04/2017'
|
1281 | * @example
|
1282 | * DateTime.now().toLocaleString({ locale: 'en-gb' }); //=> '20/04/2017'
|
1283 | * @example
|
1284 | * DateTime.now().toLocaleString(DateTime.DATE_FULL); //=> 'April 20, 2017'
|
1285 | * @example
|
1286 | * DateTime.now().toLocaleString(DateTime.TIME_SIMPLE); //=> '11:32 AM'
|
1287 | * @example
|
1288 | * DateTime.now().toLocaleString(DateTime.DATETIME_SHORT); //=> '4/20/2017, 11:32 AM'
|
1289 | * @example
|
1290 | * DateTime.now().toLocaleString({ weekday: 'long', month: 'long', day: '2-digit' }); //=> 'Thursday, April 20'
|
1291 | * @example
|
1292 | * DateTime.now().toLocaleString({ weekday: 'short', month: 'short', day: '2-digit', hour: '2-digit', minute: '2-digit' }); //=> 'Thu, Apr 20, 11:27 AM'
|
1293 | * @example
|
1294 | * DateTime.now().toLocaleString({ hour: '2-digit', minute: '2-digit', hourCycle: 'h23' }); //=> '11:32'
|
1295 | */
|
1296 | toLocaleString(
|
1297 | formatOpts?: DateTimeFormatOptions,
|
1298 | opts?: LocaleOptions,
|
1299 | ): IfValid<string, "Invalid DateTime", IsValid>;
|
1300 |
|
1301 | /**
|
1302 | * Returns an array of format "parts", meaning individual tokens along with metadata. This is allows callers to post-process individual sections of the formatted output.
|
1303 | * Defaults to the system's locale if no locale has been specified
|
1304 | * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/formatToParts
|
1305 | *
|
1306 | * @example
|
1307 | * DateTime.now().toLocaleParts(); //=> [
|
1308 | * //=> { type: 'day', value: '25' },
|
1309 | * //=> { type: 'literal', value: '/' },
|
1310 | * //=> { type: 'month', value: '05' },
|
1311 | * //=> { type: 'literal', value: '/' },
|
1312 | * //=> { type: 'year', value: '1982' }
|
1313 | * //=> ]
|
1314 | * @example
|
1315 | * DateTime.invalid('').toLocaleParts(); //=> []
|
1316 | */
|
1317 | toLocaleParts(opts?: DateTimeFormatOptions): Intl.DateTimeFormatPart[];
|
1318 |
|
1319 | /**
|
1320 | * Returns an ISO 8601-compliant string representation of this DateTime
|
1321 | *
|
1322 | * @example
|
1323 | * DateTime.utc(1982, 5, 25).toISO() //=> '1982-05-25T00:00:00.000Z'
|
1324 | * @example
|
1325 | * DateTime.now().toISO() //=> '2017-04-22T20:47:05.335-04:00'
|
1326 | * @example
|
1327 | * DateTime.now().toISO({ includeOffset: false }) //=> '2017-04-22T20:47:05.335'
|
1328 | * @example
|
1329 | * DateTime.now().toISO({ format: 'basic' }) //=> '20170422T204705.335-0400'
|
1330 | */
|
1331 | toISO(opts?: ToISOTimeOptions): IfValid<string, null, IsValid>;
|
1332 |
|
1333 | /**
|
1334 | * Returns an ISO 8601-compliant string representation of this DateTime's date component
|
1335 | *
|
1336 | * @param opts - options
|
1337 | * @param opts.format - choose between the basic and extended format. Defaults to 'extended'.
|
1338 | *
|
1339 | * @example
|
1340 | * DateTime.utc(1982, 5, 25).toISODate() //=> '1982-05-25'
|
1341 | * @example
|
1342 | * DateTime.utc(1982, 5, 25).toISODate({ format: 'basic' }) //=> '19820525'
|
1343 | */
|
1344 | toISODate(opts?: ToISODateOptions): IfValid<string, null, IsValid>;
|
1345 |
|
1346 | /**
|
1347 | * Returns an ISO 8601-compliant string representation of this DateTime's week date
|
1348 | *
|
1349 | * @example
|
1350 | * DateTime.utc(1982, 5, 25).toISOWeekDate() //=> '1982-W21-2'
|
1351 | */
|
1352 | toISOWeekDate(): IfValid<string, null, IsValid>;
|
1353 |
|
1354 | /**
|
1355 | * Returns an ISO 8601-compliant string representation of this DateTime's time component
|
1356 | *
|
1357 | * @param opts - options
|
1358 | * @param opts.suppressMilliseconds - exclude milliseconds from the format if they're 0. Defaults to false.
|
1359 | * @param opts.suppressSeconds - exclude seconds from the format if they're 0. Defaults to false.
|
1360 | * @param opts.includeOffset - include the offset, such as 'Z' or '-04:00'. Defaults to true.
|
1361 | * @param opts.includePrefix - include the `T` prefix. Defaults to false.
|
1362 | * @param opts.format - choose between the basic and extended format. Defaults to 'extended'.
|
1363 | *
|
1364 | * @example
|
1365 | * DateTime.utc().set({ hour: 7, minute: 34 }).toISOTime() //=> '07:34:19.361Z'
|
1366 | * @example
|
1367 | * DateTime.utc().set({ hour: 7, minute: 34, seconds: 0, milliseconds: 0 }).toISOTime({ suppressSeconds: true }) //=> '07:34Z'
|
1368 | * @example
|
1369 | * DateTime.utc().set({ hour: 7, minute: 34 }).toISOTime({ format: 'basic' }) //=> '073419.361Z'
|
1370 | * @example
|
1371 | * DateTime.utc().set({ hour: 7, minute: 34 }).toISOTime({ includePrefix: true }) //=> 'T07:34:19.361Z'
|
1372 | */
|
1373 | toISOTime(opts?: ToISOTimeOptions): IfValid<string, null, IsValid>;
|
1374 |
|
1375 | /**
|
1376 | * Returns an RFC 2822-compatible string representation of this DateTime, always in UTC
|
1377 | *
|
1378 | * @example
|
1379 | * DateTime.utc(2014, 7, 13).toRFC2822() //=> 'Sun, 13 Jul 2014 00:00:00 +0000'
|
1380 | * @example
|
1381 | * DateTime.local(2014, 7, 13).toRFC2822() //=> 'Sun, 13 Jul 2014 00:00:00 -0400'
|
1382 | */
|
1383 | toRFC2822(): IfValid<string, null, IsValid>;
|
1384 |
|
1385 | /**
|
1386 | * Returns a string representation of this DateTime appropriate for use in HTTP headers.
|
1387 | * Specifically, the string conforms to RFC 1123.
|
1388 | * @see https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1
|
1389 | *
|
1390 | * @example
|
1391 | * DateTime.utc(2014, 7, 13).toHTTP() //=> 'Sun, 13 Jul 2014 00:00:00 GMT'
|
1392 | * @example
|
1393 | * DateTime.utc(2014, 7, 13, 19).toHTTP() //=> 'Sun, 13 Jul 2014 19:00:00 GMT'
|
1394 | */
|
1395 | toHTTP(): IfValid<string, null, IsValid>;
|
1396 |
|
1397 | /**
|
1398 | * Returns a string representation of this DateTime appropriate for use in SQL Date
|
1399 | *
|
1400 | * @example
|
1401 | * DateTime.utc(2014, 7, 13).toSQLDate() //=> '2014-07-13'
|
1402 | */
|
1403 | toSQLDate(): IfValid<string, null, IsValid>;
|
1404 |
|
1405 | /**
|
1406 | * Returns a string representation of this DateTime appropriate for use in SQL Time
|
1407 | *
|
1408 | * @example
|
1409 | * DateTime.utc().toSQL() //=> '05:15:16.345'
|
1410 | * @example
|
1411 | * DateTime.now().toSQL() //=> '05:15:16.345 -04:00'
|
1412 | * @example
|
1413 | * DateTime.now().toSQL({ includeOffset: false }) //=> '05:15:16.345'
|
1414 | * @example
|
1415 | * DateTime.now().toSQL({ includeZone: false }) //=> '05:15:16.345 America/New_York'
|
1416 | */
|
1417 | toSQLTime(opts?: ToSQLOptions): IfValid<string, null, IsValid>;
|
1418 |
|
1419 | /**
|
1420 | * Returns a string representation of this DateTime for use in SQL DateTime
|
1421 | *
|
1422 | * @example
|
1423 | * DateTime.utc(2014, 7, 13).toSQL() //=> '2014-07-13 00:00:00.000 Z'
|
1424 | * @example
|
1425 | * DateTime.local(2014, 7, 13).toSQL() //=> '2014-07-13 00:00:00.000 -04:00'
|
1426 | * @example
|
1427 | * DateTime.local(2014, 7, 13).toSQL({ includeOffset: false }) //=> '2014-07-13 00:00:00.000'
|
1428 | * @example
|
1429 | * DateTime.local(2014, 7, 13).toSQL({ includeZone: true }) //=> '2014-07-13 00:00:00.000 America/New_York'
|
1430 | */
|
1431 | toSQL(opts?: ToSQLOptions): IfValid<string, null, IsValid>;
|
1432 |
|
1433 | /**
|
1434 | * Returns a string representation of this DateTime appropriate for debugging
|
1435 | */
|
1436 | toString(): IfValid<string, "Invalid DateTime", IsValid>;
|
1437 |
|
1438 | /**
|
1439 | * Returns the epoch milliseconds of this DateTime. Alias of {@link DateTime.toMillis}
|
1440 | */
|
1441 | valueOf(): IfValid<number, typeof NaN, IsValid>;
|
1442 |
|
1443 | /**
|
1444 | * Returns the epoch milliseconds of this DateTime.
|
1445 | */
|
1446 | toMillis(): IfValid<number, typeof NaN, IsValid>;
|
1447 |
|
1448 | /**
|
1449 | * Returns the epoch seconds of this DateTime.
|
1450 | */
|
1451 | toSeconds(): IfValid<number, typeof NaN, IsValid>;
|
1452 |
|
1453 | /**
|
1454 | * Returns the epoch seconds (as a whole number) of this DateTime.
|
1455 | */
|
1456 | toUnixInteger(): IfValid<number, typeof NaN, IsValid>;
|
1457 |
|
1458 | /**
|
1459 | * Returns an ISO 8601 representation of this DateTime appropriate for use in JSON.
|
1460 | */
|
1461 | toJSON(): IfValid<string, null, IsValid>;
|
1462 |
|
1463 | /**
|
1464 | * Returns a BSON-serializable equivalent to this DateTime.
|
1465 | */
|
1466 | toBSON(): Date;
|
1467 |
|
1468 | /**
|
1469 | * Returns a JavaScript object with this DateTime's year, month, day, and so on.
|
1470 | *
|
1471 | * @param opts - options for generating the object
|
1472 | * @param opts.includeConfig - include configuration attributes in the output. Defaults to false.
|
1473 | *
|
1474 | * @example
|
1475 | * DateTime.now().toObject() //=> { year: 2017, month: 4, day: 22, hour: 20, minute: 49, second: 42, millisecond: 268 }
|
1476 | */
|
1477 | toObject<IncludeConfig extends boolean | undefined>(opts?: {
|
1478 | /**
|
1479 | * Include configuration attributes in the output
|
1480 | * @defaultValue false
|
1481 | */
|
1482 | includeConfig?: IncludeConfig;
|
1483 | }): ToObjectOutput<IncludeConfig, IsValid>;
|
1484 |
|
1485 | /**
|
1486 | * Returns a JavaScript Date equivalent to this DateTime.
|
1487 | */
|
1488 | toJSDate(): Date;
|
1489 |
|
1490 | // COMPARE
|
1491 |
|
1492 | /**
|
1493 | * Return the difference between two DateTimes as a Duration.
|
1494 | *
|
1495 | * @param otherDateTime - the DateTime to compare this one to
|
1496 | * @param unit - the unit or array of units to include in the duration.
|
1497 | * Defaults to ['milliseconds'].
|
1498 | * @param opts - options that affect the creation of the Duration
|
1499 | * @param opts.conversionAccuracy - the conversion system to use.
|
1500 | * Defaults to 'casual'.
|
1501 | *
|
1502 | * @example
|
1503 | * let i1 = DateTime.fromISO('1982-05-25T09:45'),
|
1504 | * i2 = DateTime.fromISO('1983-10-14T10:30');
|
1505 | * i2.diff(i1).toObject() //=> { milliseconds: 43807500000 }
|
1506 | * i2.diff(i1, 'hours').toObject() //=> { hours: 12168.75 }
|
1507 | * i2.diff(i1, ['months', 'days']).toObject() //=> { months: 16, days: 19.03125 }
|
1508 | * i2.diff(i1, ['months', 'days', 'hours']).toObject() //=> { months: 16, days: 19, hours: 0.75 }
|
1509 | */
|
1510 | diff(otherDateTime: DateTime, unit?: DurationUnits, opts?: DiffOptions): Duration<IsValid>;
|
1511 |
|
1512 | /**
|
1513 | * Return the difference between this DateTime and right now.
|
1514 | * See {@link DateTime.diff}
|
1515 | *
|
1516 | * @param unit - the unit(s) to include in the duration. Defaults to ['milliseconds'].
|
1517 | * @param opts - options that affect the creation of the Duration
|
1518 | * @param opts.conversionAccuracy - the conversion system to use. Defaults to 'casual'.
|
1519 | */
|
1520 | diffNow(unit?: DurationUnits, opts?: DiffOptions): Duration<Valid>;
|
1521 |
|
1522 | /**
|
1523 | * Return an Interval spanning between this DateTime and another DateTime
|
1524 | *
|
1525 | * @param otherDateTime - the other end point of the Interval
|
1526 | */
|
1527 | until(otherDateTime: DateTime): IfValid<Interval<Valid>, DateTime<Invalid>, IsValid>;
|
1528 |
|
1529 | /**
|
1530 | * Return whether this DateTime is in the same unit of time as another DateTime.
|
1531 | * Note that time zones are **ignored** in this comparison, which compares the **local** calendar time. Use {@link DateTime.setZone} to convert one of the dates if needed.
|
1532 | *
|
1533 | * @param otherDateTime - the other DateTime
|
1534 | * @param unit - the unit of time to check sameness on
|
1535 | *
|
1536 | * @example
|
1537 | * DateTime.now().hasSame(otherDT, 'day'); //~> true if otherDT is in the same current calendar day
|
1538 | */
|
1539 | hasSame(otherDateTime: DateTime, unit: DateTimeUnit, opts?: HasSameOptions): IfValid<boolean, false, IsValid>;
|
1540 |
|
1541 | /**
|
1542 | * An equality check.
|
1543 | * Two DateTimes are equal if and only if they represent the same millisecond, have the same zone and location, and are both valid.
|
1544 | * To compare just the millisecond values, use `+dt1 === +dt2`.
|
1545 | *
|
1546 | * @param other - the other DateTime
|
1547 | */
|
1548 | equals(other: DateTime): IfValid<boolean, false, IsValid>;
|
1549 |
|
1550 | /**
|
1551 | * Returns a string representation of this time relative to now, such as "in two days".
|
1552 | * Can only internationalize if your platform supports Intl.RelativeTimeFormat.
|
1553 | * Rounds down by default.
|
1554 | *
|
1555 | * @example
|
1556 | * DateTime.now().plus({ days: 1 }).toRelative() //=> "in 1 day"
|
1557 | * @example
|
1558 | * DateTime.now().setLocale("es").toRelative({ days: 1 }) //=> "dentro de 1 día"
|
1559 | * @example
|
1560 | * DateTime.now().plus({ days: 1 }).toRelative({ locale: "fr" }) //=> "dans 23 heures"
|
1561 | * @example
|
1562 | * DateTime.now().minus({ days: 2 }).toRelative() //=> "2 days ago"
|
1563 | * @example
|
1564 | * DateTime.now().minus({ days: 2 }).toRelative({ unit: "hours" }) //=> "48 hours ago"
|
1565 | * @example
|
1566 | * DateTime.now().minus({ hours: 36 }).toRelative({ round: false }) //=> "1.5 days ago"
|
1567 | */
|
1568 | toRelative(options?: ToRelativeOptions): IfValid<string, null, IsValid>;
|
1569 |
|
1570 | /**
|
1571 | * Returns a string representation of this date relative to today, such as "yesterday" or "next month".
|
1572 | * Only internationalizes on platforms that support Intl.RelativeTimeFormat.
|
1573 | *
|
1574 | * @example
|
1575 | * DateTime.now().plus({ days: 1 }).toRelativeCalendar() //=> "tomorrow"
|
1576 | * @example
|
1577 | * DateTime.now().setLocale("es").plus({ days: 1 }).toRelative() //=> ""mañana"
|
1578 | * @example
|
1579 | * DateTime.now().plus({ days: 1 }).toRelativeCalendar({ locale: "fr" }) //=> "demain"
|
1580 | * @example
|
1581 | * DateTime.now().minus({ days: 2 }).toRelativeCalendar() //=> "2 days ago"
|
1582 | */
|
1583 | toRelativeCalendar(options?: ToRelativeCalendarOptions): IfValid<string, null, IsValid>;
|
1584 |
|
1585 | /**
|
1586 | * Return the min of several date times
|
1587 | *
|
1588 | * @param dateTimes - the DateTimes from which to choose the minimum
|
1589 | */
|
1590 | static min<AllValid extends boolean>(
|
1591 | ...dateTimes: Array<DateTime<AllValid>>
|
1592 | ): (AllValid extends true ? DateTime<Valid> : never) | (AllValid extends false ? DateTime<Invalid> : never);
|
1593 |
|
1594 | /**
|
1595 | * Return the max of several date times
|
1596 | *
|
1597 | * @param dateTimes - the DateTimes from which to choose the maximum
|
1598 | */
|
1599 | static max<AllValid extends boolean>(
|
1600 | ...dateTimes: Array<DateTime<AllValid>>
|
1601 | ): (AllValid extends true ? DateTime<Valid> : never) | (AllValid extends false ? DateTime<Invalid> : never);
|
1602 |
|
1603 | // MISC
|
1604 |
|
1605 | /**
|
1606 | * Explain how a string would be parsed by fromFormat()
|
1607 | *
|
1608 | * @param text - the string to parse
|
1609 | * @param fmt - the format the string is expected to be in (see description)
|
1610 | * @param options - options taken by fromFormat()
|
1611 | */
|
1612 | static fromFormatExplain(text: string, fmt: string, options?: DateTimeOptions): ExplainedFormat;
|
1613 |
|
1614 | /**
|
1615 | * @deprecated use fromFormatExplain instead
|
1616 | */
|
1617 | static fromStringExplain(text: string, fmt: string, options?: DateTimeOptions): ExplainedFormat;
|
1618 |
|
1619 | // FORMAT PRESETS
|
1620 |
|
1621 | /**
|
1622 | * {@link DateTime.toLocaleString} format like 10/14/1983
|
1623 | */
|
1624 | static get DATE_SHORT(): Intl.DateTimeFormatOptions;
|
1625 |
|
1626 | /**
|
1627 | * {@link DateTime.toLocaleString} format like 'Oct 14, 1983'
|
1628 | */
|
1629 | static get DATE_MED(): Intl.DateTimeFormatOptions;
|
1630 |
|
1631 | /**
|
1632 | * {@link DateTime.toLocaleString} format like 'Fri, Oct 14, 1983'
|
1633 | */
|
1634 | static get DATE_MED_WITH_WEEKDAY(): Intl.DateTimeFormatOptions;
|
1635 |
|
1636 | /**
|
1637 | * {@link DateTime.toLocaleString} format like 'October 14, 1983'
|
1638 | */
|
1639 | static get DATE_FULL(): Intl.DateTimeFormatOptions;
|
1640 |
|
1641 | /**
|
1642 | * {@link DateTime.toLocaleString} format like 'Tuesday, October 14, 1983'
|
1643 | */
|
1644 | static get DATE_HUGE(): Intl.DateTimeFormatOptions;
|
1645 |
|
1646 | /**
|
1647 | * {@link DateTime.toLocaleString} format like '09:30 AM'. Only 12-hour if the locale is.
|
1648 | */
|
1649 | static get TIME_SIMPLE(): Intl.DateTimeFormatOptions;
|
1650 |
|
1651 | /**
|
1652 | * {@link DateTime.toLocaleString} format like '09:30:23 AM'. Only 12-hour if the locale is.
|
1653 | */
|
1654 | static get TIME_WITH_SECONDS(): Intl.DateTimeFormatOptions;
|
1655 |
|
1656 | /**
|
1657 | * {@link DateTime.toLocaleString} format like '09:30:23 AM EDT'. Only 12-hour if the locale is.
|
1658 | */
|
1659 | static get TIME_WITH_SHORT_OFFSET(): Intl.DateTimeFormatOptions;
|
1660 |
|
1661 | /**
|
1662 | * {@link DateTime.toLocaleString} format like '09:30:23 AM Eastern Daylight Time'. Only 12-hour if the locale is.
|
1663 | */
|
1664 | static get TIME_WITH_LONG_OFFSET(): Intl.DateTimeFormatOptions;
|
1665 |
|
1666 | /**
|
1667 | * {@link DateTime.toLocaleString} format like '09:30', always 24-hour.
|
1668 | */
|
1669 | static get TIME_24_SIMPLE(): Intl.DateTimeFormatOptions;
|
1670 |
|
1671 | /**
|
1672 | * {@link DateTime.toLocaleString} format like '09:30:23', always 24-hour.
|
1673 | */
|
1674 | static get TIME_24_WITH_SECONDS(): Intl.DateTimeFormatOptions;
|
1675 |
|
1676 | /**
|
1677 | * {@link DateTime.toLocaleString} format like '09:30:23 EDT', always 24-hour.
|
1678 | */
|
1679 | static get TIME_24_WITH_SHORT_OFFSET(): Intl.DateTimeFormatOptions;
|
1680 |
|
1681 | /**
|
1682 | * {@link DateTime.toLocaleString} format like '09:30:23 Eastern Daylight Time', always 24-hour.
|
1683 | */
|
1684 | static get TIME_24_WITH_LONG_OFFSET(): Intl.DateTimeFormatOptions;
|
1685 |
|
1686 | /**
|
1687 | * {@link DateTime.toLocaleString} format like '10/14/1983, 9:30 AM'. Only 12-hour if the locale is.
|
1688 | */
|
1689 | static get DATETIME_SHORT(): Intl.DateTimeFormatOptions;
|
1690 |
|
1691 | /**
|
1692 | * {@link DateTime.toLocaleString} format like '10/14/1983, 9:30:33 AM'. Only 12-hour if the locale is.
|
1693 | */
|
1694 | static get DATETIME_SHORT_WITH_SECONDS(): Intl.DateTimeFormatOptions;
|
1695 |
|
1696 | /**
|
1697 | * {@link DateTime.toLocaleString} format like 'Oct 14, 1983, 9:30 AM'. Only 12-hour if the locale is.
|
1698 | */
|
1699 | static get DATETIME_MED(): Intl.DateTimeFormatOptions;
|
1700 |
|
1701 | /**
|
1702 | * {@link DateTime.toLocaleString} format like 'Oct 14, 1983, 9:30:33 AM'. Only 12-hour if the locale is.
|
1703 | */
|
1704 | static get DATETIME_MED_WITH_SECONDS(): Intl.DateTimeFormatOptions;
|
1705 |
|
1706 | /**
|
1707 | * {@link DateTime.toLocaleString} format like 'Fri, 14 Oct 1983, 9:30 AM'. Only 12-hour if the locale is.
|
1708 | */
|
1709 | static get DATETIME_MED_WITH_WEEKDAY(): Intl.DateTimeFormatOptions;
|
1710 |
|
1711 | /**
|
1712 | * {@link DateTime.toLocaleString} format like 'October 14, 1983, 9:30 AM EDT'. Only 12-hour if the locale is.
|
1713 | */
|
1714 | static get DATETIME_FULL(): Intl.DateTimeFormatOptions;
|
1715 |
|
1716 | /**
|
1717 | * {@link DateTime.toLocaleString} format like 'October 14, 1983, 9:30:33 AM EDT'. Only 12-hour if the locale is.
|
1718 | */
|
1719 | static get DATETIME_FULL_WITH_SECONDS(): Intl.DateTimeFormatOptions;
|
1720 |
|
1721 | /**
|
1722 | * {@link DateTime.toLocaleString} format like 'Friday, October 14, 1983, 9:30 AM Eastern Daylight Time'. Only 12-hour if the locale is.
|
1723 | */
|
1724 | static get DATETIME_HUGE(): Intl.DateTimeFormatOptions;
|
1725 |
|
1726 | /**
|
1727 | * {@link DateTime.toLocaleString} format like 'Friday, October 14, 1983, 9:30:33 AM Eastern Daylight Time'. Only 12-hour if the locale is.
|
1728 | */
|
1729 | static get DATETIME_HUGE_WITH_SECONDS(): Intl.DateTimeFormatOptions;
|
1730 | }
|