UNPKG

43 kBTypeScriptView Raw
1import {
2 CalendarSystem,
3 DateTimeFormatOptions,
4 NumberingSystem,
5 StringUnitLength, ToISOFormat, ToISOTimeDurationOptions,
6 ZoneOptions,
7} from '../index';
8import { Zone } from './zone';
9import { Duration, DurationInput, DurationUnit, DurationUnits } from './duration';
10import { Interval } from './interval';
11
12export type ToRelativeUnit =
13 | 'years'
14 | 'quarters'
15 | 'months'
16 | 'weeks'
17 | 'days'
18 | 'hours'
19 | 'minutes'
20 | 'seconds';
21
22export interface ToRelativeOptions extends ToRelativeCalendarOptions {
23 /**
24 * @default long
25 */
26 style?: StringUnitLength;
27 /** @default true */
28 round?: boolean;
29 /**
30 * Padding in milliseconds. This allows you to round up the result if it fits inside the threshold.
31 * Don't use in combination with {round: false} because the decimal output will include the padding.
32 * @default 0
33 */
34 padding?: number;
35}
36
37export interface ToRelativeCalendarOptions {
38 /**
39 * The DateTime to use as the basis to which this time is compared
40 * @default now
41 */
42 base?: DateTime;
43 /**
44 * Override the locale of this DateTime
45 */
46 locale?: string;
47 /** If omitted, the method will pick the unit. */
48 unit?: ToRelativeUnit;
49 /**
50 * Override the numberingSystem of this DateTime.
51 * The Intl system may choose not to honor this.
52 */
53 numberingSystem?: NumberingSystem;
54}
55
56export interface ToSQLOptions {
57 /**
58 * Include the offset, such as 'Z' or '-04:00'
59 * @default true
60 */
61 includeOffset?: boolean;
62 /**
63 * Include the zone, such as 'America/New_York'. Overrides includeOffset.
64 * @default false
65 */
66 includeZone?: boolean;
67}
68
69export interface ToISODateOptions {
70 /**
71 * Choose between the basic and extended format
72 * @default 'extended'
73 */
74 format?: ToISOFormat;
75}
76
77export interface ToISOTimeOptions extends ToISOTimeDurationOptions {
78 /**
79 * Include the offset, such as 'Z' or '-04:00'
80 * @default true
81 */
82 includeOffset?: boolean;
83}
84
85/** @deprecated alias for backwards compatibility */
86export type ISOTimeOptions = ToISOTimeOptions;
87
88export interface LocaleOptions {
89 /**
90 * @default system's locale
91 */
92 locale?: string;
93 outputCalendar?: CalendarSystem;
94 numberingSystem?: NumberingSystem;
95}
96
97export interface DateTimeOptions extends LocaleOptions {
98 /**
99 * Use this zone if no offset is specified in the input string itself. Will also convert the time to this zone.
100 * @default local
101 */
102 zone?: string | Zone;
103 /**
104 * Override the zone with a fixed-offset zone specified in the string itself, if it specifies one.
105 * @default false
106 */
107 setZone?: boolean;
108}
109
110export type DateTimeJSOptions = Omit<DateTimeOptions, 'setZone'>;
111
112export interface DateObjectUnits {
113 // a year, such as 1987
114 year?: number;
115 // a month, 1-12
116 month?: number;
117 // a day of the month, 1-31, depending on the month
118 day?: number;
119 // day of the year, 1-365 or 366
120 ordinal?: number;
121 // an ISO week year
122 weekYear?: number;
123 // an ISO week number, between 1 and 52 or 53, depending on the year
124 weekNumber?: number;
125 // an ISO weekday, 1-7, where 1 is Monday and 7 is Sunday
126 weekday?: number;
127 // hour of the day, 0-23
128 hour?: number;
129 // minute of the hour, 0-59
130 minute?: number;
131 // second of the minute, 0-59
132 second?: number;
133 // millisecond of the second, 0-999
134 millisecond?: number;
135}
136
137export interface DateObject extends DateObjectUnits, LocaleOptions {
138 zone?: string | Zone;
139}
140
141export type ConversionAccuracy = 'casual' | 'longterm';
142
143export interface DiffOptions {
144 conversionAccuracy?: ConversionAccuracy;
145}
146
147export interface ExplainedFormat {
148 input: string;
149 tokens: Array<{ literal: boolean; val: string }>;
150 regex?: RegExp;
151 rawMatches?: RegExpMatchArray | null;
152 matches?: { [k: string]: any };
153 result?: { [k: string]: any } | null;
154 zone?: Zone | null;
155 invalidReason?: string;
156}
157
158/**
159 * A DateTime is an immutable data structure representing a specific date and time and accompanying methods.
160 * It contains class and instance methods for creating, parsing, interrogating, transforming, and formatting them.
161 *
162 * A DateTime comprises of:
163 * * A timestamp. Each DateTime instance refers to a specific millisecond of the Unix epoch.
164 * * A time zone. Each instance is considered in the context of a specific zone (by default the local system's zone).
165 * * Configuration properties that effect how output strings are formatted, such as `locale`, `numberingSystem`, and `outputCalendar`.
166 *
167 * Here is a brief overview of the most commonly used functionality it provides:
168 *
169 * * **Creation**: To create a DateTime from its components, use one of its factory class methods: {@link local}, {@link utc}, and (most flexibly) {@link fromObject}.
170 * To create one from a standard string format, use {@link fromISO}, {@link fromHTTP}, and {@link fromRFC2822}.
171 * To create one from a custom string format, use {@link fromFormat}. To create one from a native JS date, use {@link fromJSDate}.
172 * * **Gregorian calendar and time**: To examine the Gregorian properties of a DateTime individually
173 * (i.e as opposed to collectively through {@link toObject}), use the {@link year}, {@link month}, {@link day}, {@link hour}, {@link minute}, {@link second}, {@link millisecond} accessors.
174 * * **Week calendar**: For ISO week calendar attributes, see the {@link weekYear}, {@link weekNumber}, and {@link weekday} accessors.
175 * * **Configuration** See the {@link locale} and {@link numberingSystem} accessors.
176 * * **Transformation**: To transform the DateTime into other DateTimes, use {@link set}, {@link reconfigure}, {@link setZone}, {@link setLocale},
177 * {@link plus}, {@link minus}, {@link endOf}, {@link startOf}, {@link toUTC}, and {@link toLocal}.
178 * * **Output**: To convert the DateTime to other representations, use the {@link toRelative}, {@link toRelativeCalendar}, {@link toJSON}, {@link toISO},
179 * {@link toHTTP}, {@link toObject}, {@link toRFC2822}, {@link toString}, {@link toLocaleString}, {@link toFormat}, {@link toMillis} and {@link toJSDate}.
180 *
181 * There's plenty others documented below. In addition, for more information on subtler topics
182 * like internationalization, time zones, alternative calendars, validity, and so on, see the external documentation.
183 */
184export class DateTime {
185 /**
186 * {@link toLocaleString} format like 'October 14, 1983, 9:30 AM EDT'. Only 12-hour if the locale is.
187 */
188 static readonly DATETIME_FULL: DateTimeFormatOptions;
189 /**
190 * {@link toLocaleString} format like 'October 14, 1983, 9:30:33 AM EDT'. Only 12-hour if the locale is.
191 */
192 static readonly DATETIME_FULL_WITH_SECONDS: DateTimeFormatOptions;
193 /**
194 * {@link toLocaleString} format like 'Friday, October 14, 1983, 9:30 AM Eastern Daylight Time'. Only 12-hour if the locale is.
195 */
196 static readonly DATETIME_HUGE: DateTimeFormatOptions;
197 /**
198 * {@link toLocaleString} format like 'Friday, October 14, 1983, 9:30:33 AM Eastern Daylight Time'. Only 12-hour if the locale is.
199 */
200 static readonly DATETIME_HUGE_WITH_SECONDS: DateTimeFormatOptions;
201 /**
202 * {@link toLocaleString} format like 'Oct 14, 1983, 9:30 AM'. Only 12-hour if the locale is.
203 */
204 static readonly DATETIME_MED: DateTimeFormatOptions;
205 /**
206 * {@link toLocaleString} format like 'Oct 14, 1983, 9:30:33 AM'. Only 12-hour if the locale is.
207 */
208 static readonly DATETIME_MED_WITH_SECONDS: DateTimeFormatOptions;
209 /**
210 * {@link toLocaleString} format like 'Fri, 14 Oct 1983, 9:30 AM'. Only 12-hour if the locale is.
211 */
212 static readonly DATETIME_MED_WITH_WEEKDAY: DateTimeFormatOptions;
213 /**
214 * {@link toLocaleString} format like '10/14/1983, 9:30 AM'. Only 12-hour if the locale is.
215 */
216 static readonly DATETIME_SHORT: DateTimeFormatOptions;
217 /**
218 * {@link toLocaleString} format like '10/14/1983, 9:30:33 AM'. Only 12-hour if the locale is.
219 */
220 static readonly DATETIME_SHORT_WITH_SECONDS: DateTimeFormatOptions;
221 /**
222 * {@link toLocaleString} format like 'October 14, 1983'
223 */
224 static readonly DATE_FULL: DateTimeFormatOptions;
225 /**
226 * {@link toLocaleString} format like 'Tuesday, October 14, 1983'
227 */
228 static readonly DATE_HUGE: DateTimeFormatOptions;
229 /**
230 * {@link toLocaleString} format like 'Oct 14, 1983'
231 */
232 static readonly DATE_MED: DateTimeFormatOptions;
233 /**
234 * {@link toLocaleString} format like 'Fri, Oct 14, 1983'
235 */
236 static readonly DATE_MED_WITH_WEEKDAY: DateTimeFormatOptions;
237 /**
238 * {@link toLocaleString} format like 10/14/1983
239 */
240 static readonly DATE_SHORT: DateTimeFormatOptions;
241 /**
242 * {@link toLocaleString} format like '09:30', always 24-hour.
243 */
244 static readonly TIME_24_SIMPLE: DateTimeFormatOptions;
245 /**
246 * {@link toLocaleString} format like '09:30:23 Eastern Daylight Time', always 24-hour.
247 */
248 static readonly TIME_24_WITH_LONG_OFFSET: DateTimeFormatOptions;
249 /**
250 * {@link toLocaleString} format like '09:30:23', always 24-hour.
251 */
252 static readonly TIME_24_WITH_SECONDS: DateTimeFormatOptions;
253 /**
254 * {@link toLocaleString} format like '09:30:23 EDT', always 24-hour.
255 */
256 static readonly TIME_24_WITH_SHORT_OFFSET: DateTimeFormatOptions;
257 /**
258 * {@link toLocaleString} format like '09:30 AM'. Only 12-hour if the locale is.
259 */
260 static readonly TIME_SIMPLE: DateTimeFormatOptions;
261 /**
262 * {@link toLocaleString} format like '09:30:23 AM Eastern Daylight Time'. Only 12-hour if the locale is.
263 */
264 static readonly TIME_WITH_LONG_OFFSET: DateTimeFormatOptions;
265 /**
266 * {@link toLocaleString} format like '09:30:23 AM'. Only 12-hour if the locale is.
267 */
268 static readonly TIME_WITH_SECONDS: DateTimeFormatOptions;
269 /**
270 * {@link toLocaleString} format like '09:30:23 AM EDT'. Only 12-hour if the locale is.
271 */
272 static readonly TIME_WITH_SHORT_OFFSET: DateTimeFormatOptions;
273
274 /**
275 * Create a DateTime from an HTTP header date
276 * @see https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1
277 * @param text - the HTTP header date
278 * @param [options] - options to affect the creation
279 * @param [options.zone='local'] - convert the time to this zone.
280 * 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.
281 * @example
282 * DateTime.fromHTTP('Sun, 06 Nov 1994 08:49:37 GMT')
283 * @example
284 * DateTime.fromHTTP('Sunday, 06-Nov-94 08:49:37 GMT')
285 * @example
286 * DateTime.fromHTTP('Sun Nov 6 08:49:37 1994')
287 */
288 static fromHTTP(text: string, options?: DateTimeOptions): DateTime;
289
290 /**
291 * Create a DateTime from an ISO 8601 string
292 * @example
293 * DateTime.fromISO('2016-05-25T09:08:34.123')
294 * @example
295 * DateTime.fromISO('2016-05-25T09:08:34.123+06:00')
296 * @example
297 * DateTime.fromISO('2016-05-25T09:08:34.123+06:00', {setZone: true})
298 * @example
299 * DateTime.fromISO('2016-05-25T09:08:34.123', {zone: 'utc'})
300 * @example
301 * DateTime.fromISO('2016-W05-4')
302 */
303 static fromISO(text: string, options?: DateTimeOptions): DateTime;
304
305 /**
306 * Create a DateTime from a JavaScript Date object.
307 * Uses the default zone.
308 */
309 static fromJSDate(date: Date, options?: DateTimeJSOptions): DateTime;
310
311 /**
312 * Create a DateTime from a number of milliseconds since the epoch (meaning since 1 January 1970 00:00:00 UTC).
313 * Uses the default zone.
314 */
315 static fromMillis(ms: number, options?: DateTimeOptions): DateTime;
316
317 /**
318 * Create a DateTime from a JavaScript object with keys like 'year' and 'hour' with reasonable defaults.
319 * @example
320 * DateTime.fromObject({ year: 1982, month: 5, day: 25}).toISODate() //=> '1982-05-25'
321 * @example
322 * DateTime.fromObject({ year: 1982 }).toISODate() //=> '1982-01-01'
323 * @example
324 * DateTime.fromObject({ hour: 10, minute: 26, second: 6 }) //~> today at 10:26:06
325 * @example
326 * DateTime.fromObject({ hour: 10, minute: 26, second: 6, zone: 'utc' }),
327 * @example
328 * DateTime.fromObject({ hour: 10, minute: 26, second: 6, zone: 'local' })
329 * @example
330 * DateTime.fromObject({ hour: 10, minute: 26, second: 6, zone: 'America/New_York' })
331 * @example
332 * DateTime.fromObject({ weekYear: 2016, weekNumber: 2, weekday: 3 }).toISODate() //=> '2016-01-13'
333 */
334 static fromObject(obj: DateObject): DateTime;
335
336 /**
337 * Create a DateTime from an RFC 2822 string
338 * @example
339 * DateTime.fromRFC2822('25 Nov 2016 13:23:12 GMT')
340 * @example
341 * DateTime.fromRFC2822('Fri, 25 Nov 2016 13:23:12 +0600')
342 * @example
343 * DateTime.fromRFC2822('25 Nov 2016 13:23 Z')
344 */
345 static fromRFC2822(text: string, options?: DateTimeOptions): DateTime;
346
347 /**
348 * Create a DateTime from a number of seconds since the epoch (meaning since 1 January 1970 00:00:00 UTC).
349 * Uses the default zone.
350 */
351 static fromSeconds(seconds: number, options?: DateTimeOptions): DateTime;
352
353 /**
354 * Create a DateTime from a SQL date, time, or datetime
355 * Defaults to en-US if no locale has been specified, regardless of the system's locale
356 * @example
357 * DateTime.fromSQL('2017-05-15')
358 * @example
359 * DateTime.fromSQL('2017-05-15 09:12:34')
360 * @example
361 * DateTime.fromSQL('2017-05-15 09:12:34.342')
362 * @example
363 * DateTime.fromSQL('2017-05-15 09:12:34.342+06:00')
364 * @example
365 * DateTime.fromSQL('2017-05-15 09:12:34.342 America/Los_Angeles')
366 * @example
367 * DateTime.fromSQL('2017-05-15 09:12:34.342 America/Los_Angeles', { setZone: true })
368 * @example
369 * DateTime.fromSQL('2017-05-15 09:12:34.342', { zone: 'America/Los_Angeles' })
370 * @example
371 * DateTime.fromSQL('09:12:34.342')
372 */
373 static fromSQL(text: string, options?: DateTimeOptions): DateTime;
374
375 /**
376 * Create a DateTime from an input string and format string.
377 * Defaults to en-US if no locale has been specified, regardless of the system's locale.
378 * @see https://moment.github.io/luxon/docs/manual/parsing.html#table-of-tokens
379 */
380 static fromFormat(text: string, format: string, opts?: DateTimeOptions): DateTime;
381
382 /**
383 * Explain how a string would be parsed by {@link fromFormat}
384 */
385 static fromFormatExplain(text: string, format: string, opts?: DateTimeOptions): ExplainedFormat;
386
387 /**
388 * @deprecated since 0.3.0. Use {@link fromFormat} instead
389 */
390 static fromString(text: string, format: string, options?: DateTimeOptions): DateTime;
391
392 /**
393 * @deprecated 0.3.0. Use {@link fromFormatExplain} instead
394 */
395 static fromStringExplain(
396 text: string,
397 format: string,
398 options?: DateTimeOptions,
399 ): ExplainedFormat;
400
401 /**
402 * Create an invalid DateTime.
403 * @param reason - simple string of why this DateTime is invalid.
404 * Should not contain parameters or anything else data-dependent
405 * @param [explanation] - longer explanation, may include parameters and other useful debugging information
406 */
407 static invalid(reason: string, explanation?: string): DateTime;
408
409 /**
410 * Check if an object is a DateTime. Works across context boundaries
411 */
412 static isDateTime(o: any): o is DateTime;
413
414 /**
415 * Create a local DateTime
416 * @param [year] - The calendar year. If omitted (as in, call `local()` with no arguments), the current time will be used
417 * @param [month=1] - The month, 1-indexed
418 * @param [day=1] - The day of the month, 1-indexed
419 * @param [hour=0] - The hour of the day, in 24-hour time
420 * @param [minute=0] - The minute of the hour, meaning a number between 0 and 59
421 * @param [second=0] - The second of the minute, meaning a number between 0 and 59
422 * @param [millisecond=0] - The millisecond of the second, meaning a number between 0 and 999
423 * @example
424 * DateTime.local() //~> now
425 * @example
426 * DateTime.local(2017) //~> 2017-01-01T00:00:00
427 * @example
428 * DateTime.local(2017, 3) //~> 2017-03-01T00:00:00
429 * @example
430 * DateTime.local(2017, 3, 12) //~> 2017-03-12T00:00:00
431 * @example
432 * DateTime.local(2017, 3, 12, 5) //~> 2017-03-12T05:00:00
433 * @example
434 * DateTime.local(2017, 3, 12, 5, 45) //~> 2017-03-12T05:45:00
435 * @example
436 * DateTime.local(2017, 3, 12, 5, 45, 10) //~> 2017-03-12T05:45:10
437 * @example
438 * DateTime.local(2017, 3, 12, 5, 45, 10, 765) //~> 2017-03-12T05:45:10.765
439 */
440 static local(
441 year?: number,
442 month?: number,
443 day?: number,
444 hour?: number,
445 minute?: number,
446 second?: number,
447 millisecond?: number,
448 ): DateTime;
449
450 /** Return the maximum of several date times */
451 static max(): undefined;
452 /** Return the maximum of several date times */
453 static max(...dateTimes: DateTime[]): DateTime;
454
455 /** Return the minimum of several date times */
456 static min(): undefined;
457 /** Return the minimum of several date times */
458 static min(...dateTimes: DateTime[]): DateTime;
459
460 /**
461 * Create a DateTime for the current instant, in the system's time zone.
462 *
463 * Use Settings to override these default values if needed.
464 * @example
465 * DateTime.now().toISO() //~> now in the ISO format
466 */
467 static now(): DateTime;
468
469 /**
470 * Create a DateTime in UTC
471 * @param [year] - The calendar year. If omitted (as in, call `utc()` with no arguments), the current time will be used
472 * @param [month=1] - The month, 1-indexed
473 * @param [day=1] - The day of the month
474 * @param [hour=0] - The hour of the day, in 24-hour time
475 * @param [minute=0] - The minute of the hour, meaning a number between 0 and 59
476 * @param [second=0] - The second of the minute, meaning a number between 0 and 59
477 * @param [millisecond=0] - The millisecond of the second, meaning a number between 0 and 999
478 * @example
479 * DateTime.utc() //~> now
480 * @example
481 * DateTime.utc(2017) //~> 2017-01-01T00:00:00Z
482 * @example
483 * DateTime.utc(2017, 3) //~> 2017-03-01T00:00:00Z
484 * @example
485 * DateTime.utc(2017, 3, 12) //~> 2017-03-12T00:00:00Z
486 * @example
487 * DateTime.utc(2017, 3, 12, 5) //~> 2017-03-12T05:00:00Z
488 * @example
489 * DateTime.utc(2017, 3, 12, 5, 45) //~> 2017-03-12T05:45:00Z
490 * @example
491 * DateTime.utc(2017, 3, 12, 5, 45, 10) //~> 2017-03-12T05:45:10Z
492 * @example
493 * DateTime.utc(2017, 3, 12, 5, 45, 10, 765) //~> 2017-03-12T05:45:10.765Z
494 */
495 static utc(
496 year?: number,
497 month?: number,
498 day?: number,
499 hour?: number,
500 minute?: number,
501 second?: number,
502 millisecond?: number,
503 ): DateTime;
504
505 /**
506 * Get the day of the month (1-30ish).
507 * @example
508 * DateTime.local(2017, 5, 25).day //=> 25
509 */
510 day: number;
511 /**
512 * Returns the number of days in this DateTime's month
513 * @example
514 * DateTime.local(2016, 2).daysInMonth //=> 29
515 * @example
516 * DateTime.local(2016, 3).daysInMonth //=> 31
517 */
518 daysInMonth: number;
519 /**
520 * Returns the number of days in this DateTime's year
521 * @example
522 * DateTime.local(2016).daysInYear //=> 366
523 * @example
524 * DateTime.local(2013).daysInYear //=> 365
525 */
526 daysInYear: number;
527 /**
528 * Get the hour of the day (0-23).
529 * @example
530 * DateTime.local(2017, 5, 25, 9).hour //=> 9
531 */
532 hour: number;
533 /**
534 * Returns an error code if this DateTime is invalid, or null if the DateTime is valid
535 */
536 invalidReason: string | null;
537 /**
538 * Returns an explanation of why this DateTime became invalid, or null if the DateTime is valid
539 */
540 invalidExplanation: string | null;
541 /**
542 * Get whether the DateTime is in a DST.
543 */
544 isInDST: boolean;
545 /**
546 * Returns true if this DateTime is in a leap year, false otherwise
547 * @example
548 * DateTime.local(2016).isInLeapYear //=> true
549 * @example
550 * DateTime.local(2013).isInLeapYear //=> false
551 */
552 isInLeapYear: boolean;
553 /**
554 * Get whether this zone's offset ever changes, as in a DST.
555 */
556 isOffsetFixed: boolean;
557 /**
558 * Returns whether the DateTime is valid. Invalid DateTimes occur when:
559 * * The DateTime was created from invalid calendar information, such as the 13th month or February 30
560 * * The DateTime was created by an operation on another invalid date
561 */
562 isValid: boolean;
563 /**
564 * Get the locale of a DateTime, such 'en-GB'. The locale is used when formatting the DateTime
565 *
566 */
567 locale: string;
568 /**
569 * Get the millisecond of the second (0-999).
570 * @example
571 * DateTime.local(2017, 5, 25, 9, 30, 52, 654).millisecond //=> 654
572 */
573 millisecond: number;
574 /**
575 * Get the minute of the hour (0-59).
576 * @example
577 * DateTime.local(2017, 5, 25, 9, 30).minute //=> 30
578 */
579 minute: number;
580 /**
581 * Get the month (1-12).
582 * @example
583 * DateTime.local(2017, 5, 25).month //=> 5
584 */
585 month: number;
586 /**
587 * Get the human readable long month name, such as 'October'.
588 * Defaults to the system's locale if no locale has been specified
589 * @example
590 * DateTime.local(2017, 10, 30).monthLong //=> October
591 */
592 monthLong: string;
593 /**
594 * Get the human readable short month name, such as 'Oct'.
595 * Defaults to the system's locale if no locale has been specified
596 * @example
597 * DateTime.local(2017, 10, 30).monthShort //=> Oct
598 */
599 monthShort: string;
600 /**
601 * Get the numbering system of a DateTime, such 'beng'. The numbering system is used when formatting the DateTime
602 *
603 */
604 numberingSystem: string;
605 /**
606 * Get the UTC offset of this DateTime in minutes
607 * @example
608 * DateTime.now().offset //=> -240
609 * @example
610 * DateTime.utc().offset //=> 0
611 */
612 offset: number;
613 /**
614 * Get the long human name for the zone's current offset, for example "Eastern Standard Time" or "Eastern Daylight Time".
615 * Defaults to the system's locale if no locale has been specified
616 */
617 offsetNameLong: string;
618 /**
619 * Get the short human name for the zone's current offset, for example "EST" or "EDT".
620 * Defaults to the system's locale if no locale has been specified
621 */
622 offsetNameShort: string;
623 /**
624 * Get the ordinal (meaning the day of the year)
625 * @example
626 * DateTime.local(2017, 5, 25).ordinal //=> 145
627 */
628 ordinal: number;
629
630 /**
631 * Get the output calendar of a DateTime, such 'islamic'. The output calendar is used when formatting the DateTime
632 */
633 outputCalendar: string;
634 /**
635 * Get the quarter
636 * @example
637 * DateTime.local(2017, 5, 25).quarter //=> 2
638 */
639 quarter: number;
640 /**
641 * Get the second of the minute (0-59).
642 * @example
643 * DateTime.local(2017, 5, 25, 9, 30, 52).second //=> 52
644 */
645 second: number;
646 /**
647 * Get the week number of the week year (1-52ish).
648 * @see https://en.wikipedia.org/wiki/ISO_week_date
649 * @example
650 * DateTime.local(2017, 5, 25).weekNumber //=> 21
651 */
652 weekNumber: number;
653 /**
654 * Get the week year
655 * @see https://en.wikipedia.org/wiki/ISO_week_date
656 * @example
657 * DateTime.local(2014, 11, 31).weekYear //=> 2015
658 */
659 weekYear: number;
660 /**
661 * Get the day of the week.
662 * 1 is Monday and 7 is Sunday
663 * @see https://en.wikipedia.org/wiki/ISO_week_date
664 * @example
665 * DateTime.local(2014, 11, 31).weekday //=> 4
666 */
667 weekday: number;
668 /**
669 * Get the human readable long weekday, such as 'Monday'.
670 * Defaults to the system's locale if no locale has been specified
671 * @example
672 * DateTime.local(2017, 10, 30).weekdayLong //=> Monday
673 */
674 weekdayLong: string;
675 /**
676 * Get the human readable short weekday, such as 'Mon'.
677 * Defaults to the system's locale if no locale has been specified
678 * @example
679 * DateTime.local(2017, 10, 30).weekdayShort //=> Mon
680 */
681 weekdayShort: string;
682 /**
683 * Returns the number of weeks in this DateTime's year
684 * @see https://en.wikipedia.org/wiki/ISO_week_date
685 * @example
686 * DateTime.local(2004).weeksInWeekYear //=> 53
687 * @example
688 * DateTime.local(2013).weeksInWeekYear //=> 52
689 */
690 weeksInWeekYear: number;
691 /**
692 * Get the year
693 * @example
694 * DateTime.local(2017, 5, 25).year //=> 2017
695 */
696 year: number;
697 /**
698 * Get the name of the time zone.
699 */
700 zoneName: string;
701 /**
702 * Get the time zone associated with this DateTime.
703 */
704 zone: Zone;
705
706 /**
707 * Return the difference between two DateTimes as a Duration.
708 * @param other - the DateTime to compare this one to
709 * @param [unit=['milliseconds']] - the unit or array of units (such as 'hours' or 'days') to include in the duration.
710 * @param [options] - options that affect the creation of the Duration
711 * @param [options.conversionAccuracy='casual'] - the conversion system to use
712 * @example
713 * let i1 = DateTime.fromISO('1982-05-25T09:45'),
714 * i2 = DateTime.fromISO('1983-10-14T10:30');
715 * i2.diff(i1).toObject() //=> { milliseconds: 43807500000 }
716 * i2.diff(i1, 'hours').toObject() //=> { hours: 12168.75 }
717 * i2.diff(i1, ['months', 'days']).toObject() //=> { months: 16, days: 19.03125 }
718 * i2.diff(i1, ['months', 'days', 'hours']).toObject() //=> { months: 16, days: 19, hours: 0.75 }
719 */
720 diff(other: DateTime, unit?: DurationUnits, options?: DiffOptions): Duration;
721
722 /**
723 * Return the difference between this DateTime and right now.
724 * See {@link diff}
725 * @param [unit=['milliseconds']] - the unit or units units (such as 'hours' or 'days') to include in the duration
726 * @param [options] - options that affect the creation of the Duration
727 * @param [options.conversionAccuracy='casual'] - the conversion system to use
728 */
729 diffNow(unit?: DurationUnits, options?: DiffOptions): Duration;
730
731 /**
732 * "Set" this DateTime to the end (meaning the last millisecond) of a unit of time
733 * @example
734 * DateTime.local(2014, 3, 3).endOf('month').toISO(); //=> '2014-03-31T23:59:59.999-05:00'
735 * @example
736 * DateTime.local(2014, 3, 3).endOf('year').toISO(); //=> '2014-12-31T23:59:59.999-05:00'
737 * @example
738 * DateTime.local(2014, 3, 3).endOf('week').toISO(); // => '2014-03-09T23:59:59.999-05:00', weeks start on Mondays
739 * @example
740 * DateTime.local(2014, 3, 3, 5, 30).endOf('day').toISO(); //=> '2014-03-03T23:59:59.999-05:00'
741 * @example
742 * DateTime.local(2014, 3, 3, 5, 30).endOf('hour').toISO(); //=> '2014-03-03T05:59:59.999-05:00'
743 */
744 endOf(unit: DurationUnit): DateTime;
745
746 /**
747 * Equality check
748 * Two DateTimes are equal if they represent the same millisecond, have the same zone and location, and are both valid.
749 * To compare just the millisecond values, use `+dt1 === +dt2`.
750 */
751 equals(other: DateTime): boolean;
752
753 /**
754 * Get the value of unit.
755 * @example
756 * DateTime.local(2017, 7, 4).get('month'); //=> 7
757 * @example
758 * DateTime.local(2017, 7, 4).get('day'); //=> 4
759 */
760 get(unit: keyof DateTime): number;
761
762 /**
763 * Return whether this DateTime is in the same unit of time as another DateTime.
764 * Higher-order units must also be identical for this function to return `true`.
765 * Note that time zones are **ignored** in this comparison, which compares the **local** calendar time. Use {@link setZone} to convert one of the dates if needed.
766 * @example
767 * DateTime.now().hasSame(otherDT, 'day'); //~> true if otherDT is in the same current calendar day
768 */
769 hasSame(other: DateTime, unit: DurationUnit): boolean;
770
771 /**
772 * Subtract a period of time to this DateTime and return the resulting DateTime
773 * See {@link plus}
774 */
775 minus(duration: DurationInput): DateTime;
776
777 /**
778 * Add a period of time to this DateTime and return the resulting DateTime
779 *
780 * Adding hours, minutes, seconds, or milliseconds increases the timestamp by the right number of milliseconds.
781 * Adding days, months, or years shifts the calendar, accounting for DSTs and leap years along the way.
782 * Thus, `dt.plus({ hours: 24 })` may result in a different time than `dt.plus({ days: 1 })` if there's a DST shift in between.
783 * @example
784 * DateTime.now().plus(123) //~> in 123 milliseconds
785 * @example
786 * DateTime.now().plus({ minutes: 15 }) //~> in 15 minutes
787 * @example
788 * DateTime.now().plus({ days: 1 }) //~> this time tomorrow
789 * @example
790 * DateTime.now().plus({ days: -1 }) //~> this time yesterday
791 * @example
792 * DateTime.now().plus({ hours: 3, minutes: 13 }) //~> in 3 hr, 13 min
793 * @example
794 * DateTime.now().plus(Duration.fromObject({ hours: 3, minutes: 13 })) //~> in 3 hr, 13 min
795 */
796 plus(duration: DurationInput): DateTime;
797
798 /**
799 * "Set" the locale options. Returns a newly-constructed DateTime.
800 */
801 reconfigure(properties: LocaleOptions): DateTime;
802
803 /**
804 * Returns the resolved Intl options for this DateTime.
805 * This is useful in understanding the behavior of formatting methods
806 */
807 resolvedLocaleOpts(options?: LocaleOptions & DateTimeFormatOptions): Intl.ResolvedDateTimeFormatOptions;
808
809 /**
810 * "Set" the values of specified units. Returns a newly-constructed DateTime.
811 * You can only set units with this method; for setting metadata, see {@link reconfigure} and {@link setZone}.
812 */
813 set(values: DateObjectUnits): DateTime;
814
815 /**
816 * "Set" the locale. Returns a newly-constructed DateTime.
817 * Just a convenient alias for reconfigure({ locale })
818 */
819 setLocale(locale: string): DateTime;
820
821 /**
822 * "Set" the DateTime's zone to specified zone. Returns a newly-constructed DateTime.
823 *
824 * By default, the setter keeps the underlying time the same (as in, the same timestamp), but the new instance will
825 * report different local times and consider DSTs when making computations, as with {@link plus}.
826 * You may wish to use {@link toLocal} and {@link toUTC} which provide simple convenience wrappers for commonly used zones.
827 *
828 * @param zone - a zone identifier. As a string, that can be any IANA zone supported by the host environment,
829 * or a fixed-offset name of the form 'UTC+3', or the strings 'local' or 'utc'.
830 * You may also supply an instance of a {@link Zone} class.
831 * @param [options] - options
832 */
833 setZone(zone: string | Zone, options?: ZoneOptions): DateTime;
834
835 /**
836 * "Set" this DateTime to the beginning of a unit of time.
837 * @example
838 * DateTime.local(2014, 3, 3).startOf('month').toISODate(); //=> '2014-03-01'
839 * @example
840 * DateTime.local(2014, 3, 3).startOf('year').toISODate(); //=> '2014-01-01'
841 * @example
842 * DateTime.local(2014, 3, 3).startOf('week').toISODate(); //=> '2014-03-03', weeks always start on Mondays
843 * @example
844 * DateTime.local(2014, 3, 3, 5, 30).startOf('day').toISOTime(); //=> '00:00.000-05:00'
845 * @example
846 * DateTime.local(2014, 3, 3, 5, 30).startOf('hour').toISOTime(); //=> '05:00:00.000-05:00'
847 */
848 startOf(unit: DurationUnit): DateTime;
849
850 /**
851 * Returns a BSON serializable equivalent to this DateTime.
852 */
853 toBSON(): Date;
854
855 /**
856 * Returns a string representation of this DateTime formatted according to the specified format string.
857 *
858 * **You may not want this.** See {@link toLocaleString} for a more flexible formatting tool.
859 *
860 * For a table of tokens and their interpretations, see [here](https://moment.github.io/luxon/docs/manual/formatting.html#table-of-tokens).
861 *
862 * Defaults to en-US if no locale has been specified, regardless of the system's locale.
863 *
864 * @see https://moment.github.io/luxon/docs/manual/formatting.html#table-of-tokens
865 * @example
866 * DateTime.now().toFormat('yyyy LLL dd') //=> '2017 Apr 22'
867 * @example
868 * DateTime.now().setLocale('fr').toFormat('yyyy LLL dd') //=> '2017 avr. 22'
869 * @example
870 * DateTime.now().toFormat('yyyy LLL dd', { locale: "fr" }) //=> '2017 avr. 22'
871 * @example
872 * DateTime.now().toFormat("HH 'hours and' mm 'minutes'") //=> '20 hours and 55 minutes'
873 */
874 toFormat(format: string, options?: LocaleOptions & DateTimeFormatOptions): string;
875
876 /**
877 * Returns a string representation of this DateTime appropriate for use in HTTP headers.
878 * Specifically, the string conforms to RFC 1123.
879 * @see https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1
880 * @example
881 * DateTime.utc(2014, 7, 13).toHTTP() //=> 'Sun, 13 Jul 2014 00:00:00 GMT'
882 * @example
883 * DateTime.utc(2014, 7, 13, 19).toHTTP() //=> 'Sun, 13 Jul 2014 19:00:00 GMT'
884 */
885 toHTTP(): string;
886
887 /**
888 * Returns an ISO 8601-compliant string representation of this DateTime
889 * @example
890 * DateTime.utc(1982, 5, 25).toISO() //=> '1982-05-25T00:00:00.000Z'
891 * @example
892 * DateTime.now().toISO() //=> '2017-04-22T20:47:05.335-04:00'
893 * @example
894 * DateTime.now().toISO({ includeOffset: false }) //=> '2017-04-22T20:47:05.335'
895 * @example
896 * DateTime.now().toISO({ format: 'basic' }) //=> '20170422T204705.335-0400'
897 */
898 toISO(options?: ToISOTimeOptions): string;
899
900 /**
901 * Returns an ISO 8601-compliant string representation of this DateTime's date component
902 * @example
903 * DateTime.utc(1982, 5, 25).toISODate() //=> '1982-05-25'
904 * @example
905 * DateTime.utc(1982, 5, 25).toISODate({ format: 'basic' }) //=> '19820525'
906 */
907 toISODate(options?: ToISODateOptions): string;
908
909 /**
910 * Returns an ISO 8601-compliant string representation of this DateTime's time component
911 * @example
912 * DateTime.utc().set({ hour: 7, minute: 34 }).toISOTime() //=> '07:34:19.361Z'
913 * @example
914 * DateTime.utc().set({ hour: 7, minute: 34, seconds: 0, milliseconds: 0 }).toISOTime({ suppressSeconds: true }) //=> '07:34Z'
915 * @example
916 * DateTime.utc().set({ hour: 7, minute: 34 }).toISOTime({ format: 'basic' }) //=> '073419.361Z'
917 * @example
918 * DateTime.utc().set({ hour: 7, minute: 34 }).toISOTime({ includePrefix: true }) //=> 'T07:34:19.361Z'
919 */
920 toISOTime(options?: ToISOTimeOptions): string;
921
922 /**
923 * Returns an ISO 8601-compliant string representation of this DateTime's week date
924 * @example
925 * DateTime.utc(1982, 5, 25).toISOWeekDate() //=> '1982-W21-2'
926 */
927 toISOWeekDate(): string;
928
929 /**
930 * Returns a JavaScript Date equivalent to this DateTime.
931 */
932 toJSDate(): Date;
933
934 /**
935 * Returns an ISO 8601 representation of this DateTime appropriate for use in JSON.
936 * Called implicitly via {@link JSON.stringify}
937 */
938 toJSON(): string;
939
940 /**
941 * "Set" the DateTime's zone to the host's local zone. Returns a newly-constructed DateTime.
942 *
943 * Equivalent to {@link setZone}('local')
944 */
945 toLocal(): DateTime;
946
947 /**
948 * Returns an array of format "parts", meaning individual tokens along with metadata.
949 * This is allows callers to post-process individual sections of the formatted output.
950 * Defaults to the system's locale if no locale has been specified
951 * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/formatToParts
952 * @example
953 * DateTime.now().toLocaleParts(); //=> [
954 * //=> { type: 'day', value: '25' },
955 * //=> { type: 'literal', value: '/' },
956 * //=> { type: 'month', value: '05' },
957 * //=> { type: 'literal', value: '/' },
958 * //=> { type: 'year', value: '1982' }
959 * //=> ]
960 */
961 toLocaleParts(options?: LocaleOptions & DateTimeFormatOptions): any[];
962
963 /**
964 * Returns a localized string representing this date.
965 * Accepts the same options as the Intl.DateTimeFormat constructor and any presets defined by Luxon, such as {@link DateTime.DATE_FULL} or {@link DateTime.TIME_SIMPLE}.
966 * The exact behavior of this method is browser-specific, but in general it will return an appropriate representation
967 * of the DateTime in the assigned locale.
968 * Defaults to the system's locale if no locale has been specified
969 * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
970 * @example
971 * DateTime.now().toLocaleString(); //=> 4/20/2017
972 * @example
973 * DateTime.now().setLocale('en-gb').toLocaleString(); //=> '20/04/2017'
974 * @example
975 * DateTime.now().toLocaleString({ locale: 'en-gb' }); //=> '20/04/2017'
976 * @example
977 * DateTime.now().toLocaleString(DateTime.DATE_FULL); //=> 'April 20, 2017'
978 * @example
979 * DateTime.now().toLocaleString(DateTime.TIME_SIMPLE); //=> '11:32 AM'
980 * @example
981 * DateTime.now().toLocaleString(DateTime.DATETIME_SHORT); //=> '4/20/2017, 11:32 AM'
982 * @example
983 * DateTime.now().toLocaleString({ weekday: 'long', month: 'long', day: '2-digit' }); //=> 'Thursday, April 20'
984 * @example
985 * DateTime.now().toLocaleString({ weekday: 'short', month: 'short', day: '2-digit', hour: '2-digit', minute: '2-digit' }); //=> 'Thu, Apr 20, 11:27 AM'
986 * @example
987 * DateTime.now().toLocaleString({ hour: '2-digit', minute: '2-digit', hour12: false }); //=> '11:32'
988 */
989 toLocaleString(options?: LocaleOptions & DateTimeFormatOptions): string;
990
991 /**
992 * Returns the epoch milliseconds of this DateTime.
993 */
994 toMillis(): number;
995
996 /**
997 * Returns a JavaScript object with this DateTime's year, month, day, and so on.
998 * @example
999 * DateTime.now().toObject() //=> { year: 2017, month: 4, day: 22, hour: 20, minute: 49, second: 42, millisecond: 268 }
1000 */
1001 toObject(options?: {
1002 /**
1003 * Include configuration attributes in the output
1004 * @default false
1005 */
1006 includeConfig?: boolean
1007 }): DateObject;
1008
1009 /**
1010 * Returns a string representation of a this time relative to now, such as "in two days".
1011 * Can only internationalize if your platform supports Intl.RelativeTimeFormat. Rounds down by default.
1012 * @example
1013 * DateTime.now().plus({ days: 1 }).toRelative() //=> "in 1 day"
1014 * @example
1015 * DateTime.now().setLocale("es").toRelative({ days: 1 }) //=> "dentro de 1 día"
1016 * @example
1017 * DateTime.now().plus({ days: 1 }).toRelative({ locale: "fr" }) //=> "dans 23 heures"
1018 * @example
1019 * DateTime.now().minus({ days: 2 }).toRelative() //=> "2 days ago"
1020 * @example
1021 * DateTime.now().minus({ days: 2 }).toRelative({ unit: "hours" }) //=> "48 hours ago"
1022 * @example
1023 * DateTime.now().minus({ hours: 36 }).toRelative({ round: false }) //=> "1.5 days ago"
1024 */
1025 toRelative(options?: ToRelativeOptions): string | null;
1026
1027 /**
1028 * Returns a string representation of this date relative to today, such as "yesterday" or "next month".
1029 * Only internationalizes on platforms that supports Intl.RelativeTimeFormat.
1030 * @example
1031 * DateTime.now().plus({ days: 1 }).toRelativeCalendar() //=> "tomorrow"
1032 * @example
1033 * DateTime.now().setLocale("es").plus({ days: 1 }).toRelative() //=> "mañana"
1034 * @example
1035 * DateTime.now().plus({ days: 1 }).toRelativeCalendar({ locale: "fr" }) //=> "demain"
1036 * @example
1037 * DateTime.now().minus({ days: 2 }).toRelativeCalendar() //=> "2 days ago"
1038 */
1039 toRelativeCalendar(options?: ToRelativeCalendarOptions): string | null;
1040
1041 /**
1042 * Returns an RFC 2822-compatible string representation of this DateTime, always in UTC
1043 * @example
1044 * DateTime.utc(2014, 7, 13).toRFC2822() //=> 'Sun, 13 Jul 2014 00:00:00 +0000'
1045 * @example
1046 * DateTime.local(2014, 7, 13).toRFC2822() //=> 'Sun, 13 Jul 2014 00:00:00 -0400'
1047 */
1048 toRFC2822(): string;
1049
1050 /**
1051 * Returns the epoch seconds of this DateTime.
1052 */
1053 toSeconds(): number;
1054
1055 /**
1056 * Returns a string representation of this DateTime appropriate for use in SQL DateTime
1057 * @example
1058 * DateTime.utc(2014, 7, 13).toSQL() //=> '2014-07-13 00:00:00.000 Z'
1059 * @example
1060 * DateTime.local(2014, 7, 13).toSQL() //=> '2014-07-13 00:00:00.000 -04:00'
1061 * @example
1062 * DateTime.local(2014, 7, 13).toSQL({ includeOffset: false }) //=> '2014-07-13 00:00:00.000'
1063 * @example
1064 * DateTime.local(2014, 7, 13).toSQL({ includeZone: true }) //=> '2014-07-13 00:00:00.000 America/New_York'
1065 */
1066 toSQL(options?: ToSQLOptions): string;
1067
1068 /**
1069 * Returns a string representation of this DateTime appropriate for use in SQL Date
1070 * @example
1071 * DateTime.utc(2014, 7, 13).toSQLDate() //=> '2014-07-13'
1072 */
1073 toSQLDate(): string;
1074
1075 /**
1076 * Returns a string representation of this DateTime appropriate for use in SQL Time
1077 * @example
1078 * DateTime.utc().toSQL() //=> '05:15:16.345'
1079 * @example
1080 * DateTime.now().toSQL() //=> '05:15:16.345 -04:00'
1081 * @example
1082 * DateTime.now().toSQL({ includeOffset: false }) //=> '05:15:16.345'
1083 * @example
1084 * DateTime.now().toSQL({ includeZone: false }) //=> '05:15:16.345 America/New_York'
1085 */
1086 toSQLTime(options?: ToSQLOptions): string;
1087
1088 /**
1089 * Returns a string representation of this DateTime appropriate for debugging
1090 */
1091 toString(): string;
1092
1093 /**
1094 * "Set" the DateTime's zone to UTC. Returns a newly-constructed DateTime.
1095 *
1096 * Equivalent to {@link setZone}('utc')
1097 * @param [offset=0] - optionally, an offset from UTC in minutes
1098 * @param [options] - options to pass to `setZone()`
1099 */
1100 toUTC(offset?: number, options?: ZoneOptions): DateTime;
1101
1102 /**
1103 * Return an Interval spanning between this DateTime and another DateTime
1104 */
1105 until(other: DateTime): Interval;
1106
1107 /**
1108 * Returns the epoch milliseconds of this DateTime. Alias of {@link toMillis}
1109 * Called implicitly when coercing types.
1110 */
1111 valueOf(): number;
1112}