|
| 1 | +import { describe, expect, it } from 'vitest'; |
| 2 | +import { formatChinaDate } from './utils.js'; |
| 3 | + |
| 4 | +describe('formatChinaDate', () => { |
| 5 | + it('returns the Asia/Shanghai date for a UTC ms at China midnight', () => { |
| 6 | + expect(formatChinaDate(Date.UTC(2026, 4, 7, 16, 0, 0))).toBe('2026-05-08'); |
| 7 | + }); |
| 8 | + it('returns the same China date for a moment late in the day', () => { |
| 9 | + expect(formatChinaDate(Date.UTC(2026, 4, 8, 14, 0, 0))).toBe('2026-05-08'); |
| 10 | + }); |
| 11 | + it('formats representative A-share and US-market bars on xueqiu Beijing dates', () => { |
| 12 | + expect(formatChinaDate(Date.UTC(2026, 4, 7, 16, 0, 0))).toBe('2026-05-08'); |
| 13 | + expect(formatChinaDate(Date.UTC(2026, 4, 10, 16, 0, 0))).toBe('2026-05-11'); |
| 14 | + }); |
| 15 | + it('crosses the China day boundary at 16:00 UTC', () => { |
| 16 | + expect(formatChinaDate(Date.UTC(2026, 0, 1, 15, 59, 59))).toBe('2026-01-01'); |
| 17 | + expect(formatChinaDate(Date.UTC(2026, 0, 1, 16, 0, 0))).toBe('2026-01-02'); |
| 18 | + }); |
| 19 | + it('always returns an ISO calendar date string, not a locale-shaped slash date', () => { |
| 20 | + expect(formatChinaDate(Date.UTC(2026, 0, 1, 16, 0, 0))).toMatch(/^\d{4}-\d{2}-\d{2}$/); |
| 21 | + }); |
| 22 | + it('returns null for nullish input', () => { |
| 23 | + expect(formatChinaDate(null)).toBeNull(); |
| 24 | + expect(formatChinaDate(undefined)).toBeNull(); |
| 25 | + }); |
| 26 | +}); |
0 commit comments