Course contentsShow
← JavaScript
Lesson 1657 of 2,72335. Standard Library and Built-insFree lesson

Understanding Numeric vs Always Options

Control whether output uses numeric form ('in 1 day') or textual form ('tomorrow') with the numeric option.

Understanding Numeric vs Always Options

You'll learn how to control whether relative time displays appear as numbers ("in 1 day") or descriptive words ("tomorrow") using the numeric option.

What This Option Controls

When formatting relative time with Intl.RelativeTimeFormat, you can choose between two presentation styles. By default, the formatter tries to use descriptive terms like "yesterday" or "next week" when they sound natural. The numeric option gives you control over this behavior.

The Two Values

The numeric option accepts two values:

  • "auto" (default): Uses descriptive words when they exist and feel natural. For example, 1 day becomes "tomorrow" and -1 day becomes "yesterday".
  • "always": Forces numeric output in all cases. For example, 1 day becomes "in 1 day" and -1 day becomes "1 day ago".

When to Use Each

Think of it like giving directions. Sometimes saying "tomorrow at 3pm" sounds friendlier and more natural. Other times, especially in data tables or logs, you want consistent numeric formatting: "in 1 day, in 2 days, in 3 days" keeps a predictable pattern.

const autoFormat = new Intl.RelativeTimeFormat('en', { numeric: 'auto' });
const alwaysFormat = new Intl.RelativeTimeFormat('en', { numeric: 'always' });

console.log(autoFormat.format(1, 'day'));    // "tomorrow"
console.log(alwaysFormat.format(1, 'day'));  // "in 1 day"

console.log(autoFormat.format(-1, 'day'));   // "yesterday"
console.log(alwaysFormat.format(-1, 'day')); // "1 day ago"

console.log(autoFormat.format(0, 'day'));    // "today"
console.log(alwaysFormat.format(0, 'day'));  // "in 0 days"

Use "auto" for human-friendly interfaces and "always" when you need consistency or are displaying data systematically.

Key Takeaway: The numeric option controls whether RelativeTimeFormat prefers descriptive words ("auto") or always uses numbers ("always"), letting you balance natural language with predictable formatting.