typescript.naive_datetime
Correctness
Medium
Detects usage of timezone-unaware date operations that cause subtle bugs.
Why It Matters
Section titled “Why It Matters”Naive datetimes:
- Time zone bugs — Comparisons across zones fail
- DST issues — Missing/duplicate hours
- Data corruption — Stored times are ambiguous
Example
Section titled “Example”// ❌ Before (naive datetime)function scheduleTask(at: Date): void { // Date is in local time - what if server is in different TZ? if (at > new Date()) { queue.schedule(at.toISOString()); }}// ✅ After (timezone-aware with luxon)import { DateTime } from 'luxon';
function scheduleTask(at: DateTime): void { if (!at.isValid || !at.zone) { throw new Error('Valid DateTime with timezone required'); } if (at > DateTime.utc()) { queue.schedule(at.toUTC().toISO()); }}What Unfault Detects
Section titled “What Unfault Detects”- new Date() without timezone context
- Date parsing without explicit timezone
- toISOString without UTC conversion
Auto-Fix
Section titled “Auto-Fix”Unfault can suggest luxon or date-fns-tz usage.