-
Notifications
You must be signed in to change notification settings - Fork 30.2k
/
datetime.d.ts
1730 lines (1572 loc) · 64.5 KB
/
datetime.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import {
CalendarSystem,
DateTimeFormatOptions,
NumberingSystem,
StringUnitLength,
ToISOFormat,
ToISOTimeDurationOptions,
ZoneOptions,
} from "../index";
import { CanBeInvalid, DefaultValidity, IfValid, Invalid, Valid } from "./_util";
import { Duration, DurationLike, DurationUnits } from "./duration";
import { Interval } from "./interval";
import { Zone } from "./zone";
export type DateTimeUnit = "year" | "quarter" | "month" | "week" | "day" | "hour" | "minute" | "second" | "millisecond";
export type ToRelativeUnit = "years" | "quarters" | "months" | "weeks" | "days" | "hours" | "minutes" | "seconds";
export type MonthNumbers = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
export type WeekdayNumbers = 1 | 2 | 3 | 4 | 5 | 6 | 7;
export type DayNumbers =
| 1
| 2
| 3
| 4
| 5
| 6
| 7
| 8
| 9
| 10
| 11
| 12
| 13
| 14
| 15
| 16
| 17
| 18
| 19
| 20
| 21
| 22
| 23
| 24
| 25
| 26
| 27
| 28
| 29
| 30
| 31;
export type SecondNumbers =
| 0
| 1
| 2
| 3
| 4
| 5
| 6
| 7
| 8
| 9
| 10
| 11
| 12
| 13
| 14
| 15
| 16
| 17
| 18
| 19
| 20
| 21
| 22
| 23
| 24
| 25
| 26
| 27
| 28
| 29
| 30
| 31
| 32
| 33
| 34
| 35
| 36
| 37
| 38
| 39
| 40
| 41
| 42
| 43
| 44
| 45
| 46
| 47
| 48
| 49
| 50
| 51
| 52
| 53
| 54
| 55
| 56
| 57
| 58
| 59;
export type MinuteNumbers = SecondNumbers;
export type HourNumbers =
| 0
| 1
| 2
| 3
| 4
| 5
| 6
| 7
| 8
| 9
| 10
| 11
| 12
| 13
| 14
| 15
| 16
| 17
| 18
| 19
| 20
| 21
| 22
| 23;
export type WeekNumbers =
| 1
| 2
| 3
| 4
| 5
| 6
| 7
| 8
| 9
| 10
| 11
| 12
| 13
| 14
| 15
| 16
| 17
| 18
| 19
| 20
| 21
| 22
| 23
| 24
| 25
| 26
| 27
| 28
| 29
| 30
| 31
| 32
| 33
| 34
| 35
| 36
| 37
| 38
| 39
| 40
| 41
| 42
| 43
| 44
| 45
| 46
| 47
| 48
| 49
| 50
| 51
| 52
| 53;
export type QuarterNumbers = 1 | 2 | 3 | 4;
export type PossibleDaysInMonth = 28 | 29 | 30 | 31;
export type PossibleDaysInYear = 365 | 366;
export type PossibleWeeksInYear = 52 | 53;
export type ToObjectOutput<
IncludeConfig extends boolean | undefined = undefined,
IsValid extends boolean | undefined = undefined,
> = IsValid extends true ? _ToObjectOutput<IncludeConfig>
: CanBeInvalid extends false ? _ToObjectOutput<IncludeConfig>
: Partial<_ToObjectOutput<IncludeConfig>>;
/** @internal */
export type _ToObjectOutput<IncludeConfig extends boolean | undefined = undefined> =
& Record<_ToObjectUnit, number>
& (IncludeConfig extends true ? LocaleOptions : unknown);
/** @internal */
export type _ToObjectUnit = Exclude<DateTimeUnit, "quarter" | "week">;
export interface ToRelativeOptions extends Omit<ToRelativeCalendarOptions, "unit"> {
/**
* @default long
*/
style?: StringUnitLength | undefined;
/** @default true */
round?: boolean | undefined;
/**
* Padding in milliseconds. This allows you to round up the result if it fits inside the threshold.
* Do not use this in combination with `{round: false}` because the decimal output will include the padding.
* @default 0
*/
padding?: number | undefined;
/**
* A single unit or an array of units. If an array is supplied, the method will pick the best one
* to use from the array. If omitted, the method will pick the unit from a default set.
*/
unit?: ToRelativeUnit | ToRelativeUnit[] | undefined;
}
export interface ToRelativeCalendarOptions {
/**
* The DateTime to use as the basis to which this time is compared
* @default now
*/
base?: DateTime | undefined;
/**
* Override the locale of this DateTime
*/
locale?: string | undefined;
/** If omitted, the method will pick the unit. */
unit?: ToRelativeUnit | undefined;
/**
* Override the numberingSystem of this DateTime.
* The Intl system may choose not to honor this.
*/
numberingSystem?: NumberingSystem | undefined;
}
export interface ToSQLOptions {
/**
* Include the offset, such as 'Z' or '-04:00'
* @default true
*/
includeOffset?: boolean | undefined;
/**
* Include the zone, such as 'America/New_York'. Overrides includeOffset.
* @default false
*/
includeZone?: boolean | undefined;
/**
* include the space between the time and the offset, such as '05:15:16.345 -04:00'
* @default true
*/
includeOffsetSpace?: boolean;
}
export interface ToISODateOptions {
/**
* Choose between the basic and extended format
* @default 'extended'
*/
format?: ToISOFormat | undefined;
}
export interface ToISOTimeOptions extends ToISOTimeDurationOptions {
/**
* Include the offset, such as 'Z' or '-04:00'
* @default true
*/
includeOffset?: boolean | undefined;
/**
* add the time zone format extension
* @default false
*/
extendedZone?: boolean | undefined;
}
/** @deprecated alias for backwards compatibility */
export type ISOTimeOptions = ToISOTimeOptions;
export interface LocaleOptions {
/**
* @default system's locale
*/
locale?: string | undefined;
outputCalendar?: CalendarSystem | undefined;
numberingSystem?: NumberingSystem | undefined;
}
export type ResolvedLocaleOptions = Required<LocaleOptions>;
export interface DateTimeOptions extends LocaleOptions {
/**
* Use this zone if no offset is specified in the input string itself. Will also convert the time to this zone.
* @default local
*/
zone?: string | Zone | undefined;
/**
* Override the zone with a fixed-offset zone specified in the string itself, if it specifies one.
* @default false
*/
setZone?: boolean | undefined;
}
export type DateTimeJSOptions = Omit<DateTimeOptions, "setZone">;
/**
* Note that ISO weekday and local weekday fields are mutually exclusive
*/
export interface DateObjectUnits {
// a year, such as 1987
year?: number | undefined;
// a month, 1-12
month?: number | undefined;
// a day of the month, 1-31, depending on the month
day?: number | undefined;
// day of the year, 1-365 or 366
ordinal?: number | undefined;
// an ISO week year
weekYear?: number | undefined;
// a week year, according to the locale
localWeekYear?: number | undefined;
// an ISO week number, between 1 and 52 or 53, depending on the year
weekNumber?: number | undefined;
// a week number, between 1 and 52 or 53, depending on the year, according to the locale
localWeekNumber?: number | undefined;
// an ISO weekday, 1-7, where 1 is Monday and 7 is Sunday
weekday?: WeekdayNumbers | undefined;
// a weekday, 1-7, where 1 is the first day of the week, and 7 is the last, according to the locale
localWeekday?: WeekdayNumbers | undefined;
// hour of the day, 0-23
hour?: number | undefined;
// minute of the hour, 0-59
minute?: number | undefined;
// second of the minute, 0-59
second?: number | undefined;
// millisecond of the second, 0-999
millisecond?: number | undefined;
}
export type ConversionAccuracy = "casual" | "longterm";
/**
* @deprecated You should use `Intl.DateTimeFormatOptions` fields and values instead.
*/
export type DateTimeFormatPresetValue = "numeric" | "short" | "long";
/**
* @deprecated Use `Intl.DateTimeFormatOptions` instead.
*/
export type DateTimeFormatPreset = Intl.DateTimeFormatOptions;
export interface DiffOptions {
/**
* @default 'casual'
*/
conversionAccuracy?: ConversionAccuracy | undefined;
}
export interface _UseLocaleWeekOption {
/** If true, use weeks based on the locale, i.e., use the locale-dependent start of the week */
useLocaleWeeks?: boolean;
}
export type HasSameOptions = _UseLocaleWeekOption;
export type StartOfOptions = _UseLocaleWeekOption;
export type EndOfOptions = _UseLocaleWeekOption;
export interface ExplainedFormat {
input: string;
tokens: Array<{ literal: boolean; val: string }>;
regex?: RegExp | undefined;
rawMatches?: RegExpMatchArray | null | undefined;
matches?: { [k: string]: any } | undefined;
result?: { [k: string]: any } | null | undefined;
zone?: Zone | null | undefined;
invalidReason?: string | undefined;
}
export type DateTimeMaybeValid = CanBeInvalid extends true ? (DateTime<Valid> | DateTime<Invalid>) : DateTime;
/**
* A DateTime is an immutable data structure representing a specific date and time and accompanying methods.
* It contains class and instance methods for creating, parsing, interrogating, transforming, and formatting them.
*
* A DateTime consists of the following parts:
* * A timestamp. Each DateTime instance refers to a specific millisecond of the Unix epoch.
* * A time zone. Each instance is considered in the context of a specific zone (by default, the local system's zone).
* * Configuration properties that affect how output strings are formatted, such as `locale`, `numberingSystem`, and `outputCalendar`.
*
* Here is a brief overview of the most commonly used functionality it provides:
*
* * **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}.
* To create one from a standard string format, use {@link DateTime.fromISO}, {@link DateTime.fromHTTP}, and {@link DateTime.fromRFC2822}.
* To create one from a custom string format, use {@link DateTime.fromFormat}. To create one from a native JS date, use {@link DateTime.fromJSDate}.
* * **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},
* {@link DateTime#month}, {@link DateTime#day}, {@link DateTime#hour}, {@link DateTime#minute}, {@link DateTime#second}, {@link DateTime#millisecond} accessors.
* * **Week calendar**: For ISO week calendar attributes, see the {@link DateTime#weekYear}, {@link DateTime#weekNumber}, and {@link DateTime#weekday} accessors.
* * **Configuration** See the {@link DateTime#locale} and {@link DateTime#numberingSystem} accessors.
* * **Transformation**: To transform the DateTime into other DateTimes, use {@link DateTime#set}, {@link DateTime#reconfigure}, {@link DateTime#setZone}, {@link DateTime#setLocale},
* {@link DateTime.plus}, {@link DateTime#minus}, {@link DateTime#endOf}, {@link DateTime#startOf}, {@link DateTime#toUTC}, and {@link DateTime#toLocal}.
* * **Output**: To convert the DateTime to other representations, use the {@link DateTime#toRelative}, {@link DateTime#toRelativeCalendar}, {@link DateTime#toJSON}, {@link DateTime#toISO},
* {@link DateTime#toHTTP}, {@link DateTime#toObject}, {@link DateTime#toRFC2822}, {@link DateTime#toString}, {@link DateTime#toLocaleString}, {@link DateTime#toFormat},
* {@link DateTime#toMillis} and {@link DateTime#toJSDate}.
*
* There's plenty others documented below. In addition, for more information on subtler topics
* like internationalization, time zones, alternative calendars, validity, and so on, see the external documentation.
*/
export class DateTime<IsValid extends boolean = DefaultValidity> {
/**
* Create a DateTime for the current instant, in the system's time zone.
*
* Use Settings to override these default values if needed.
* @example
* DateTime.now().toISO() //~> now in the ISO format
*/
static now(): DateTime<Valid>;
/**
* Create a local DateTime
*
* @param year - The calendar year. If omitted (as in, call `local()` with no arguments), the current time will be used
* @param month - The month, 1-indexed
* @param day - The day of the month, 1-indexed
* @param hour - The hour of the day, in 24-hour time
* @param minute - The minute of the hour, meaning a number between 0 and 59
* @param second - The second of the minute, meaning a number between 0 and 59
* @param millisecond - The millisecond of the second, meaning a number between 0 and 999
* @param opts
*
* @example
* DateTime.local() //~> now
* @example
* DateTime.local({ zone: "America/New_York" }) //~> now, in US east coast time
* @example
* DateTime.local(2017) //~> 2017-01-01T00:00:00
* @example
* DateTime.local(2017, 3) //~> 2017-03-01T00:00:00
* @example
* DateTime.local(2017, 3, 12, { locale: "fr") //~> 2017-03-12T00:00:00, with a French locale
* @example
* DateTime.local(2017, 3, 12, 5) //~> 2017-03-12T05:00:00
* @example
* DateTime.local(2017, 3, 12, 5, { zone: "utc" }) //~> 2017-03-12T05:00:00, in UTC
* @example
* DateTime.local(2017, 3, 12, 5, 45) //~> 2017-03-12T05:45:00
* @example
* DateTime.local(2017, 3, 12, 5, 45, 10) //~> 2017-03-12T05:45:10
* @example
* DateTime.local(2017, 3, 12, 5, 45, 10, 765) //~> 2017-03-12T05:45:10.765
*/
static local(
year: number,
month: number,
day: number,
hour: number,
minute: number,
second: number,
millisecond: number,
opts?: DateTimeJSOptions,
): DateTimeMaybeValid;
static local(
year: number,
month: number,
day: number,
hour: number,
minute: number,
second: number,
opts?: DateTimeJSOptions,
): DateTimeMaybeValid;
static local(
year: number,
month: number,
day: number,
hour: number,
minute: number,
opts?: DateTimeJSOptions,
): DateTimeMaybeValid;
static local(year: number, month: number, day: number, hour: number, opts?: DateTimeJSOptions): DateTimeMaybeValid;
static local(year: number, month: number, day: number, opts?: DateTimeJSOptions): DateTimeMaybeValid;
static local(year: number, month: number, opts?: DateTimeJSOptions): DateTimeMaybeValid;
static local(year: number, opts?: DateTimeJSOptions): DateTimeMaybeValid;
static local(opts?: DateTimeJSOptions): DateTime<Valid>;
/**
* Create a DateTime in UTC
*
* @param year - The calendar year. If omitted (as in, call `utc()` with no arguments), the current time will be used
* @param month - The month, 1-indexed
* @param day - The day of the month
* @param hour - The hour of the day, in 24-hour time
* @param minute - The minute of the hour, meaning a number between 0 and 59
* @param second - The second of the minute, meaning a number between 0 and 59
* @param millisecond - The millisecond of the second, meaning a number between 0 and 999
* @param options - configuration options for the DateTime
* @param options.locale - a locale to set on the resulting DateTime instance
* @param options.outputCalendar - the output calendar to set on the resulting DateTime instance
* @param options.numberingSystem - the numbering system to set on the resulting DateTime instance
*
* @example
* DateTime.utc() //~> now
* @example
* DateTime.utc(2017) //~> 2017-01-01T00:00:00Z
* @example
* DateTime.utc(2017, 3) //~> 2017-03-01T00:00:00Z
* @example
* DateTime.utc(2017, 3, 12) //~> 2017-03-12T00:00:00Z
* @example
* DateTime.utc(2017, 3, 12, 5) //~> 2017-03-12T05:00:00Z
* @example
* DateTime.utc(2017, 3, 12, 5, 45) //~> 2017-03-12T05:45:00Z
* @example
* DateTime.utc(2017, 3, 12, 5, 45, { locale: "fr" } ) //~> 2017-03-12T05:45:00Z with a French locale
* @example
* DateTime.utc(2017, 3, 12, 5, 45, 10) //~> 2017-03-12T05:45:10Z
* @example
* DateTime.utc(2017, 3, 12, 5, 45, 10, 765, { locale: "fr") //~> 2017-03-12T05:45:10.765Z with a French locale
*/
static utc(
year: number,
month: number,
day: number,
hour: number,
minute: number,
second: number,
millisecond: number,
options?: LocaleOptions,
): DateTimeMaybeValid;
static utc(
year: number,
month: number,
day: number,
hour: number,
minute: number,
second: number,
options?: LocaleOptions,
): DateTimeMaybeValid;
static utc(
year: number,
month: number,
day: number,
hour: number,
minute: number,
options?: LocaleOptions,
): DateTimeMaybeValid;
static utc(year: number, month: number, day: number, hour: number, options?: LocaleOptions): DateTimeMaybeValid;
static utc(year: number, month: number, day: number, options?: LocaleOptions): DateTimeMaybeValid;
static utc(year: number, month: number, options?: LocaleOptions): DateTimeMaybeValid;
static utc(year: number, options?: LocaleOptions): DateTimeMaybeValid;
static utc(options?: LocaleOptions): DateTime<Valid>;
/**
* Create a DateTime from a JavaScript Date object. Uses the default zone.
*
* @param date - a JavaScript Date object
* @param options - configuration options for the DateTime
* @param options.zone - the zone to place the DateTime into
*/
static fromJSDate(date: Date, options?: { zone?: string | Zone }): DateTimeMaybeValid;
/**
* Create a DateTime from a number of milliseconds since the epoch (meaning since 1 January 1970 00:00:00 UTC). Uses the default zone.
*
* @param milliseconds - a number of milliseconds since 1970 UTC
* @param options - configuration options for the DateTime
* @param options.zone - the zone to place the DateTime into. Defaults to 'local'.
* @param options.locale - a locale to set on the resulting DateTime instance
* @param options.outputCalendar - the output calendar to set on the resulting DateTime instance
* @param options.numberingSystem - the numbering system to set on the resulting DateTime instance
*/
static fromMillis(milliseconds: number, options?: DateTimeJSOptions): DateTimeMaybeValid;
/**
* Create a DateTime from a number of seconds since the epoch (meaning since 1 January 1970 00:00:00 UTC). Uses the default zone.
*
* @param seconds - a number of seconds since 1970 UTC
* @param options - configuration options for the DateTime
* @param options.zone - the zone to place the DateTime into. Defaults to 'local'.
* @param options.locale - a locale to set on the resulting DateTime instance
* @param options.outputCalendar - the output calendar to set on the resulting DateTime instance
* @param options.numberingSystem - the numbering system to set on the resulting DateTime instance
*/
static fromSeconds(seconds: number, options?: DateTimeJSOptions): DateTime<Valid>;
/**
* Create a DateTime from a JavaScript object with keys like 'year' and 'hour' with reasonable defaults.
*
* @param obj - the object to create the DateTime from
* @param obj.year - a year, such as 1987
* @param obj.month - a month, 1-12
* @param obj.day - a day of the month, 1-31, depending on the month
* @param obj.ordinal - day of the year, 1-365 or 366
* @param obj.weekYear - an ISO week year
* @param obj.weekNumber - an ISO week number, between 1 and 52 or 53, depending on the year
* @param obj.weekday - an ISO weekday, 1-7, where 1 is Monday and 7 is Sunday
* @param obj.hour - hour of the day, 0-23
* @param obj.minute - minute of the hour, 0-59
* @param obj.second - second of the minute, 0-59
* @param obj.millisecond - millisecond of the second, 0-999
* @param opts - options for creating this DateTime
* @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'.
* @param opts.locale - a locale to set on the resulting DateTime instance. Defaults to 'system's locale'.
* @param opts.outputCalendar - the output calendar to set on the resulting DateTime instance
* @param opts.numberingSystem - the numbering system to set on the resulting DateTime instance
*
* @example
* DateTime.fromObject({ year: 1982, month: 5, day: 25}).toISODate() //=> '1982-05-25'
* @example
* DateTime.fromObject({ year: 1982 }).toISODate() //=> '1982-01-01'
* @example
* DateTime.fromObject({ hour: 10, minute: 26, second: 6 }) //=> today at 10:26:06
* @example
* DateTime.fromObject({ hour: 10, minute: 26, second: 6 }, { zone: 'utc' })
* @example
* DateTime.fromObject({ hour: 10, minute: 26, second: 6 }, { zone: 'local' })
* @example
* DateTime.fromObject({ hour: 10, minute: 26, second: 6 }, { zone: 'America/New_York' })
* @example
* DateTime.fromObject({ weekYear: 2016, weekNumber: 2, weekday: 3 }).toISODate() //=> '2016-01-13'
* @example
* DateTime.fromObject({ localWeekYear: 2022, localWeekNumber: 1, localWeekday: 1 }, { locale: 'en-US' }).toISODate() //=> '2021-12-26'
*/
static fromObject(obj: DateObjectUnits, opts?: DateTimeJSOptions): DateTimeMaybeValid;
/**
* Create a DateTime from an ISO 8601 string
*
* @param text - the ISO string
* @param opts - options to affect the creation
* @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'.
* @param opts.setZone - override the zone with a fixed-offset zone specified in the string itself, if it specifies one. Defaults to false.
* @param opts.locale - a locale to set on the resulting DateTime instance. Defaults to 'system's locale'.
* @param opts.outputCalendar - the output calendar to set on the resulting DateTime instance
* @param opts.numberingSystem - the numbering system to set on the resulting DateTime instance
*
* @example
* DateTime.fromISO('2016-05-25T09:08:34.123')
* @example
* DateTime.fromISO('2016-05-25T09:08:34.123+06:00')
* @example
* DateTime.fromISO('2016-05-25T09:08:34.123+06:00', {setZone: true})
* @example
* DateTime.fromISO('2016-05-25T09:08:34.123', {zone: 'utc'})
* @example
* DateTime.fromISO('2016-W05-4')
*/
static fromISO(text: string, opts?: DateTimeOptions): DateTimeMaybeValid;
/**
* Create a DateTime from an RFC 2822 string
*
* @param text - the RFC 2822 string
* @param opts - options to affect the creation
* @param opts.zone - convert the time to this zone. Since the offset is always specified in the string itself,
* this has no effect on the interpretation of string, merely the zone the resulting DateTime is expressed in. Defaults to 'local'
* @param opts.setZone - override the zone with a fixed-offset zone specified in the string itself, if it specifies one. Defaults to false.
* @param opts.locale - a locale to set on the resulting DateTime instance. Defaults to 'system's locale'.
* @param opts.outputCalendar - the output calendar to set on the resulting DateTime instance
* @param opts.numberingSystem - the numbering system to set on the resulting DateTime instance
*
* @example
* DateTime.fromRFC2822('25 Nov 2016 13:23:12 GMT')
* @example
* DateTime.fromRFC2822('Fri, 25 Nov 2016 13:23:12 +0600')
* @example
* DateTime.fromRFC2822('25 Nov 2016 13:23 Z')
*/
static fromRFC2822(text: string, opts?: DateTimeOptions): DateTimeMaybeValid;
/**
* Create a DateTime from an HTTP header date
*
* @see https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1
*
* @param text - the HTTP header date
* @param opts - options to affect the creation
* @param opts.zone - convert the time to this zone. Since HTTP dates are always in UTC,
* this has no effect on the interpretation of string,merely the zone the resulting DateTime is expressed in. Defaults to 'local'.
* @param opts.setZone - override the zone with the fixed-offset zone specified in the string. For HTTP dates, this is always UTC,
* 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.
* @param opts.locale - a locale to set on the resulting DateTime instance. Defaults to 'system's locale'.
* @param opts.outputCalendar - the output calendar to set on the resulting DateTime instance
* @param opts.numberingSystem - the numbering system to set on the resulting DateTime instance
*
* @example
* DateTime.fromHTTP('Sun, 06 Nov 1994 08:49:37 GMT')
* @example
* DateTime.fromHTTP('Sunday, 06-Nov-94 08:49:37 GMT')
* @example
* DateTime.fromHTTP('Sun Nov 6 08:49:37 1994')
*/
static fromHTTP(text: string, opts?: DateTimeOptions): DateTimeMaybeValid;
/**
* Create a DateTime from an input string and format string.
* Defaults to en-US if no locale has been specified, regardless of the system's locale. For a table of tokens and their interpretations,
* see [here](https://moment.github.io/luxon/#/parsing?id=table-of-tokens).
*
* @param text - the string to parse
* @param fmt - the format the string is expected to be in (see the link below for the formats)
* @param opts - options to affect the creation
* @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'.
* @param opts.setZone - override the zone with a zone specified in the string itself, if it specifies one. Defaults to false.
* @param opts.locale - a locale string to use when parsing. Will also set the DateTime to this locale. Defaults to 'en-US'.
* @param opts.numberingSystem - the numbering system to use when parsing. Will also set the resulting DateTime to this numbering system
* @param opts.outputCalendar - the output calendar to set on the resulting DateTime instance
*/
static fromFormat(text: string, fmt: string, opts?: DateTimeOptions): DateTimeMaybeValid;
/**
* @deprecated use fromFormat instead
*/
static fromString(text: string, format: string, options?: DateTimeOptions): DateTimeMaybeValid;
/**
* Create a DateTime from a SQL date, time, or datetime
* Defaults to en-US if no locale has been specified, regardless of the system's locale
*
* @param text - the string to parse
* @param opts - options to affect the creation
* @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'.
* @param opts.setZone - override the zone with a zone specified in the string itself, if it specifies one. Defaults to false.
* @param opts.locale - a locale string to use when parsing. Will also set the DateTime to this locale. Defaults to 'en-US'.
* @param opts.numberingSystem - the numbering system to use when parsing. Will also set the resulting DateTime to this numbering system
* @param opts.outputCalendar - the output calendar to set on the resulting DateTime instance
*
* @example
* DateTime.fromSQL('2017-05-15')
* @example
* DateTime.fromSQL('2017-05-15 09:12:34')
* @example
* DateTime.fromSQL('2017-05-15 09:12:34.342')
* @example
* DateTime.fromSQL('2017-05-15 09:12:34.342+06:00')
* @example
* DateTime.fromSQL('2017-05-15 09:12:34.342 America/Los_Angeles')
* @example
* DateTime.fromSQL('2017-05-15 09:12:34.342 America/Los_Angeles', { setZone: true })
* @example
* DateTime.fromSQL('2017-05-15 09:12:34.342', { zone: 'America/Los_Angeles' })
* @example
* DateTime.fromSQL('09:12:34.342')
*/
static fromSQL(text: string, opts?: DateTimeOptions): DateTimeMaybeValid;
/**
* Create an invalid DateTime.
*
* @param reason - simple string of why this DateTime is invalid. Should not contain parameters or anything else data-dependent
* @param explanation - longer explanation, may include parameters and other useful debugging information. Defaults to null.
*/
static invalid(reason: string, explanation?: string): DateTime<Invalid>;
/**
* Check if an object is a DateTime. Works across context boundaries
*
* @param o
*/
static isDateTime(o: unknown): o is DateTimeMaybeValid;
/**
* Produce the format string for a set of options
*
* @param formatOpts - Intl.DateTimeFormat constructor options and configuration options
* @param localeOpts - Opts to override the configuration options on this DateTime
*
* @example
* DateTime.parseFormatForOpts(DateTime.DATETIME_FULL); //=> "MMMM d, yyyyy, h:m a ZZZ"
*/
static parseFormatForOpts(formatOpts?: DateTimeFormatOptions, localeOpts?: LocaleOptions): string | null;
/**
* Produce the fully expanded format token for the locale
* Does NOT quote characters, so quoted tokens will not round trip correctly
* @param fmt - the format string
* @param localeOpts - Opts to override the configuration options on this DateTime
*/
static expandFormat(fmt: string, localeOpts?: LocaleOptions): string;
private constructor(config: unknown);
// INFO
/**
* Get the value of unit.
*
* @param unit - a unit such as 'minute' or 'day'
*
* @example
* DateTime.local(2017, 7, 4).get('month'); //=> 7
* @example
* DateTime.local(2017, 7, 4).get('day'); //=> 4
*/
get(unit: keyof DateTime): number;
/**
* Get those DateTimes which have the same local time as this DateTime, but a different offset from UTC in this DateTime's zone.
* 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.
* This method will return both possible DateTimes if this DateTime's local time is ambiguous.
*/
getPossibleOffsets(): this[];
/**
* Returns whether the DateTime is valid. Invalid DateTimes occur when:
* * The DateTime was created from invalid calendar information, such as the 13th month or February 30
* * The DateTime was created by an operation on another invalid date
*/
get isValid(): IfValid<true, false, IsValid>;
/**
* Returns an error code if this DateTime is invalid, or null if the DateTime is valid
*/
get invalidReason(): IfValid<null, string, IsValid>;
/**
* Returns an explanation of why this DateTime became invalid, or null if the DateTime is valid
*/
get invalidExplanation(): IfValid<null, string | null, IsValid>;
/**
* Get the locale of a DateTime, such as 'en-GB'. The locale is used when formatting the DateTime
*/
get locale(): IfValid<string, null, IsValid>;
/**
* Get the numbering system of a DateTime, such as 'beng'. The numbering system is used when formatting the DateTime
*/
get numberingSystem(): IfValid<string, null, IsValid>;
/**
* Get the output calendar of a DateTime, such as 'islamic'. The output calendar is used when formatting the DateTime
*/
get outputCalendar(): IfValid<string, null, IsValid>;
/**
* Get the time zone associated with this DateTime.
*/
get zone(): Zone<IsValid>;
/**
* Get the name of the time zone.
*/
get zoneName(): IfValid<string, null, IsValid>;
/**
* Get the year
*
* @example DateTime.local(2017, 5, 25).year //=> 2017
*/
get year(): IfValid<number, typeof NaN, IsValid>;
/**
* Get the quarter
*
* @example DateTime.local(2017, 5, 25).quarter //=> 2
*/
get quarter(): IfValid<QuarterNumbers, typeof NaN, IsValid>;
/**
* Get the month (1-12).
*
* @example DateTime.local(2017, 5, 25).month //=> 5
*/
get month(): IfValid<MonthNumbers, typeof NaN, IsValid>;
/**
* Get the day of the month (1-30ish).
*
* @example DateTime.local(2017, 5, 25).day //=> 25
*/
get day(): IfValid<DayNumbers, typeof NaN, IsValid>;
/**
* Get the hour of the day (0-23).
*
* @example DateTime.local(2017, 5, 25, 9).hour //=> 9
*/
get hour(): IfValid<HourNumbers, typeof NaN, IsValid>;
/**
* Get the minute of the hour (0-59).
*
* @example
* DateTime.local(2017, 5, 25, 9, 30).minute //=> 30
*/
get minute(): IfValid<MinuteNumbers, typeof NaN, IsValid>;
/**
* Get the second of the minute (0-59).
*
* @example
* DateTime.local(2017, 5, 25, 9, 30, 52).second //=> 52
*/
get second(): IfValid<SecondNumbers, typeof NaN, IsValid>;
/**
* Get the millisecond of the second (0-999).
*
* @example
* DateTime.local(2017, 5, 25, 9, 30, 52, 654).millisecond //=> 654
*/
get millisecond(): IfValid<number, typeof NaN, IsValid>;
/**
* Get the week year
* @see https://en.wikipedia.org/wiki/ISO_week_date
*
* @example
* DateTime.local(2014, 12, 31).weekYear //=> 2015
*/
get weekYear(): IfValid<number, typeof NaN, IsValid>;
/**
* Get the week number of the week year (1-52ish).
* @see https://en.wikipedia.org/wiki/ISO_week_date
*
* @example
* DateTime.local(2017, 5, 25).weekNumber //=> 21
*/
get weekNumber(): IfValid<WeekNumbers, typeof NaN, IsValid>;
/**
* Get the day of the week.
* 1 is Monday and 7 is Sunday
* @see https://en.wikipedia.org/wiki/ISO_week_date
*
* @example
* DateTime.local(2014, 11, 31).weekday //=> 4
*/
get weekday(): IfValid<WeekdayNumbers, typeof NaN, IsValid>;
/**
* Returns true if this date is on a weekend, according to the locale, false otherwise
*/
get isWeekend(): IfValid<boolean, false, IsValid>;
/**
* Get the day of the week, according to the locale.
* 1 is the first day of the week, and 7 is the last day of the week.
* If the locale assigns Sunday as the first day of the week, then a date which is a Sunday will return 1.
*/
get localWeekday(): IfValid<WeekdayNumbers, typeof NaN, IsValid>;
/**
* Get the week number of the week year, according to the locale.
* Different locales assign week numbers differently.
* The week can start on different days of the week (see {@link localWeekday}),
* and because a different number of days is required for a week to count as the first week of a year.
*/
get localWeekNumber(): IfValid<number, typeof NaN, IsValid>;
/**
* Get the week year, according to the locale.
* Different locales assign week numbers (and therefore week years) differently, see {@link localWeekNumber}.
*/
get localWeekYear(): IfValid<number, typeof NaN, IsValid>;
/**
* Get the ordinal (meaning the day of the year)
*
* @example
* DateTime.local(2017, 5, 25).ordinal //=> 145
*/
get ordinal(): IfValid<number, typeof NaN, IsValid>;
/**
* Get the human readable short month name, such as 'Oct'.
* Defaults to the system's locale if no locale has been specified
*
* @example
* DateTime.local(2017, 10, 30).monthShort //=> Oct
*/
get monthShort(): IfValid<string, null, IsValid>;
/**
* Get the human readable long month name, such as 'October'.
* Defaults to the system's locale if no locale has been specified
*
* @example
* DateTime.local(2017, 10, 30).monthLong //=> October
*/
get monthLong(): IfValid<string, null, IsValid>;