Files
lingxi/packages/shared/src/time.spec.ts
T
Stev_Wang 04f49690f4
ci / 质量门禁 (push) Canceled after 0s
feat(a0): 完成工程骨架与契约基线
- 建立 pnpm workspace + Turborepo 单仓、ESLint 9/Prettier/commitlint/husky 门禁
- NestJS + Fastify API:统一错误体、trace_id、Zod 管道、/health 真实依赖探活、OpenAPI 3.1 契约
- Prisma 基线:outbox_events/idempotency_keys/system_configs 与首版迁移、幂等种子
- shared 契约包:错误码、权限点、ULID、游标分页、命名/时间工具
- ui 包与 Web 壳层:Semi + Remix 图标统一出口、Cloud Blue 视觉、登录/工作台/错误页
- worker 骨架、Playwright 冒烟、Gitea CI、OpenAPI 快照与 oasdiff 回退脚本
- 补充 A0 实施报告与本地开发说明
2026-11-02 17:01:50 +08:00

32 lines
1.1 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { addSeconds, isIsoDateString, nowIso, toIsoString } from './time.js';
describe('time utils', () => {
it('nowIso 返回 UTC ISO 字符串', () => {
expect(isIsoDateString(nowIso())).toBe(true);
});
it('toIsoString 支持 Date / 时间戳 / 字符串', () => {
const date = new Date('2026-11-02T08:00:00.000Z');
expect(toIsoString(date)).toBe('2026-11-02T08:00:00.000Z');
expect(toIsoString(date.getTime())).toBe('2026-11-02T08:00:00.000Z');
expect(toIsoString('2026-11-02T08:00:00.000Z')).toBe('2026-11-02T08:00:00.000Z');
});
it('非法时间抛错', () => {
expect(() => toIsoString('not-a-date')).toThrow(TypeError);
});
it('addSeconds 不修改原对象', () => {
const date = new Date('2026-11-02T08:00:00.000Z');
expect(addSeconds(date, 90).toISOString()).toBe('2026-11-02T08:01:30.000Z');
expect(date.toISOString()).toBe('2026-11-02T08:00:00.000Z');
});
it('isIsoDateString 拒绝非 UTC 格式', () => {
expect(isIsoDateString('2026-11-02T08:00:00+08:00')).toBe(false);
expect(isIsoDateString('2026-13-02T08:00:00.000Z')).toBe(false);
});
});