npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

zod-timezone-validation

v1.0.5

Published

Zod schemas for validating timezone strings, including non-canonical names.

Readme

Zod Timezone Validation

npm version

A lightweight and robust Zod schema for validating IANA timezone strings, with flexible handling of canonical and non-canonical names.

This library leverages the native Intl API, ensuring that timezone validation is always up-to-date with the user's environment without needing to bundle large timezone databases.

Key Features

  • Three Validation Strategies:
    • Strictly canonical names only.
    • Allow non-canonical names.
    • Transform non-canonical names to their canonical equivalents (e.g., Asia/Calcutta -> Asia/Kolkata).
  • Zero Dependencies: Relies only on zod as a peer dependency.
  • Lightweight: No bundled timezone data, uses the environment's native Intl API.
  • Fully Typed: Written in TypeScript.

Brief Overview of Exports

  • CoercedCanonicalTimezoneSchema: Validates a timezone and transforms it to its canonical form (e.g., US/Eastern becomes America/New_York). Infers a branded type CanonicalTimezone.
  • CanonicalTimezoneSchema: Ensures a timezone is strictly in its canonical form. Rejects valid but non-canonical names. Infers a branded type CanonicalTimezone.
  • TimezoneSchema: Validates any valid timezone, allowing both canonical and non-canonical names without transformation. Infers a branded type Timezone.
  • CanonicalTimezone: The branded string type for a canonical timezone.
  • Timezone: The branded string type for any valid timezone.

Using branded types provides extra type safety, ensuring that you don't accidentally assign a plain string where a validated timezone is expected. You can use the exported types in your function signatures and interfaces.

❤️ Enjoying this package? Consider buying me a coffee as a token of appreciation!

Installation

npm install zod-timezone-validation

or

yarn add zod-timezone-validation

Note: zod is a peer dependency and must be installed in your project.

Usage

The library exports three pre-configured Zod schemas to cover the most common use cases.

CoercedCanonicalTimezoneSchema

This schema validates that a string is a valid IANA timezone. If a non-canonical name is provided, it automatically transforms it into its canonical equivalent.

import { CoercedCanonicalTimezoneSchema } from 'zod-timezone-validation';

// Transforms non-canonical to canonical
const result1 = CoercedCanonicalTimezoneSchema.parse('Asia/Calcutta');
console.log(result1); // => 'Asia/Kolkata'

// Keeps canonical names as they are
const result2 = CoercedCanonicalTimezoneSchema.parse('America/New_York');
console.log(result2); // => 'America/New_York'

// Throws an error for invalid timezones
try {
  CoercedCanonicalTimezoneSchema.parse('Invalid/Timezone');
} catch (e) {
  console.error(e); // ZodError
}

CanonicalTimezoneSchema

This schema ensures the provided string is a strictly canonical IANA timezone name. It will reject any valid but non-canonical names.

import { CanonicalTimezoneSchema } from 'zod-timezone-validation';

// Accepts canonical names
const result = CanonicalTimezoneSchema.parse('Europe/London');
console.log(result); // => 'Europe/London'

// Rejects non-canonical names
try {
  CanonicalTimezoneSchema.parse('GB'); // 'GB' is a non-canonical alias for 'Europe/London'
} catch (e) {
  console.error(e); // ZodError
}

TimezoneSchema

This schema is more lenient and validates that a string is a valid IANA timezone, allowing both canonical and non-canonical names without transformation (use CoercedCanonicalTimezoneSchema if you need to transform).

import { TimezoneSchema } from 'zod-timezone-validation';

// Accepts canonical names
const result1 = TimezoneSchema.parse('Australia/Sydney');
console.log(result1); // => 'Australia/Sydney'

// Also accepts non-canonical names
const result2 = TimezoneSchema.parse('US/Eastern');
console.log(result2); // => 'US/Eastern'

// Throws an error for invalid timezones
try {
  TimezoneSchema.parse('Mars/Olympus_Mons');
} catch (e) {
  console.error(e); // ZodError
}

Getting a List of Timezones

While this library focuses on validating timezone strings, it doesn't provide an exhaustive list of them. The environment already provides a way to get a list of all supported IANA timezone names through the native Intl API.

You can get an array of all available timezones like this:

const availableTimezones = Intl.supportedValuesOf('timeZone');

console.log(availableTimezones);
// => ['Africa/Abidjan', 'Africa/Accra', 'Africa/Addis_Ababa', ..., 'Zulu']

This approach ensures that you are working with the timezones supported by the user's runtime environment (browser or server), without needing to bundle a large, static list.

License

This project is licensed under the MIT License.