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

@dtyq/timezone

v0.0.2

Published

Timezone utilities and consistent timezone list for web projects.

Readme

@dtyq/timezone

Consistent timezone data and utilities for web applications.

This package helps you:

  • Render a standardized timezone list in UI
  • Convert and format time across different timezones
  • Build common date range values (day/month)
  • Handle multilingual timezone labels
  • Reuse business-ready helper methods

Installation

pnpm add @dtyq/timezone dayjs
# or
npm i @dtyq/timezone dayjs

dayjs is a peer dependency and should be installed by your application.

Runtime Support

  • Modern browsers
  • Node.js >=16
  • SSR environments (for example Next.js/Nuxt)

The package ships TypeScript types and can be used in TypeScript or JavaScript projects.

Quick Start

import {
  getTimezones,
  convertTime,
  getDayRange,
  buildTimezoneSelectOptions,
} from "@dtyq/timezone"

const timezoneOptions = buildTimezoneSelectOptions({
  locale: "en_US",
  preferred: ["Asia/Shanghai", "Europe/London", "America/New_York"],
})

const text = convertTime("2026-03-08 09:00:00", {
  from: "Asia/Shanghai",
  to: "America/New_York",
  format: "YYYY-MM-DD HH:mm:ss",
})

const [start, end] = getDayRange({
  timezone: "Asia/Shanghai",
  format: "YYYY-MM-DD HH:mm:ss",
})

API Overview

Timezone Catalog

  • getTimezones(options?)
  • getTimezone(code, locale?)

Use these for dropdowns, search, and timezone detail display.

Time Conversion

  • now(options?)
  • convertTime(input, options)
  • toTimestamp(input, options?)
  • formatInTimezone(input, options)

Use these to convert and format values between source and target timezones.

Time Ranges

  • getDayRange(options)
  • getMonthRange(options)

Use these for query ranges, reports, and filtering windows.

Business Utilities

  • isCrossDay(input)
  • buildTimezoneSelectOptions(options?)
  • normalizeMeetingTime(input)

Use these for common product-level scenarios.

Core Data Structures

type Locale = "zh_CN" | "en_US" | string
type TimezoneCode = string // IANA, e.g. "Asia/Shanghai"
type TimeInput = string | number | Date

interface TimezoneItem {
  code: TimezoneCode
  offset: string          // e.g. "+08:00"
  offsetMinutes: number   // e.g. 480
  label: string           // localized display text
  city?: string
  countryCode?: string
  group?: string
}

Internationalization

Built-in locales:

  • en_US
  • zh_CN

You can register custom locale messages:

import { registerLocale, setDefaultLocale } from "@dtyq/timezone"

registerLocale("fr_FR", {
  "Asia/Shanghai": "(GMT+08:00) Shanghai",
})

setDefaultLocale("fr_FR")

Fallback order:

  1. target locale
  2. en_US
  3. timezone code

Dayjs Integration

If your app initializes dayjs plugins in a shared bootstrap file, inject the same instance:

import dayjs from "dayjs"
import utc from "dayjs/plugin/utc"
import timezonePlugin from "dayjs/plugin/timezone"
import { configureDayjs } from "@dtyq/timezone"

dayjs.extend(utc)
dayjs.extend(timezonePlugin)

configureDayjs(dayjs)

This guarantees app code and package code use the same dayjs instance.

Error Handling

The package throws TimezoneError with stable codes:

  • INVALID_TIME_INPUT
  • INVALID_TIMEZONE
  • INVALID_FORMAT
  • LOCALE_NOT_FOUND
  • UNSUPPORTED_OPERATION

Example:

import { convertTime } from "@dtyq/timezone"

try {
  convertTime("invalid-time", { to: "Asia/Shanghai" })
} catch (error) {
  // handle error in your app
}

Best Practices

  • Persist only IANA timezone code in backend/database
  • Use UTC timestamp for transport between client and server
  • Convert to display timezone only in UI/application layer
  • Always provide timezone in cross-day comparisons

Contributing

See CONTRIBUTING.md.

License

MIT. See LICENSE.