RelativeTimeFormat

Bindings to JavaScript's Intl.RelativeTimeFormat.

See MDN for API details.

format

RESCRIPT
let format: (t, int, timeUnit) => string

format(formatter, value, unit) returns the formatted string for value expressed in unit.

Examples

RESCRIPT
let formatter = Intl.RelativeTimeFormat.make(~locales=["en"]) formatter->Intl.RelativeTimeFormat.format(-1, #day)->String.length > 0

formatToParts

RESCRIPT
let formatToParts: (t, int, timeUnit) => array<relativeTimePart>

formatToParts(formatter, value, unit) returns an array describing how the output string is assembled.

See Intl.RelativeTimeFormat.prototype.formatToParts on MDN.

Examples

RESCRIPT
let formatter = Intl.RelativeTimeFormat.make(~locales=["en"]) formatter->Intl.RelativeTimeFormat.formatToParts(-1, #day)->Array.length > 0

ignore

RESCRIPT
let ignore: t => unit

ignore(relativeTimeFormat) ignores the provided relativeTimeFormat and returns unit.

This helper is useful when you want to discard a value (for example, the result of an operation with side effects) without having to store or process it further.

make

RESCRIPT
let make: (~locales: array<string>=?, ~options: options=?) => t

Creates a new Intl.RelativeTimeFormat instance for formatting relative time strings.

See Intl.RelativeTimeFormat on MDN.

Examples

RESCRIPT
let formatter = Intl.RelativeTimeFormat.make(~locales=["en-US"]) formatter->Intl.RelativeTimeFormat.format(1, #day)->String.length > 0

numeric

RESCRIPT
type numeric = [#always | #auto]

options

RESCRIPT
type options = { localeMatcher?: Intl_Common.localeMatcher, numeric?: numeric, style?: style, }

relativeTimePart

RESCRIPT
type relativeTimePart = { \"type": relativeTimePartComponent, value: string, unit?: timeUnit, }

relativeTimePartComponent

RESCRIPT
type relativeTimePartComponent = [#integer | #literal]

resolvedOptions

RESCRIPT
type resolvedOptions = { locale: string, numeric: numeric, style: style, numberingSystem: string, }

resolvedOptions

RESCRIPT
let resolvedOptions: t => resolvedOptions

resolvedOptions(formatter) returns the locale and options currently in use.

See Intl.RelativeTimeFormat.prototype.resolvedOptions on MDN.

Examples

RESCRIPT
let formatter = Intl.RelativeTimeFormat.make(~locales=["en-US"]) Intl.RelativeTimeFormat.resolvedOptions(formatter).locale == "en-US"

style

RESCRIPT
type style = [#long | #narrow | #short]

supportedLocalesOf

RESCRIPT
let supportedLocalesOf: ( array<string>, ~options: supportedLocalesOptions=?, ) => array<string>

supportedLocalesOf(locales, ~options) filters locales to those supported for relative time formatting.

See Intl.RelativeTimeFormat.supportedLocalesOf on MDN.

Examples

RESCRIPT
Intl.RelativeTimeFormat.supportedLocalesOf(["en-US", "klingon"]) == ["en-US"]

supportedLocalesOptions

RESCRIPT
type supportedLocalesOptions = { localeMatcher: Intl_Common.localeMatcher, }

t

RESCRIPT
type t

timeUnit

RESCRIPT
type timeUnit = [ | #day | #hour | #minute | #month | #quarter | #second | #week | #year ]