Relative Time Phrases

easy
Unit 7 · Datetime I0/3 to milestone

Implement relative(then, now) for two datetime objects returning a human phrase:

  • under 45 seconds: "just now" (or "in a moment" if then is in the future)
  • otherwise use the largest unit of minutes, hours, days, weeks (7 days), months (30 days) and years (365 days) with a value of at least 1, rounding down, e.g. "5 minutes ago", "1 hour ago", "in 3 days"
  • use the singular for 1
#datetime#formatting2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Relative Time Phrases · TechGradify