Variable TimeZoneUtilsConst

TimeZoneUtils: {
    getTimeZoneDetails(timeZone): TimeZone;
    getTimeZones(filters?, showUsersFirst?): TimeZone[];
    getTimeZonesOptions(...filters): string[];
    getUsersTimeZone(): TimeZone;
    getUsersTimeZoneName(): string;
    isValidTimeZone(timeZone): boolean;
} = ...

Type declaration

  • getTimeZoneDetails:function
    • Gets details for a specific time zone

      Parameters

      • timeZone: string

        The IANA time zone name

      Returns TimeZone

      Object containing time zone name and short name

      Throws

      Error if the time zone is invalid

      Example

      const details = TimeZoneUtils.getTimeZoneDetails('America/New_York');
      console.log(details);
      // Output: { name: 'America/New_York', shortName: 'EDT' }
  • getTimeZones:function
    • Gets a list of time zones, optionally filtered and with user's time zone first

      Parameters

      • Optional filters: string[]

        Optional array of time zone names to filter by

      • showUsersFirst: boolean = true

        Whether to show user's time zone first in the list

      Returns TimeZone[]

      Array of time zone objects

      Example

      // Get all time zones with user's time zone first
      const allTimeZones = TimeZoneUtils.getTimeZones();

      // Get filtered time zones without user's time zone first
      const filteredTimeZones = TimeZoneUtils.getTimeZones(
      ['America/New_York', 'Europe/London'],
      false
      );
  • getTimeZonesOptions:function
    • Gets HTML option elements for time zones

      Parameters

      • Rest ...filters: string[]

        Optional array of time zone names to filter by

      Returns string[]

      Array of HTML option strings

      Example

      // Get options for specific time zones
      const options = TimeZoneUtils.getTimeZonesOptions(
      'America/New_York',
      'Europe/London'
      );

      // Use in select element
      const select = document.createElement('select');
      select.innerHTML = options.join('');
  • getUsersTimeZone:function
    • Gets the user's time zone

      Returns TimeZone

      Time zone object for user's time zone

      Example

      const userTimeZone = TimeZoneUtils.getUsersTimeZone();
      console.log(`User's time zone: ${userTimeZone.name} (${userTimeZone.shortName})`);
  • getUsersTimeZoneName:function
    • Gets the user's time zone name

      Returns string

      User's IANA time zone name

      Example

      const timeZoneName = TimeZoneUtils.getUsersTimeZoneName();
      console.log(`User's time zone name: ${timeZoneName}`);
  • isValidTimeZone:function
    • Checks if a time zone name is valid

      Parameters

      • timeZone: string

        The IANA time zone name to check

      Returns boolean

      True if the time zone is valid

      Example

      const isValid = TimeZoneUtils.isValidTimeZone('America/New_York');
      console.log(`Is valid time zone: ${isValid}`);