Skip to main content
Version: 1.7.3

RelativeTimeFieldFormatOptions

Syntax

object {
  width?,
  nu?,
  context?,
  group?,
  round?,
  minimumIntegerDigits?,
  maximumFractionDigits?,
  minimumFractionDigits?,
  maximumSignificantDigits?,
  minimumSignificantDigits?
}

Properties

  • width?: RelativeTimeWidthType
    • Width of the unit of relative time: 'short' | 'narrow' | 'wide'
  • numericOnly?: boolean
    • Always use a format that includes a number, e.g. "1 day ago" instead of "Yesterday".
  • alwaysNow?: boolean
    • In numericOnly mode, if the value to be formatted is exactly zero, use the "now" format instead of a numeric format, e.g. "Today" instead of "In 0 days".
  • nu?: NumberSystemType
    • Override the numbering system
  • context?: ContextType
    • Specify the context in which the string will be display
  • group?: boolean
    • Enable grouping of digits.
  • round?: RoundingModeType
    • Mode used to round numbers during formatting.
  • minimumIntegerDigits?: number
    • Minimum integer digits to display.
  • maximumFractionDigits?: number
    • Maximum fraction digits to display.
  • minimumFractionDigits?: number
    • Minimum fraction digits to display.
  • maximumSignificantDigits?: number
    • Maximum significant digits to display.
  • minimumSignificantDigits?: number
    • Minimum significant digits to display.

Defaults

{
context: 'middle-of-text'
}

Example

const cldr = framework.get('en');
for (const n of [-5, -2, -1, 0, 1, 2, 5]) {
log(cldr.Calendars.formatRelativeTimeField(n, 'day');
}
log();
for (const n of [3.3, 3.5, 3.8]) {
log(cldr.Calendars.formatRelativeTimeField(n, 'day');
log(cldr.Calendars.formatRelativeTimeField(n, 'day', { maximumFractionDigits: 1 });
}
5 days ago
2 days ago
yesterday
today
tomorrow
in 2 days
in 5 days
 
in 3 days
in 3.3 days
in 4 days
in 3.5 days
in 4 days
in 3.8 days
for (const n of [-5, -2, -1, 0, 1, 2, 5]) {
log(cldr.Calendars.formatRelativeTimeField(n, 'day', { numericOnly: true });
}
5 days ago
2 days ago
1 day ago
in 0 days
in 1 day
in 2 days
in 5 days

References