⚠️ Ambiguous Time Detector
Discover the dark corners of DST transitions. Explore nonexistent times that never happened and ambiguous times that happened twice. Learn to detect and handle these edge cases before they break your code.
🔍 Time Detective
🚫 Nonexistent Time
Input Time
2024-03-10 02:30:00
America/New_York
Issue Details
This time does not exist due to DST spring forward transition
UTC Equivalent
2024-03-10 07:30:00 UTC
💡 Recommendations
- • Use timezone-aware libraries that handle this automatically
- • Consider scheduling critical tasks in UTC
- • Add validation to reject nonexistent times
- • Use the next valid time instead
🎯 Famous Edge Cases
Handling Ambiguous Times in Code
// ✅ Recommended: Use Luxon for DST edge case handling
import { DateTime } from 'luxon';
// Check if a time exists and is unambiguous
function analyzeTime(dateTime, timezone) {
try {
const dt = DateTime.fromISO("2024-03-10T02:30:00", { zone: "America/New_York" });
if (!dt.isValid) {
return { status: 'invalid', reason: dt.invalidReason };
}
// Check for nonexistent time (spring forward)
const naive = DateTime.fromISO("2024-03-10T02:30:00");
if (naive.hour !== dt.hour) {
return {
status: 'nonexistent',
adjustedTime: dt.toISO(),
reason: 'Time skipped due to DST spring forward'
};
}
// Check for ambiguous time (fall back)
if (dt.isInDST !== dt.minus({ hours: 1 }).isInDST) {
return {
status: 'ambiguous',
firstOccurrence: dt.toISO(),
secondOccurrence: dt.plus({ hours: 1 }).toISO(),
reason: 'Time occurs twice due to DST fall back'
};
}
return { status: 'normal', time: dt.toISO() };
} catch (error) {
return { status: 'error', reason: error.message };
}
}
// Usage
const result = analyzeTime("2024-03-10T02:30:00", "America/New_York");
console.log('Analysis result:', result);
// ❌ Avoid: Using native Date for DST edge cases
const badDate = new Date("2024-03-10T02:30:00"); // Doesn't handle DST properly!
// ✅ Safe handling of ambiguous times
const safeTime = DateTime.fromISO("2024-03-10T02:30:00", {
zone: "America/New_York",
// Use setZone with keepLocalTime for explicit control
}).setZone("UTC");