Skip to content

typescript.naive_datetime

Correctness Medium

Detects usage of timezone-unaware date operations that cause subtle bugs.

Naive datetimes:

  • Time zone bugs — Comparisons across zones fail
  • DST issues — Missing/duplicate hours
  • Data corruption — Stored times are ambiguous
// ❌ 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());
}
}
  • new Date() without timezone context
  • Date parsing without explicit timezone
  • toISOString without UTC conversion

Unfault can suggest luxon or date-fns-tz usage.