What relative time means
Relative expressions are anchored to a reference point — usually now. “3 days ago” from 2026-11-17 is 2026-11-14 at the same wall-clock time in the selected zone. Months are not fixed lengths, so “1 month ago” can mean 28 to 31 days; implementations differ.
- Seconds, minutes, hours — fixed-length units, except when crossing a DST boundary.
- Days — 24 hours normally, but 23 or 25 hours on DST transition days in some zones.
- Months — calendar months, not 30 days.
dayjsanddate-fnsclamp to the end of the month. - Years — calendar years; leap years add a day.
Why the exact timestamp matters
Relative phrases are fine for UI (“updated 2 hours ago”) but terrible for storage and APIs. Always persist an absolute timestamp and render the relative phrase at display time. Otherwise a cached “5 minutes ago” becomes a permanent lie.
Use Intl.RelativeTimeFormat for localized relative labels; it handles plural rules that string concatenation gets wrong.
Common reference points
| Phrase | Approximate seconds | Caveat |
|---|---|---|
| 1 hour ago | 3,600 | Exact unless a DST transition occurred |
| 1 day ago | 86,400 | 23/25 hours on DST days |
| 1 week ago | 604,800 | Fixed seven days |
| 1 month ago | 2,419,200–2,678,400 | 28–31 days |
| 1 year ago | 31,536,000 | 31,622,400 in a leap year |