0
# Info & Settings API
1
2
The Info and Settings classes provide utilities for locale information, timezone validation, and global configuration of Luxon's behavior.
3
4
## Capabilities
5
6
### Info Class
7
8
Static utility class for accessing locale and timezone information.
9
10
```javascript { .api }
11
/**
12
* Static utility class for locale and timezone information
13
*/
14
class Info {
15
/**
16
* Check if timezone has daylight saving time
17
* @param zone - Timezone name or Zone instance (defaults to system timezone)
18
*/
19
static hasDST(zone?: string | Zone): boolean;
20
21
/**
22
* Check if timezone name is valid in IANA database
23
* @param zone - IANA timezone name to validate
24
*/
25
static isValidIANAZone(zone: string): boolean;
26
27
/**
28
* Convert various inputs to Zone instance
29
* @param input - Zone name, offset number, or Zone instance
30
*/
31
static normalizeZone(input: string | number | Zone): Zone;
32
33
/**
34
* Get array of month names in specified locale
35
* @param length - Name length ('long', 'short', 'narrow')
36
* @param opts - Options including locale, numberingSystem, outputCalendar
37
*/
38
static months(length?: string, opts?: object): string[];
39
40
/**
41
* Get array of month names for formatting (standalone vs format context)
42
* @param length - Name length ('long', 'short', 'narrow')
43
* @param opts - Options including locale, numberingSystem, outputCalendar
44
*/
45
static monthsFormat(length?: string, opts?: object): string[];
46
47
/**
48
* Get array of weekday names in specified locale
49
* @param length - Name length ('long', 'short', 'narrow')
50
* @param opts - Options including locale, numberingSystem, outputCalendar
51
*/
52
static weekdays(length?: string, opts?: object): string[];
53
54
/**
55
* Get array of weekday names for formatting
56
* @param length - Name length ('long', 'short', 'narrow')
57
* @param opts - Options including locale, numberingSystem, outputCalendar
58
*/
59
static weekdaysFormat(length?: string, opts?: object): string[];
60
61
/**
62
* Get array of meridiem names (AM/PM) in specified locale
63
* @param opts - Options including locale
64
*/
65
static meridiems(opts?: object): string[];
66
67
/**
68
* Get array of era names in specified locale
69
* @param length - Name length ('long', 'short', 'narrow')
70
* @param opts - Options including locale, numberingSystem, outputCalendar
71
*/
72
static eras(length?: string, opts?: object): string[];
73
74
/**
75
* Get information about available features in current environment
76
*/
77
static features(): {
78
intl: boolean;
79
intlTokens: boolean;
80
zones: boolean;
81
relative: boolean;
82
};
83
}
84
```
85
86
### Settings Class
87
88
Static class for global Luxon configuration.
89
90
```javascript { .api }
91
/**
92
* Global configuration class for Luxon behavior
93
*/
94
class Settings {
95
/**
96
* Function that returns current timestamp (for testing/mocking)
97
* Default: () => Date.now()
98
*/
99
static now: () => number;
100
101
/**
102
* Default timezone for DateTime creation
103
* Default: SystemZone.instance
104
*/
105
static defaultZone: Zone;
106
107
/**
108
* Default locale for formatting and parsing
109
* Default: system locale or "en-US"
110
*/
111
static defaultLocale: string;
112
113
/**
114
* Default numbering system for formatting
115
* Default: system default or "latn"
116
*/
117
static defaultNumberingSystem: string;
118
119
/**
120
* Default calendar system for formatting
121
* Default: system default or "gregory"
122
*/
123
static defaultOutputCalendar: string;
124
125
/**
126
* Whether to throw exceptions on invalid dates/times
127
* Default: false (returns invalid instances instead)
128
*/
129
static throwOnInvalid: boolean;
130
131
/**
132
* Reset internal caches (timezones, locales, etc.)
133
*/
134
static resetCaches(): void;
135
}
136
```
137
138
## Usage Examples
139
140
### Info Class Examples
141
142
```javascript
143
import { Info } from "luxon";
144
145
// Timezone information
146
console.log(Info.hasDST("America/New_York")); // true
147
console.log(Info.hasDST("America/Phoenix")); // false
148
console.log(Info.hasDST("UTC")); // false
149
console.log(Info.hasDST()); // DST status of system timezone
150
151
// Timezone validation
152
console.log(Info.isValidIANAZone("America/New_York")); // true
153
console.log(Info.isValidIANAZone("Invalid/Zone")); // false
154
console.log(Info.isValidIANAZone("Europe/London")); // true
155
156
// Zone normalization
157
const zone1 = Info.normalizeZone("America/New_York"); // IANAZone
158
const zone2 = Info.normalizeZone(-300); // FixedOffsetZone (UTC-5)
159
const zone3 = Info.normalizeZone("system"); // SystemZone
160
161
// Locale information - months
162
console.log(Info.months("long"));
163
// ["January", "February", "March", ...]
164
165
console.log(Info.months("short", { locale: "fr" }));
166
// ["janv.", "févr.", "mars", ...]
167
168
console.log(Info.months("narrow"));
169
// ["J", "F", "M", ...]
170
171
// Weekdays
172
console.log(Info.weekdays("long"));
173
// ["Monday", "Tuesday", "Wednesday", ...]
174
175
console.log(Info.weekdays("short", { locale: "es" }));
176
// ["lun", "mar", "mié", ...]
177
178
// Other locale info
179
console.log(Info.meridiems()); // ["AM", "PM"]
180
console.log(Info.meridiems({ locale: "de" })); // ["AM", "PM"] (or locale-specific)
181
182
console.log(Info.eras("long"));
183
// ["Before Christ", "Anno Domini"]
184
185
// Feature detection
186
const features = Info.features();
187
console.log(features);
188
/*
189
{
190
intl: true, // Intl API available
191
intlTokens: true, // Intl token parsing available
192
zones: true, // IANA timezone data available
193
relative: true // Relative time formatting available
194
}
195
*/
196
```
197
198
### Settings Class Examples
199
200
```javascript
201
import { Settings, DateTime, IANAZone, FixedOffsetZone } from "luxon";
202
203
// Configure default timezone
204
Settings.defaultZone = "America/New_York";
205
Settings.defaultZone = IANAZone.create("Europe/London");
206
Settings.defaultZone = FixedOffsetZone.instance(330); // UTC+5:30
207
208
// Now all DateTime.local() calls use the default zone
209
const dt1 = DateTime.local(); // Uses configured default zone
210
const dt2 = DateTime.now(); // Also uses configured default zone
211
212
// Configure default locale
213
Settings.defaultLocale = "fr-FR";
214
Settings.defaultNumberingSystem = "arab";
215
Settings.defaultOutputCalendar = "islamic";
216
217
// Now formatting uses these defaults
218
const formatted = DateTime.now().toLocaleString();
219
220
// Configure error handling
221
Settings.throwOnInvalid = true;
222
223
try {
224
const invalid = DateTime.fromISO("not-a-date"); // Throws error
225
} catch (e) {
226
console.error("Invalid date created");
227
}
228
229
Settings.throwOnInvalid = false; // Back to default behavior
230
const invalid = DateTime.fromISO("not-a-date"); // Returns invalid DateTime
231
console.log(invalid.isValid); // false
232
233
// Mock time for testing
234
const originalNow = Settings.now;
235
Settings.now = () => new Date("2023-01-01T12:00:00Z").getTime();
236
237
const mockedNow = DateTime.now();
238
console.log(mockedNow.toISO()); // "2023-01-01T12:00:00.000Z"
239
240
// Restore original
241
Settings.now = originalNow;
242
243
// Reset caches (useful after changing system timezone/locale)
244
Settings.resetCaches();
245
```
246
247
### Combining Info and Settings
248
249
```javascript
250
import { Info, Settings, DateTime } from "luxon";
251
252
// Set locale-aware defaults
253
if (Info.features().intl) {
254
// Use system locale if Intl is available
255
const systemLocale = Intl.DateTimeFormat().resolvedOptions().locale;
256
Settings.defaultLocale = systemLocale;
257
}
258
259
// Validate timezone before setting
260
const desiredZone = "America/New_York";
261
if (Info.isValidIANAZone(desiredZone)) {
262
Settings.defaultZone = desiredZone;
263
} else {
264
console.warn(`Invalid timezone: ${desiredZone}`);
265
}
266
267
// Get environment information
268
const features = Info.features();
269
if (!features.zones) {
270
console.warn("IANA timezone data not available");
271
}
272
if (!features.relative) {
273
console.warn("Relative time formatting not available");
274
}
275
276
// Build locale-aware UI
277
const months = Info.months("long", { locale: Settings.defaultLocale });
278
const weekdays = Info.weekdays("short", { locale: Settings.defaultLocale });
279
280
// Create locale selector
281
function buildDatePickerUI() {
282
return {
283
months: months,
284
weekdays: weekdays,
285
timeZone: Settings.defaultZone.name,
286
locale: Settings.defaultLocale
287
};
288
}
289
```
290
291
## Environment Feature Detection
292
293
The `Info.features()` method returns information about available capabilities:
294
295
- **`intl`**: Whether the Intl API is available (affects locale formatting)
296
- **`intlTokens`**: Whether Intl-based token parsing is available
297
- **`zones`**: Whether IANA timezone data is available
298
- **`relative`**: Whether relative time formatting is available
299
300
Use this for graceful degradation in environments with limited capabilities.
301
302
## Configuration Best Practices
303
304
1. **Set defaults early**: Configure Settings at application startup
305
2. **Validate timezones**: Use `Info.isValidIANAZone()` before setting default zones
306
3. **Feature detection**: Check `Info.features()` for environment capabilities
307
4. **Cache management**: Call `Settings.resetCaches()` after system changes
308
5. **Testing**: Use `Settings.now` to mock time in tests