Skip to main content

dsh-tool-time/packages/dsh-tool-time

24Stars1Forks1Issues0Watchers

Offers time-related utilities including formatting, parsing, and duration calculations.

Evidence5/5methodologySourceInstallMaintenanceDSH versionSecurity scan
Machine-auditedInstall commandRepo verifieddsh-plugin topicLicenseREADMEAI wiki

ⓘ This plugin is a sub-package of the omdsh-dev/dsh-toolkit monorepo — stars and activity count the whole repository.

Language
TypeScript
License
MIT
Branch
main
collectiondshdsh-plugintoolkitzero-dependency

Install

cmdweb profile
$ dsh plugin --profile web add github:omdsh-dev/dsh-toolkit#path:packages/dsh-tool-time

Run the command above in your terminal to install this plugin via the dsh CLI. You can switch Profile in the top-right corner. New to dsh? Read the beginner tutorial

Install via your agent

Install the DeepSeek Harness plugin omdsh-dev/dsh-toolkit/packages/dsh-tool-time for me: review the repository at https://github.com/omdsh-dev/dsh-toolkit first, then run the install command and verify the plugin loads successfully.

Paste this instruction to the DSH Web GUI assistant — it will install and verify for you.

一句话定位

dsh-tool-time 是 dsh-toolkit 工具集中的时间子包,让 DSH Agent 用一次本地函数调用完成"现在几点""UTC 转北京时间""3 天后是哪天"等时间问题;不弹 bash 进程、不让模型心算闰年和 DST。

核心能力

  • 查询当前时间:默认返回 UTC 毫秒时间戳和结构化字段,可指定 IANA 时区显示墙钟
  • 时区转换:把任意严格 ISO 8601 时间戳投到指定 IANA 时区,返回 ISO、unix 毫秒、当地墙钟和带偏移的字符串
  • 日历加减:按 UTC 对时间戳做 seconds/minutes/hours/days/weeks/months/years 加减,月末日期自动钳制(如 1 月 31 日加 1 个月 = 2 月 28 日)
  • 时长差计算:算两个时间戳之间的固定毫秒差,输出带符号总量和各单位的带符号分量,加非负余数分解
  • 严格输入校验:拒绝非 ISO 8601 形式(包括 RFC 2822、自然语言日期、不带时区的日期时间)和日历溢出(如 2026-02-30)
  • 时区名校验:交给 Intl.DateTimeFormat 验证,非法时区抛 time: unknown timezone 并被前端清晰提示

技术实现

  • 语言: TypeScript (ESM)
  • 关键依赖: @deepseek-ai/cordis ^4.0.1(插件容器)、@deepseek-ai/dsh-tools ^0.0.1-rc.1(工具注册 API)、@deepseek-ai/dsh-invariants ^0.0.1-rc.1(包标识伴生)
  • 架构模式: 通过 cordis.patch.yml 用 - insert: 把 tool-time 插入 profile 的 layer stack;apply 阶段调用 ctx.tools.register(defineTool(...)) 注册名为 time 的单一工具,内部按 action 字段分发到 4 个独立函数
  • 入口文件: packages/dsh-tool-time/src/index.ts(Cordis 插件 apply)、packages/dsh-tool-time/src/time.ts(action 分发与纯函数实现)、packages/dsh-tool-time/cordis.patch.yml(profile 注入声明)

适用场景

Agent 接到"现在几点""把 2026-01-01 转成北京时间""3 天后是几号""这两次事件间隔多久"这类高频时间问题时,过去要么弹 bash 进程调 date(macOS 和 GNU 语法不一致、还要手工拼 TZ),要么让模型心算闰年和 DST 偏移,都容易出错。dsh-tool-time 用纯函数替代上述路径,统一输出毫秒精度 ISO + unix + 当地墙钟 + 格式化串四个字段,模型只需读字段无需做心算。

前置依赖与兼容性

依赖最低版本说明
DeepSeek Harness0.1.0-rc.6+(README 标注已在 0.1.0-rc.8 验证)通过 cordis.patch.yml 注入 profile 的 layer stack;本插件不附带 dsh 本体
Node.js^22.19.0 || >=24.0.0插件运行时;同时依赖 Node 内置 ICU 提供 IANA 时区数据
平台跨平台时区数据来自 Node ICU,跨平台一致性等价于"同 Node/ICU 版本下输出一致"
原生模块无纯 Node 内置 Date + Intl.DateTimeFormat,无 better-sqlite3 / node-pty 等原生依赖

安装方式

dsh plugin --profile web add github:omdsh-dev/dsh-toolkit/packages/dsh-tool-time

配置项

本插件对终端用户没有运行时配置(无 dsh profile config、无环境变量),所有行为由工具调用时的参数决定:

参数类型说明默认值
action枚举必填,4 选 1:now(当前时间)/ convert(时区转换)/ add(日期加减)/ diff(时长差)无(必填)
value字符串convert/add 用的严格 ISO 8601 时间戳(YYYY-MM-DD 或带 T 时分秒,可选毫秒/时区偏移)无(按 action 必填或可选)
timezone字符串IANA 时区名(如 Asia/Shanghai),convert 必填,now/add 可选;add 中只影响展示不影响加减UTC
from / to字符串diff 用的起止严格 ISO 8601 时间戳无(diff 必填)
amount整数add 用加减量,必须是安全整数,可负数无(add 必填)
unit枚举add 用单位:seconds / minutes / hours / days / weeks / months / years无(add 必填)

常见问题

Q: 这个插件会起 bash 进程跑 date 命令吗?

A: 不会。全部逻辑由 Node 内置 Date 与 Intl.DateTimeFormat 实现,纯函数、零进程,性能稳定且不依赖 GNU/BSD date 的差异。

Q: 时区转换和"加一天"是按哪个时区算的?

A: 转换(convert)按 IANA 时区展示墙钟;日历加减(add)始终按 UTC 运算,timezone 字段只影响结果里的 local/formatted 显示字段,不会影响实际加减后的 instant。

Q: 支持自然语言日期如"next week"或"下周三"吗?

A: 不支持。只能接受严格 ISO 8601 子集(YYYY-MM-DD 或带时分秒/偏移),RFC 2822 和自然语言一律拒绝,避免歧义和模型心算误差。

Q: 年份范围有限制吗?

A: 输入和计算结果年份都必须在 1000 到 9999 之间;1000 之前 JavaScript Date 有 1900+ 映射的历史坑,超过 9999 则偏移计算与 Intl era 会失真。

Q: diff 能输出"几个月""几年"吗?

A: 不能。diff 只输出固定时长(毫秒/秒/分/时/天/周),因为月和年无法从毫秒唯一推导;如果需要日历月差请用 add 加减后再减。

Q: 安装到 web profile 后 dsh run 也能用吗?

A: 不能直接用。web 与 headless 是两个独立 profile,需要分别安装;dsh run 默认走 headless profile,记得用 --profile headless 也加一次。

Q: 卸载会改 dsh 本体或我的 API Key 吗?

A: 不会。插件卸载只移除工具注册,不动 dsh 安装、凭据、provider 配置;同理重装 dsh 也不会自动回带本插件。

Q: 执行超时怎么办?

A: 工具声明的超时时间是 1 秒。四个 action 都是本地纯函数,正常毫秒级完成;如果真触发 timeoutMs 几乎一定是 Node ICU 数据异常或系统时钟异常,需要重启环境。

上手难度

入门 — 装上插件即可调用,无需任何额外配置或凭据;唯一需要学习的是 ISO 8601 时间戳的写法(带不带 Z、要不要时分秒),对于写过 JSON 接口的人都很自然。

已知问题与限制

  • 只接受年份 1000-9999 之间的输入与计算结果;该范围外会被工具拒绝(src/time.ts:140-146, 216-219, 309-314)
  • add 的月份/年份加减有业务上限 3,000,000(约 25 万年),超出会被前置拒绝以避免触达 Date 边界(src/time.ts:188-190)
  • add 的 timezone 仅影响 local/formatted 展示字段,不影响实际运算;想要"墙钟加减"语义需要等 v2(README.md:168)
  • diff 不支持日历月/年差,只能输出固定时长(毫秒/秒/分/时/天/周)(src/time.ts:214-240)
  • 字符串参数限制为 200 字符以内,超长会被前置拒绝(src/time.ts:256-259)
  • 时区数据来自 Node 内置 ICU,"跨平台一致"等价于"相同 Node/ICU 数据版本下一致";历史时区(<1900)的秒级 offset 会被截断到分钟(README.md:170-173)
  • local / formatted 字段是秒精度展示字段;毫秒精度仅保留在 iso / unix 上(README.md:172)

Read the usage guide →

Install steps, key points, FAQ and compatibility for this plugin — auto-derived from indexed fields.

Listing badge

Listed on deepseek-plugin.org
[![Listed on deepseek-plugin.org](https://img.shields.io/badge/listed_on-deepseek--plugin.org-007EC6)](https://deepseek-plugin.org/plugins/omdsh-dev/dsh-toolkit/packages/dsh-tool-time)

Paste this markdown into your GitHub README to link back to this listing. The badge only states the listing — not a security endorsement.

← Back to plugin directory