CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-luxon

Immutable date wrapper library for JavaScript with comprehensive date/time manipulation, timezone support, and internationalization capabilities.

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

info-settings.mddocs/

Info & Settings API

The Info and Settings classes provide utilities for locale information, timezone validation, and global configuration of Luxon's behavior.

Capabilities

Info Class

Static utility class for accessing locale and timezone information.

/**
 * Static utility class for locale and timezone information
 */
class Info {
  /**
   * Check if timezone has daylight saving time
   * @param zone - Timezone name or Zone instance (defaults to system timezone)
   */
  static hasDST(zone?: string | Zone): boolean;
  
  /**
   * Check if timezone name is valid in IANA database
   * @param zone - IANA timezone name to validate
   */
  static isValidIANAZone(zone: string): boolean;
  
  /**
   * Convert various inputs to Zone instance
   * @param input - Zone name, offset number, or Zone instance
   */
  static normalizeZone(input: string | number | Zone): Zone;
  
  /**
   * Get array of month names in specified locale
   * @param length - Name length ('long', 'short', 'narrow')
   * @param opts - Options including locale, numberingSystem, outputCalendar
   */
  static months(length?: string, opts?: object): string[];
  
  /**
   * Get array of month names for formatting (standalone vs format context)
   * @param length - Name length ('long', 'short', 'narrow')
   * @param opts - Options including locale, numberingSystem, outputCalendar
   */
  static monthsFormat(length?: string, opts?: object): string[];
  
  /**
   * Get array of weekday names in specified locale
   * @param length - Name length ('long', 'short', 'narrow')
   * @param opts - Options including locale, numberingSystem, outputCalendar
   */
  static weekdays(length?: string, opts?: object): string[];
  
  /**
   * Get array of weekday names for formatting
   * @param length - Name length ('long', 'short', 'narrow')  
   * @param opts - Options including locale, numberingSystem, outputCalendar
   */
  static weekdaysFormat(length?: string, opts?: object): string[];
  
  /**
   * Get array of meridiem names (AM/PM) in specified locale
   * @param opts - Options including locale
   */
  static meridiems(opts?: object): string[];
  
  /**
   * Get array of era names in specified locale
   * @param length - Name length ('long', 'short', 'narrow')
   * @param opts - Options including locale, numberingSystem, outputCalendar
   */
  static eras(length?: string, opts?: object): string[];
  
  /**
   * Get information about available features in current environment
   */
  static features(): {
    intl: boolean;
    intlTokens: boolean;
    zones: boolean;
    relative: boolean;
  };
}

Settings Class

Static class for global Luxon configuration.

/**
 * Global configuration class for Luxon behavior
 */
class Settings {
  /**
   * Function that returns current timestamp (for testing/mocking)
   * Default: () => Date.now()
   */
  static now: () => number;
  
  /**
   * Default timezone for DateTime creation
   * Default: SystemZone.instance
   */
  static defaultZone: Zone;
  
  /**
   * Default locale for formatting and parsing
   * Default: system locale or "en-US"
   */
  static defaultLocale: string;
  
  /**
   * Default numbering system for formatting
   * Default: system default or "latn"
   */
  static defaultNumberingSystem: string;
  
  /**
   * Default calendar system for formatting
   * Default: system default or "gregory"
   */
  static defaultOutputCalendar: string;
  
  /**
   * Whether to throw exceptions on invalid dates/times
   * Default: false (returns invalid instances instead)
   */
  static throwOnInvalid: boolean;
  
  /**
   * Reset internal caches (timezones, locales, etc.)
   */
  static resetCaches(): void;
}

Usage Examples

Info Class Examples

import { Info } from "luxon";

// Timezone information
console.log(Info.hasDST("America/New_York"));    // true
console.log(Info.hasDST("America/Phoenix"));     // false  
console.log(Info.hasDST("UTC"));                 // false
console.log(Info.hasDST());                      // DST status of system timezone

// Timezone validation
console.log(Info.isValidIANAZone("America/New_York"));  // true
console.log(Info.isValidIANAZone("Invalid/Zone"));      // false
console.log(Info.isValidIANAZone("Europe/London"));     // true

// Zone normalization
const zone1 = Info.normalizeZone("America/New_York");   // IANAZone
const zone2 = Info.normalizeZone(-300);                 // FixedOffsetZone (UTC-5)
const zone3 = Info.normalizeZone("system");             // SystemZone

// Locale information - months
console.log(Info.months("long"));
// ["January", "February", "March", ...]

console.log(Info.months("short", { locale: "fr" }));
// ["janv.", "févr.", "mars", ...]

console.log(Info.months("narrow"));
// ["J", "F", "M", ...]

// Weekdays  
console.log(Info.weekdays("long"));
// ["Monday", "Tuesday", "Wednesday", ...]

console.log(Info.weekdays("short", { locale: "es" }));
// ["lun", "mar", "mié", ...]

// Other locale info
console.log(Info.meridiems());                // ["AM", "PM"]
console.log(Info.meridiems({ locale: "de" })); // ["AM", "PM"] (or locale-specific)

console.log(Info.eras("long"));
// ["Before Christ", "Anno Domini"]

// Feature detection
const features = Info.features();
console.log(features);
/*
{
  intl: true,         // Intl API available
  intlTokens: true,   // Intl token parsing available  
  zones: true,        // IANA timezone data available
  relative: true      // Relative time formatting available
}
*/

Settings Class Examples

import { Settings, DateTime, IANAZone, FixedOffsetZone } from "luxon";

// Configure default timezone
Settings.defaultZone = "America/New_York";
Settings.defaultZone = IANAZone.create("Europe/London");
Settings.defaultZone = FixedOffsetZone.instance(330); // UTC+5:30

// Now all DateTime.local() calls use the default zone
const dt1 = DateTime.local(); // Uses configured default zone
const dt2 = DateTime.now();   // Also uses configured default zone

// Configure default locale
Settings.defaultLocale = "fr-FR";
Settings.defaultNumberingSystem = "arab";
Settings.defaultOutputCalendar = "islamic";

// Now formatting uses these defaults
const formatted = DateTime.now().toLocaleString();

// Configure error handling
Settings.throwOnInvalid = true;

try {
  const invalid = DateTime.fromISO("not-a-date"); // Throws error
} catch (e) {
  console.error("Invalid date created");
}

Settings.throwOnInvalid = false; // Back to default behavior
const invalid = DateTime.fromISO("not-a-date"); // Returns invalid DateTime
console.log(invalid.isValid); // false

// Mock time for testing
const originalNow = Settings.now;
Settings.now = () => new Date("2023-01-01T12:00:00Z").getTime();

const mockedNow = DateTime.now();
console.log(mockedNow.toISO()); // "2023-01-01T12:00:00.000Z"

// Restore original
Settings.now = originalNow;

// Reset caches (useful after changing system timezone/locale)
Settings.resetCaches();

Combining Info and Settings

import { Info, Settings, DateTime } from "luxon";

// Set locale-aware defaults
if (Info.features().intl) {
  // Use system locale if Intl is available
  const systemLocale = Intl.DateTimeFormat().resolvedOptions().locale;
  Settings.defaultLocale = systemLocale;
}

// Validate timezone before setting
const desiredZone = "America/New_York";
if (Info.isValidIANAZone(desiredZone)) {
  Settings.defaultZone = desiredZone;
} else {
  console.warn(`Invalid timezone: ${desiredZone}`);
}

// Get environment information
const features = Info.features();
if (!features.zones) {
  console.warn("IANA timezone data not available");
}
if (!features.relative) {
  console.warn("Relative time formatting not available");
}

// Build locale-aware UI
const months = Info.months("long", { locale: Settings.defaultLocale });
const weekdays = Info.weekdays("short", { locale: Settings.defaultLocale });

// Create locale selector
function buildDatePickerUI() {
  return {
    months: months,
    weekdays: weekdays,  
    timeZone: Settings.defaultZone.name,
    locale: Settings.defaultLocale
  };
}

Environment Feature Detection

The Info.features() method returns information about available capabilities:

  • intl: Whether the Intl API is available (affects locale formatting)
  • intlTokens: Whether Intl-based token parsing is available
  • zones: Whether IANA timezone data is available
  • relative: Whether relative time formatting is available

Use this for graceful degradation in environments with limited capabilities.

Configuration Best Practices

  1. Set defaults early: Configure Settings at application startup
  2. Validate timezones: Use Info.isValidIANAZone() before setting default zones
  3. Feature detection: Check Info.features() for environment capabilities
  4. Cache management: Call Settings.resetCaches() after system changes
  5. Testing: Use Settings.now to mock time in tests

docs

datetime.md

duration.md

index.md

info-settings.md

interval.md

zones.md

tile.json