UNPKG

7.32 kBTypeScriptView Raw
1import { CalendarSystem, NumberingSystem, StringUnitLength, UnitLength } from './misc';
2import { Zone } from './zone';
3
4export interface InfoOptions {
5 locale?: string | undefined;
6}
7
8export interface InfoUnitOptions extends InfoOptions {
9 numberingSystem?: NumberingSystem | undefined;
10}
11
12/** @deprecated */
13export type UnitOptions = InfoUnitOptions;
14
15export interface InfoCalendarOptions extends InfoUnitOptions {
16 outputCalendar?: CalendarSystem | undefined;
17}
18
19/**
20 * The set of available features in this environment. Some features of Luxon are not available in all environments.
21 */
22export interface Features {
23 /**
24 * Whether this environment supports relative time formatting
25 */
26 relative: boolean;
27}
28
29/**
30 * The Info class contains static methods for retrieving general time and date related data. For example, it has methods for finding out if a time zone has a DST, for listing the months in any
31 * supported locale, and for discovering which of Luxon features are available in the current environment.
32 */
33export namespace Info {
34 /**
35 * Return whether the specified zone contains a DST.
36 *
37 * @param zone - Zone to check. Defaults to the environment's local zone. Defaults to 'local'.
38 */
39 function hasDST(zone?: string | Zone): boolean;
40
41 /**
42 * Return whether the specified zone is a valid IANA specifier.
43 *
44 * @param zone - Zone to check
45 */
46 function isValidIANAZone(zone: string): boolean;
47
48 /**
49 * Converts the input into a {@link Zone} instance.
50 *
51 * * If `input` is already a Zone instance, it is returned unchanged.
52 * * If `input` is a string containing a valid time zone name, a Zone instance
53 * with that name is returned.
54 * * If `input` is a string that doesn't refer to a known time zone, a Zone
55 * instance with {@link Zone.isValid} == false is returned.
56 * * If `input is a number, a Zone instance with the specified fixed offset
57 * in minutes is returned.
58 * * If `input` is `null` or `undefined`, the default zone is returned.
59 *
60 * @param input - the value to be converted
61 */
62 function normalizeZone(input?: string | Zone | number): Zone;
63
64 /**
65 * Return an array of standalone month names.
66 * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
67 *
68 * @param length - the length of the month representation, such as "numeric", "2-digit", "narrow", "short", "long". Defaults to 'long'.
69 * @param opts - options
70 * @param opts.locale - the locale code
71 * @param opts.numberingSystem - the numbering system. Defaults to null.
72 * @param opts.locObj - an existing locale object to use. Defaults to null.
73 * @param opts.outputCalendar - the calendar. Defaults to 'gregory'.
74 *
75 * @example
76 * Info.months()[0] //=> 'January'
77 * @example
78 * Info.months('short')[0] //=> 'Jan'
79 * @example
80 * Info.months('numeric')[0] //=> '1'
81 * @example
82 * Info.months('short', { locale: 'fr-CA' } )[0] //=> 'janv.'
83 * @example
84 * Info.months('numeric', { locale: 'ar' })[0] //=> '١'
85 * @example
86 * Info.months('long', { outputCalendar: 'islamic' })[0] //=> 'Rabiʻ I'
87 */
88 function months(length?: UnitLength, opts?: InfoCalendarOptions): string[];
89
90 /**
91 * Return an array of format month names.
92 * Format months differ from standalone months in that they're meant to appear next to the day of the month. In some languages, that
93 * changes the string.
94 * See {@link Info#months}
95 *
96 * @param length - the length of the month representation, such as "numeric", "2-digit", "narrow", "short", "long". Defaults to 'long'.
97 * @param opts - options
98 * @param opts.locale - the locale code
99 * @param opts.numberingSystem - the numbering system. Defaults to null.
100 * @param opts.locObj - an existing locale object to use. Defaults to null.
101 * @param opts.outputCalendar - the calendar. Defaults to 'gregory'.
102 */
103 function monthsFormat(length?: UnitLength, options?: InfoCalendarOptions): string[];
104
105 /**
106 * Return an array of standalone week names.
107 * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
108 *
109 * @param length - the length of the weekday representation, such as "narrow", "short", "long". Defaults to 'long'.
110 * @param opts - options
111 * @param opts.locale - the locale code
112 * @param opts.numberingSystem - the numbering system. Defaults to null.
113 * @param opts.locObj - an existing locale object to use. Defaults to null.
114 *
115 * @example
116 * Info.weekdays()[0] //=> 'Monday'
117 * @example
118 * Info.weekdays('short')[0] //=> 'Mon'
119 * @example
120 * Info.weekdays('short', { locale: 'fr-CA' })[0] //=> 'lun.'
121 * @example
122 * Info.weekdays('short', { locale: 'ar' })[0] //=> 'الاثنين'
123 */
124 function weekdays(length?: StringUnitLength, options?: InfoUnitOptions): string[];
125
126 /**
127 * Return an array of format week names.
128 * Format weekdays differ from standalone weekdays in that they're meant to appear next to more date information. In some languages, that
129 * changes the string.
130 * See {@link Info#weekdays}
131 *
132 * @param length - the length of the month representation, such as "narrow", "short", "long". Defaults to 'long'.
133 * @param opts - options
134 * @param opts.locale - the locale code. Defaults to null.
135 * @param opts.numberingSystem - the numbering system. Defaults to null.
136 * @param opts.locObj - an existing locale object to use. Defaults to null.
137 */
138 function weekdaysFormat(length?: StringUnitLength, options?: InfoUnitOptions): string[];
139
140 /**
141 * Return an array of meridiems.
142 *
143 * @param opts - options
144 * @param opts.locale - the locale code
145 *
146 * @example
147 * Info.meridiems() //=> [ 'AM', 'PM' ]
148 * @example
149 * Info.meridiems({ locale: 'my' }) //=> [ 'နံနက်', 'ညနေ' ]
150 */
151 function meridiems(options?: InfoOptions): string[];
152
153 /**
154 * Return an array of eras, such as ['BC', 'AD']. The locale can be specified, but the calendar system is always Gregorian.
155 *
156 * @param length - the length of the era representation, such as "short" or "long". Defaults to 'short'.
157 * @param opts - options
158 * @param opts.locale - the locale code
159 *
160 * @example
161 * Info.eras() //=> [ 'BC', 'AD' ]
162 * @example
163 * Info.eras('long') //=> [ 'Before Christ', 'Anno Domini' ]
164 * @example
165 * Info.eras('long', { locale: 'fr' }) //=> [ 'avant Jésus-Christ', 'après Jésus-Christ' ]
166 */
167 function eras(length?: StringUnitLength, options?: InfoOptions): string[];
168
169 /**
170 * Return the set of available features in this environment.
171 * Some features of Luxon are not available in all environments. For example, on older browsers, timezone support is not available. Use this function to figure out if that's the case.
172 * Keys:
173 * * `relative`: whether this environment supports relative time formatting
174 *
175 * @example
176 * Info.features() //=> { intl: true, intlTokens: false, zones: true, relative: false }
177 */
178 function features(): Features;
179}