π§ 10 Date-and-Time Bugs I Still See in Production (and How to Avoid Them)
A senior developer's checklist of the mistakes that break schedules, invoices, and reports. Includes code samples and free tools to fix every issue.
After more than a decade writing backend code, I've fixed the same time-related bugs over and over.
Below are ten of the worst offenders, why they happen, and a proven way to avoid each one. I've linked free tools and API calls from Pastetime so you can try the fixes right away.
π Bug 1 β Storing Local Time in the Database
What you see
Reports jump an hour forward or back every spring and autumn.
Why it happens
Local timestamps are ambiguous when daylightβsaving rules shift or the server moves to a new zone.
Fix
Store UTC only, convert on display.
Quick test
Paste any local time into the UTC-to converter to see the safe format.
π Bug 2 β Mixing Unix Seconds and Milliseconds
Symptom
Graphs plot dates in the year 51345 or collapse to 1970.
// Safe JS conversion
const unixMs = 1754136000000; // milliseconds
const date = new Date(unixMs); // correct
const unixS = Math.floor(unixMs / 1000);
Need a spot-check?
POST /api/convert-timestamp
in the API docs returns both seconds and milliseconds.
π Bug 3 β Hard-coding Weekends
Problem Business-day counts are wrong where the weekend is FridayβSaturday.
curl -X POST "https://www.pastetime.com/api/business-days" \
-H "Content-Type: application/json" \
-d '{
"startDate": "2025-07-01",
"endDate": "2025-07-10",
"weekendDays": ["Friday","Saturday"]
}'
Or use the UI at /business-days-calculator.
π Bug 4 β Ignoring DST in Cron Jobs
Jobs drift by an hour when daylight-saving hits. Fix: run cron in UTC or use a scheduler that's zone-aware.
π Bug 5 β DIY Natural-Language Parsing
Regex can't parse "next Friday 3 pm Berlin."
POST /api/convert
handles it and returns ISO, Unix, and human text.
π Bug 6 β Silent JavaScript Date Coercion
new Date('2025-07-02')
can flip to the previous day in some browsers.
Always include the timezone offset or use a library like date-fns-tz
.
π Bug 7 β Hard-coded Holiday Lists
Holiday arrays go stale. Pass holidays at runtime via the Business Days API, or store them centrally.
π Bug 8 β Leap Year (and Leap Second) Edge Cases
Date math fails on Feb 29 or during leap seconds. Trust a tested library or API instead of hand-rolled arithmetic.
π Bug 9 β Server Timezone Drift
Containers boot in UTC, code expects local.
Pin the TZ
env var or convert to UTC everywhere.
π Bug 10 β Sorting Raw Date Strings
2025-07-2
sorts before 2025-07-12
.
Use padded ISO (YYYY-MM-DD
) or Unix timestamps, not loose strings.
π Cheat Sheet
Bug | Fast Fix | Tool / API |
---|---|---|
Local time in DB | Store UTC only | /utc-to |
Seconds vs ms | Standardise or convert | /api/convert-timestamp |
Hard-coded weekends | Pass config | /api/business-days |
DST cron drift | Run in UTC | Upcoming cron guide |
DIY NLP parsing | Use API | /api/convert |
JS coercion | Include TZ offset | Timestamp guide |
π Wrap-Up
Date bugs rarely crash apps, yet they quietly break schedules and revenue. Use the Pastetime web tools for quick fixes or call the API when you need reliable automation.
Have a horror story or feature request? Open an issue or ping me on X.
Support the project on Ko-fi or Buy Me a Coffee.