@bigbinary/neeto-time-zones

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

npm version license

中文使用文档
文档目录14 节
  1. 安装
  2. 将 CSS 样式导入到主样式表
  3. 新时区选择器
  4. 用法 1
  5. 使用量 2
  6. 配置
  7. ianaTimezone 到人可读
  8. 转写支持
  9. 获取时区对象
  10. 是时区
  11. 获取浏览时区
  12. 发展
  13. 清除还原
  14. 出版指令

@ bigbinary/ 需要时区

npm version license

与时区合作的简单而轻量级的国家预防机制一揽子计划。 这个软件包为时区提供了人类友好的时区选择器和实用功能.

安装

您可以使用纱线安装软件包 :

yarn add @bigbinary/neeto-time-zones

将 CSS 样式导入到主样式表

您应该添加以下内容 main.scss 文件 :

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

新时区选择器

看看现场演示

用法 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}
    />
  );
};

使用量 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);
      }}
    />
  );
}

配置

您可以通过选项作为第二个参数来配置时区选择器组件.

  1. 元素ID: NeetoTimezoneSelector 的标识。 默认 ID 是 timezone-selector
  2. 类Name:可添加到组件中的自定义类.
  3. 初始值:时区选择器的初始值.
  4. 位置:选择者应打开的位置。 可用选项 : top, (中文(简体) ), bottom默认位置为 bottom。 。 。 .
  5. : 当时区选择器改变时调用函数.
  6. 上 HourFormatChange: 当时间格式改变时调用函数.
  7. 是TimeFormatSwitchBible:将此设置为假将隐藏时间格式来切换 。 默认值为真 .
  8. 是TimeFormat24H:当禁用内部时间格式切换时,请使用此道具来通过时间格式选项。 这将用于更改时区选择器内的时间格式 .

ianaTimezone 到人可读

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

转写支持

时区标签可以在用户的浏览器语言脚本(如印地语,阿拉伯语,日语)中显示. 这是 转写 ——英语时区名称在目标脚本中拼写而来,不是被翻译.

拾取器部件自动通过 navigator.language 并装入相应的转写文件。 拾取器不需要配置 .

对于消费的应用软件 ianaTimezoneToHumanReadable 直接( 不渲染拾取器), 调用 initTranslations() 一旦在应用程序启动时预装转写数据 :

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)

支助的当地人(35人)

活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活活

中国地产变体自动处理:

  • zh-Hans-CN, (中文(简体) ), zh-Hans, (中文(简体) ), zh-SG, (中文(简体) ), zh - 简化中文(zh-CN(中文(简体) )
  • zh-Hant-TW, (中文(简体) ), zh-Hant, (中文(简体) ), zh-HK, (中文(简体) ), zh-MO ——传统汉语zh-TW(中文(简体) )

添加新区域

  1. 创建 data/translations/<locale>.json 带有所需结构(见现有文件供参考)
  2. 复制文件到 ruby/data/translations/<locale>.json
  3. 添加一个 case "<locale>": return () => import("../../data/translations/<locale>.json"); 输入 js/translations/index.js
  4. 重建软件包

获取时区对象

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

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

是时区

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

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

获取浏览时区

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

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

发展

清除还原

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

要与主机应用程序捆绑 :

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

出版指令

将标记为补丁、次要或主干件的PR合并到主分支后,将发布一个软件包。 补丁标签地址为错误修正, 小符号表示新特性的添加, 并主要表示断开更改, 坚持其中概述的原则 语义版 (SemVer)。 。 。 .

您可以在 GitHub 动作中检查并发布发布工作流程, 以获取实时更新 .

版本与发布记录

@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 和提交记录判断。