UNPKG

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