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:
- Which index? Months start at 0.
getDayis the weekday andgetDatethe day of the month. - Was the parse valid? An Invalid Date is truthy. Check
getTime()forNaN. - Which zone? A date-only string is UTC. A date-time without an offset is local.
toISOString()is always UTC. - Which unit? JWT
exp, Unix timestamps and many APIs use seconds, while JavaScript uses milliseconds. - Whose "today"? A day boundary belongs to a user's time zone, not the server's.
- Is the
Dateshared? Theset…methods change it in place. - What happens at the edges? The 31st, the last day of a month, a leap year, the night the clocks change.
- Is the range half-open?
>= startand< next startnever drops the last day.
Tells
| You see | Ask |
|---|---|
new Date(y, 12, …) or month from a form | Zero-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 object | Shared Date? |
setMonth(getMonth() + 1) | What about the 31st? |
<= end with a date-only end | Is the last day dropped? |
+ 24 * 60 * 60 * 1000 | Clock change? |
Go deeper
- Values, equality and numbers:
NaNchecks and unsafe numbers - Previous surface: Functions,
thisand closures · Next: Resources and cleanup