@checkdigit/time

中文文档
6.0.0发布于 2026/09/03MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 9163

Standard time handling

原始使用文档
文档目录5 节
  1. formatUtc
  2. Installing and usage
  3. Documentation
  4. Migration guide
  5. Critical maintenance notes (VERY IMPORTANT!!!):

Check Digit Time Library

Copyright © 2022-2026 Check Digit, LLC

The Check Digit time library is the officially sanctioned method for Check Digit services to deal with time. It has date manipulation functions provided by date-fns. Features:

  • Stripped down date-fns functions
  • date-fns-tz for timezone support
  • formatUtc for formatting UTC dates

The date-fns library is included. The only locale currently supported is en-US, but otherwise contains all available functionality as of v4.1.0 except that the code in fp folder are excluded, which contain functional programming related stuff that is not used at the moment.

Additionally, the date-fns-tz library is included. Contains all available functionality as of v3.2.0 except that the code in fp folder are excluded, which contain functional programming related stuff that is not used at the moment.

formatUtc

The formatUtc function is a wrapper around date-fns-tz's format function, but with the following differences:

  • There is no options argument, timeZone is always UTC.

Generally speaking, formatUtc should be used in place of format or tzFormat, unless non-UTC time zones are required.

Installing and usage

npm install @checkdigit/time then:

For date-fns functionality:

import { formatUtc } from '@checkdigit/time';

console.log(formatUtc(new Date(), 'yyyy-MM-dd'));

Documentation

The documentation for date-fns is here: https://date-fns.org/

The documentation for date-fns-tz is here: https://github.com/marnusw/date-fns-tz

Migration guide

following are the main steps to sync up with the latest date-fns/date-fns-tz

  • clone 3rd party repo
  • remove test/fp stuff
  • copy/override into @checkdigit/time repo's corresponding folder
  • update CHANGELOG.md (it helps to understand the changes since the last update and to prepare accordingly)
  • replace imports from '.js' to '.ts'
  • Add comments in the beginning of the files to silence ts/lint errors if it forces overwhelming changes otherwise
  • check things which compiles but may have other issues, e.g. import { type ZZZ } => import type { ZZZ }
  • adjust tsconfig.json compilerOptions if necessary
  • apply previous patch (e.g. daylight saving timezone, etc.)
  • pass existing local tests
  • beta-test across dependent repos to make sure it still works

Critical maintenance notes (VERY IMPORTANT!!!):

When updating the latest code from the original repositories, except making all the necessary changes to make them fully typescript compatible, please remember to carry over the patches to overcome the following issues:

  • hours is incorrect when it's close to daylight saving timezone threshold

Please search for [PATCH:] in the existing codebase.

版本与发布记录

@checkdigit/time 共发布 35 个版本,首次发布于 2022/10/13;过去 12 个月发布了 3 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
6.0.0latest2026/09/032 个月前
6.0.0-PR.23-a0ffbeta2026/09/022 个月前
6.0.0-PR.23-fe1e2026/08/292 个月前
5.0.02025/07/011.4 年前
5.0.0-PR.21-e2de2025/07/011.4 年前
5.0.0-PR.21-a3782025/07/011.4 年前

关于 @checkdigit/time 的常见问题

@checkdigit/time 是什么?

Standard time handling

如何安装 @checkdigit/time?

在项目目录运行 npm install @checkdigit/time,或使用 pnpm add / yarn add / bun add。

@checkdigit/time 支持 TypeScript 吗?

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

@checkdigit/time 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@checkdigit/time 需要什么版本的 Node.js?

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

@checkdigit/time 可以商用吗?

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

@checkdigit/time 的下载量有多少?

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

@checkdigit/time 还在维护吗?

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