#4334·date-fns

tzOffset accepts malformed UTC offsets in its manual fallback

Author: xu91102Created Sep 26, 2026Updated Sep 29, 2026

tzOffset accepts malformed UTC offsets after Intl rejects them, because the manual fallback matches any ±HH substring without validating the complete string or component ranges.

Reproduction on main 717ce0a807ea4c6b540d015b5c408723175b2838:

typescript
const date = new Date('2020-01-15T00:00:00Z');
tzOffset('prefix+02:30', date); // 150
tzOffset('+02:30suffix', date); // 150
tzOffset('+24:00', date);       // 1440
tzOffset('+12:60', date);       // 780
tzOffset('+02:', date);        // 120

Expected: NaN for these invalid time-zone strings, consistent with other invalid zones. Keep valid ±HH, ±HHMM and ±HH:MM support as documented, along with the unchanged IANA path.

Seven regression cases fail before the fix. Verified using Node 22.23.2 on macOS. This concerns malformed-input acceptance, separate from existing PRs for negative sub-hour signs. Investigated with OpenAI Codex assistance.