UNPKG

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