time.spec.ts 1.3 KB

1234567891011121314151617181920212223242526272829
  1. import { describe, expect, it } from 'vitest'
  2. import { canonicalClientTimeZone } from '@deepseek-ai/dsh-util-time'
  3. describe('canonicalClientTimeZone', () => {
  4. it('accepts UTC and Area/Location names unchanged', () => {
  5. expect(canonicalClientTimeZone('UTC')).toBe('UTC')
  6. expect(canonicalClientTimeZone('Asia/Shanghai')).toBe('Asia/Shanghai')
  7. expect(canonicalClientTimeZone('Europe/London')).toBe('Europe/London')
  8. })
  9. it('answers the platform-canonical name rather than the alias asked for', () => {
  10. // A durable record is compared against the zone a later reader derives, so
  11. // an alias must not survive the boundary. Which name each alias group
  12. // resolves to is the runtime's ICU data, not this library's choice.
  13. const canonical = canonicalClientTimeZone('Asia/Chongqing')
  14. expect(canonical).not.toBe('Asia/Chongqing')
  15. expect(canonicalClientTimeZone(canonical ?? '')).toBe(canonical)
  16. })
  17. it('refuses blank, padded, abbreviated, and single-segment names', () => {
  18. for (const value of ['', ' ', ' UTC', 'UTC ', 'CST', 'GMT+8', 'Asia', 'utc']) {
  19. expect(canonicalClientTimeZone(value)).toBeUndefined()
  20. }
  21. })
  22. it('refuses a well-formed name the platform does not support', () => {
  23. expect(canonicalClientTimeZone('Not/A_Real_Zone')).toBeUndefined()
  24. })
  25. })