6 min read

Eye Training · Time and Dates

A Date is one instant. Every bug comes from forgetting which calendar, which time zone or which unit you're reading it in.

Part 2 · Surface 23. Bug counts are hidden and some snippets are clean. See Start Here for how to use these drills.


J · The basics

Bug hunt
J · Launch date
Bug count hidden, and some snippets are clean. Click every line you think is wrong (or none), then check.
0:00 / 1 min
Bug hunt
J · Date label
Bug count hidden, and some snippets are clean. Click every line you think is wrong (or none), then check.
0:00 / 1 min
Bug hunt
J · Parse a due date
Bug count hidden, and some snippets are clean. Click every line you think is wrong (or none), then check.
0:00 / 1 min
Bug hunt
J · Sort events
Bug count hidden, and some snippets are clean. Click every line you think is wrong (or none), then check.
0:00 / 1 min

M · Three years in, these should jump out

Bug hunt
M · Birthday card
Bug count hidden, and some snippets are clean. Click every line you think is wrong (or none), then check.
0:00 / 1 min
Bug hunt
M · Invoice due date
Bug count hidden, and some snippets are clean. Click every line you think is wrong (or none), then check.
0:00 / 1 min
Bug hunt
M · Token expiry
Bug count hidden, and some snippets are clean. Click every line you think is wrong (or none), then check.
0:00 / 1 min
Bug hunt
M · Daily streak
Bug count hidden, and some snippets are clean. Click every line you think is wrong (or none), then check.
0:00 / 2 min
Bug hunt
M · Order time
Bug count hidden, and some snippets are clean. Click every line you think is wrong (or none), then check.
0:00 / 1 min

S · Where seniors stand out

Bug hunt
S · Next billing date
Bug count hidden, and some snippets are clean. Click every line you think is wrong (or none), then check.
0:00 / 2 min
Bug hunt
S · Monthly report
Bug count hidden, and some snippets are clean. Click every line you think is wrong (or none), then check.
0:00 / 2 min
Bug hunt
S · Same time tomorrow
Bug count hidden, and some snippets are clean. Click every line you think is wrong (or none), then check.
0:00 / 2 min

What your eye checks

Whenever a snippet builds, parses, compares or stores a date, ask:

  1. Which index? Months start at 0. getDay is the weekday and getDate the day of the month.
  2. Was the parse valid? An Invalid Date is truthy. Check getTime() for NaN.
  3. Which zone? A date-only string is UTC. A date-time without an offset is local. toISOString() is always UTC.
  4. Which unit? JWT exp, Unix timestamps and many APIs use seconds, while JavaScript uses milliseconds.
  5. Whose "today"? A day boundary belongs to a user's time zone, not the server's.
  6. Is the Date shared? The set… methods change it in place.
  7. What happens at the edges? The 31st, the last day of a month, a leap year, the night the clocks change.
  8. Is the range half-open? >= start and < next start never drops the last day.

Tells

You seeAsk
new Date(y, 12, …) or month from a formZero-based?
getDay()Weekday or day of the month?
if (!date) after new Date(…)Invalid Date is truthy
new Date('2026-11-09')UTC midnight: which day does the user see?
exp, iat, timestamp next to Date.now()Seconds or milliseconds?
toISOString().slice(0, 10)Whose day?
date.setDate(…) on a field of another objectShared Date?
setMonth(getMonth() + 1)What about the 31st?
<= end with a date-only endIs the last day dropped?
+ 24 * 60 * 60 * 1000Clock change?

Go deeper