Time Units: week, month, quarter, year
What you'll learn: How to format relative time using larger units like weeks, months, quarters, and years with Intl.RelativeTimeFormat.
Understanding Larger Time Units
While seconds, minutes, hours, and days work well for short-term relative times ("3 hours ago"), longer periods need bigger units. Intl.RelativeTimeFormat supports "week", "month", "quarter", and "year" to express time spans that stretch over weeks, months, or years.
Think of it like choosing the right measuring tool: you wouldn't measure a road trip in inches—you'd use miles. Similarly, "52 weeks ago" sounds awkward compared to "1 year ago."
Using Larger Units
Each unit follows the same pattern you've already learned:
const rtf = new Intl.RelativeTimeFormat('en', { numeric: 'auto' });
// Weeks
console.log(rtf.format(-2, 'week')); // "2 weeks ago"
console.log(rtf.format(1, 'week')); // "next week"
// Months
console.log(rtf.format(-3, 'month')); // "3 months ago"
console.log(rtf.format(6, 'month')); // "in 6 months"
// Quarters
console.log(rtf.format(-1, 'quarter')); // "last quarter"
console.log(rtf.format(2, 'quarter')); // "in 2 quarters"
// Years
console.log(rtf.format(-1, 'year')); // "last year"
console.log(rtf.format(5, 'year')); // "in 5 years"
Choosing the Right Unit
The API doesn't automatically convert units for you. If you calculate that something happened 400 days ago, you'll need to decide whether to show it as "57 weeks ago" or "13 months ago" or "1 year ago"—the formatter only handles the output, not the calculation logic.
Key Takeaway: Intl.RelativeTimeFormat supports "week", "month", "quarter", and "year" units for expressing longer time periods, but you must choose and calculate the appropriate unit yourself based on your application's needs.