@bigbinary/neeto-time-zones

中文文档
0.8.27发布于 2026/11/04MITTypeScriptESM + CJS近 30 天下载 3.6万

npm version license

原始使用文档
文档目录14 节
  1. Installation
  2. Importing CSS styles to the main stylesheet
  3. NeetoTimezoneSelector
  4. Usage 1
  5. Usage 2
  6. Configuration
  7. ianaTimezoneToHumanReadable
  8. Transliteration support
  9. getTimezoneObject
  10. isValidTimezone
  11. getBrowserTimezone
  12. Development
  13. Clone the repo
  14. Instructions for Publishing

@bigbinary/neeto-time-zones

npm version license

A simple and lightweight NPM package for working with time zones. This package provides a human friendly timezone selector and utility functions for timezones.

Installation

You can install the package using yarn:

yarn add @bigbinary/neeto-time-zones

Importing CSS styles to the main stylesheet

You should add the following to main.scss file:

@import "@bigbinary/neeto-time-zones/dist/style.css";

NeetoTimezoneSelector

Check out the live demo

Usage 1

import { NeetoTimezoneSelector } from "@bigbinary/neeto-time-zones";

const ReactComponent = () => {
  const timezoneRef = useCallback(node => {
    if (!(node !== null)) return;

    new NeetoTimezoneSelector(node, {
      elementId: "custom-selector-element",
      className: "custom-selector-class",
      initialValue: "initial-timezone",
      position: "top",
      onChange: (timezone) => {
        console.log(timezone);
      },
      onHourFormatChange: (timeFormat) => {
        console.log(timeFormat);
      }
    });
  }, []);

  return (
    <div
      ref={timezoneRef}
    />
  );
};

Usage 2

import NeetoTimezoneSelector from "@bigbinary/neeto-time-zones/react";

const ReactComponent = () => {
  return (
    <NeetoTimezoneSelector
      elementId="custom-selector-element"
      className="custom-selector-class"
      initialValue="initial-timezone"
      position="top"
      onChange={(timezone) => {
        console.log(timezone);
      }}
      onHourFormatChange={(timeFormat) => {
        console.log(timeFormat);
      }}
    />
  );
}

Configuration

You can pass options as the second parameter to configure the timezone selector component.

  1. elementId: ID for the NeetoTimezoneSelector. By default the ID will be timezone-selector
  2. className: Custom classes that can be added to the component.
  3. initialValue: Initial Value of the timezone selector.
  4. position: Position in which the selector should open in. Available options: top, bottom. Default position is bottom.
  5. onChange: Function to be called when the timezone selector changes.
  6. onHourFormatChange: Function to be called when the time format changes.
  7. isTimeFormatSwitchVisible: Setting this to false will hide the time format toggle. The default value is true.
  8. isTimeFormat24H: When the internal time format toggle is disabled, use this prop to pass the time format option. This will be used to change the time format inside the timezone selector.

ianaTimezoneToHumanReadable

import { ianaTimezoneToHumanReadable } from "@bigbinary/neeto-time-zones";

ianaTimezoneToHumanReadable("Asia/Calcutta") // => Indian Standard Time

ianaTimezoneToHumanReadable("America/New_York") // => Eastern Standard Time

ianaTimezoneToHumanReadable("Europe/Berlin") // => Central Standard Time

Transliteration support

Timezone labels can be displayed in the user's browser language script (e.g., Hindi, Arabic, Japanese). This is transliteration — the English timezone names are written phonetically in the target script, not translated.

The picker widget automatically detects the browser locale via navigator.language and loads the appropriate transliteration file. No configuration is needed for the picker.

For consuming apps that use ianaTimezoneToHumanReadable directly (without rendering the picker), call initTranslations() once at app startup to pre-load the transliteration data:

import { initTranslations } from "@bigbinary/neeto-time-zones";

// Call once at app startup (e.g., in your entry point)
initTranslations();

// After initTranslations resolves, ianaTimezoneToHumanReadable
// returns transliterated labels based on the browser locale.
ianaTimezoneToHumanReadable("Asia/Calcutta")
// => "इंडियन स्टैंडर्ड टाइम" (when browser locale is "hi")
// => "Indian Standard Time" (when browser locale is "en" or unsupported)

Supported locales (35)

ar, bg, ca, cs, da, de, es, es-MX, et, fi, fil, fr, he, hi, hr, hu, id, it, ja, ko, nl, pl, pt, pt-BR, ro, ru, sk, sl, sv, th, tr, uk, vi, zh-CN, zh-TW

Chinese locale variants are handled automatically:

  • zh-Hans-CN, zh-Hans, zh-SG, zh → Simplified Chinese (zh-CN)
  • zh-Hant-TW, zh-Hant, zh-HK, zh-MO → Traditional Chinese (zh-TW)

Adding a new locale

  1. Create data/translations/<locale>.json with the required structure (see existing files for reference)
  2. Copy the file to ruby/data/translations/<locale>.json
  3. Add a case "<locale>": return () => import("../../data/translations/<locale>.json"); entry in js/translations/index.js
  4. Rebuild the package

getTimezoneObject

import { getTimezoneObject } from "@bigbinary/neeto-time-zones";

getTimezoneObject("Asia/Kolkata")
// => { utc: ["Asia/Kolkata", "Asia/Calcutta"], main: "Asia/Kolkata", label: "Indian Standard Time", ... }

isValidTimezone

import { isValidTimezone } from "@bigbinary/neeto-time-zones";

isValidTimezone("Asia/Kolkata") // => true
isValidTimezone("Invalid/Zone") // => false

getBrowserTimezone

import { getBrowserTimezone } from "@bigbinary/neeto-time-zones";

getBrowserTimezone() // => "Asia/Kolkata" (based on browser's Intl API)

Development

Clone the repo

git clone [email protected]:bigbinary/neeto-time-zones.git
cd neeto-time-zones/js
yarn install
yarn dev

To bundle with host app:

yarn build && cp dist/* ../../neeto-cal-web/node_modules/@bigbinary/neeto-time-zones/dist

Instructions for Publishing

A package is released upon merging a PR labeled as patch, minor, or major into the main branch. The patch label addresses bug fixes, minor signifies the addition of new features, and major denotes breaking changes, adhering to the principles outlined in Semantic Versioning (SemVer).

You can checkout the Create and publish releases workflow in GitHub Actions to get a live update.

版本与发布记录

@bigbinary/neeto-time-zones 共发布 52 个版本,首次发布于 2023/10/12;过去 12 个月发布了 14 个版本。

版本发布日期距今
0.8.27latest2026/11/044 天前
0.8.262026/06/284 个月前
0.8.252026/05/016 个月前
0.8.242026/04/216 个月前
0.8.232026/04/176 个月前
0.8.222026/04/136 个月前

关于 @bigbinary/neeto-time-zones 的常见问题

如何安装 @bigbinary/neeto-time-zones?

在项目目录运行 npm install @bigbinary/neeto-time-zones,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:ramda(^0.29.1)、react(^18 || ^17.0.1 || ^16)、react-dom(^18 || ^17.0.1 || ^16)、@bigbinary/neeto-cist(^1.0.4)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@bigbinary/neeto-time-zones 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@bigbinary/neeto-time-zones 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@bigbinary/neeto-time-zones 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18.12。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@bigbinary/neeto-time-zones 可以商用吗?

@bigbinary/neeto-time-zones 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@bigbinary/neeto-time-zones 的下载量有多少?

根据 npm 官方下载统计,@bigbinary/neeto-time-zones 在 2026/10/08 – 2026/11/06 这 30 天内被下载 36,135 次,日均约 1,205 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bigbinary/neeto-time-zones 还在维护吗?

最新版本 0.8.27 发布于 2026/11/04(4 天前);至今共发布 52 个版本,其中过去 12 个月发布了 14 个;首次发布于 2023/10/12。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。