forked from wangziqi/gongxue-base
由 OCR(open-codereview.ai,deepseek-v4-flash)审查驱动修复: - wallets 原子扣款防 double-spend;refund 条件更新幂等;findTransactions 分页 - financial/imports/occupancies/attendance 事务与 advisory lock;重复生成/提交幂等 - 矛盾校验器、日期区间、实体双映射/DECIMAL/nullable、时区统一(china-time) - rbac-seed 防重激活、exam 权限恢复、状态一致性、路由顺序、N+1/IN 分块等性能项 Reviewed-by: OCR (open-codereview.ai)
39 lines
1.3 KiB
TypeScript
39 lines
1.3 KiB
TypeScript
import {
|
|
CHINA_UTC_OFFSET,
|
|
addDaysToDateOnly,
|
|
getWeekDayFromDateOnly,
|
|
isConsecutiveDates,
|
|
parseChinaDateOnly,
|
|
} from './china-time';
|
|
|
|
describe('china-time', () => {
|
|
it('exports UTC+8 offset', () => {
|
|
expect(CHINA_UTC_OFFSET).toBe(8);
|
|
});
|
|
|
|
it('addDaysToDateOnly crosses month/year boundaries', () => {
|
|
expect(addDaysToDateOnly('2026-02-28', 1)).toBe('2026-03-01');
|
|
expect(addDaysToDateOnly('2026-12-31', 1)).toBe('2027-01-01');
|
|
expect(addDaysToDateOnly('2026-01-01', -1)).toBe('2025-12-31');
|
|
expect(addDaysToDateOnly('2026-08-09', 7)).toBe('2026-08-16');
|
|
});
|
|
|
|
it('getWeekDayFromDateOnly is timezone independent', () => {
|
|
// 2026-08-09 是周日 → 7
|
|
expect(getWeekDayFromDateOnly('2026-08-09')).toBe(7);
|
|
// 2026-08-10 是周一 → 1
|
|
expect(getWeekDayFromDateOnly('2026-08-10')).toBe(1);
|
|
});
|
|
|
|
it('parseChinaDateOnly anchors to UTC+8 midnight', () => {
|
|
const d = parseChinaDateOnly('2026-08-09');
|
|
expect(d.toISOString()).toBe('2026-08-08T16:00:00.000Z');
|
|
});
|
|
|
|
it('isConsecutiveDates detects adjacent dates', () => {
|
|
expect(isConsecutiveDates('2026-08-09', '2026-08-10')).toBe(true);
|
|
expect(isConsecutiveDates('2026-08-09', '2026-08-11')).toBe(false);
|
|
expect(isConsecutiveDates('2026-08-09', '2026-08-09')).toBe(false);
|
|
});
|
|
});
|