RelativeTimeFormat
Bindings to JavaScript's Intl.RelativeTimeFormat.
See MDN for API details.
t
type tnumeric
type numeric = [#always | #auto]style
type style = [#long | #narrow | #short]timeUnit
type timeUnit = [
| #day
| #hour
| #minute
| #month
| #quarter
| #second
| #week
| #year
]options
type options = {
localeMatcher?: Intl_Common.localeMatcher,
numeric?: numeric,
style?: style,
}supportedLocalesOptions
type supportedLocalesOptions = {
localeMatcher: Intl_Common.localeMatcher,
}resolvedOptions
type resolvedOptions = {
locale: string,
numeric: numeric,
style: style,
numberingSystem: string,
}relativeTimePartComponent
type relativeTimePartComponent = [#integer | #literal]relativeTimePart
type relativeTimePart = {
\"type": relativeTimePartComponent,
value: string,
unit?: timeUnit,
}make
let make: (~locales: array<string>=?, ~options: options=?) => tCreates a new Intl.RelativeTimeFormat instance for formatting relative time strings.
See Intl.RelativeTimeFormat on MDN.
Examples
RESCRIPTlet formatter = Intl.RelativeTimeFormat.make(~locales=["en-US"])
formatter->Intl.RelativeTimeFormat.format(1, #day)->String.length > 0
supportedLocalesOf
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
RESCRIPTIntl.RelativeTimeFormat.supportedLocalesOf(["en-US", "klingon"]) == ["en-US"]
resolvedOptions
let resolvedOptions: t => resolvedOptionsresolvedOptions(formatter) returns the locale and options currently in use.
See Intl.RelativeTimeFormat.prototype.resolvedOptions on MDN.
Examples
RESCRIPTlet formatter = Intl.RelativeTimeFormat.make(~locales=["en-US"])
Intl.RelativeTimeFormat.resolvedOptions(formatter).locale == "en-US"
format
let format: (t, int, timeUnit) => stringformat(formatter, value, unit) returns the formatted string for value expressed in unit.
Examples
RESCRIPTlet formatter = Intl.RelativeTimeFormat.make(~locales=["en"])
formatter->Intl.RelativeTimeFormat.format(-1, #day)->String.length > 0
formatToParts
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
RESCRIPTlet formatter = Intl.RelativeTimeFormat.make(~locales=["en"])
formatter->Intl.RelativeTimeFormat.formatToParts(-1, #day)->Array.length > 0
ignore
let ignore: t => unitignore(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.