HeadlinesBriefing favicon HeadlinesBriefing.com

Fixing a 14-Hour VS Code Timezone Bug

DEV Community •
×

A developer discovered a critical bug in their VS Code extension, DotShare, where scheduled posts fired 14 hours late. The root cause was a timezone trap: using `toISOString()` on a `datetime-local` input string, which misinterpreted local time as UTC. This created a compounding error from an AM/PM confusion and a UTC+2 offset, delaying posts until 2:00 AM instead of noon.

To resolve the issue, the developer replaced complex Date object comparisons with a simpler system using Unix timestamps. By storing times as standardized ISO strings and comparing them via `.getTime()`—which returns absolute milliseconds since the epoch—the scheduler now operates independently of timezones. This approach eliminated the ambiguity that caused the original lag.

The fix resulted in zero latency, with posts triggering precisely on schedule. Key lessons include never trusting `datetime-local` inputs without explicit parsing, using debug logs to trace logic, and remembering to convert milliseconds to seconds (using `Math.floor`) for APIs like Telegram. This case highlights a common pitfall in web development.