- Companion
- object
Value members
Concrete methods
Formats a value and a unit according to the locale
and formatting options of the given
Intl.RelativeTimeFormat
object.
Formats a value and a unit according to the locale
and formatting options of the given
Intl.RelativeTimeFormat
object.
While this method automatically provides the correct plural forms, the grammatical form is otherwise as neutral as possible. It is the caller's responsibility to handle cut-off logic such as deciding between displaying "in 7 days" or "in 1 week". This API does not support relative dates involving compound units. e.g "in 5 days and 4 hours".
- Value Params
- unit
- Unit
to use in the relative time internationalized message.
Possible values are:
"year"
,"quarter"
,"month"
,"week"
,"day"
,"hour"
,"minute"
,"second"
. Plural forms are also permitted.
- Unit
to use in the relative time internationalized message.
Possible values are:
- value
- Numeric value to use in the internationalized relative time message
- Throws
- `RangeError`
if
unit
was given something other thanunit
possible values
A version of the format method which it returns an array of objects
which represent "parts" of the object,
separating the formatted number into its constituent parts
and separating it from other surrounding text.
These objects have two properties:
type
a NumberFormat formatToParts type, and value
,
which is the String which is the component of the output.
If a "part" came from NumberFormat,
it will have a unit property which indicates the unit
being formatted;
literals which are part of the larger frame will not have this property.
A version of the format method which it returns an array of objects
which represent "parts" of the object,
separating the formatted number into its constituent parts
and separating it from other surrounding text.
These objects have two properties:
type
a NumberFormat formatToParts type, and value
,
which is the String which is the component of the output.
If a "part" came from NumberFormat,
it will have a unit property which indicates the unit
being formatted;
literals which are part of the larger frame will not have this property.
- Value Params
- unit
- Unit
to use in the relative time internationalized message.
Possible values are:
"year"
,"quarter"
,"month"
,"week"
,"day"
,"hour"
,"minute"
,"second"
. Plural forms are also permitted.
- Unit
to use in the relative time internationalized message.
Possible values are:
- value
- Numeric value to use in the internationalized relative time message
- Throws
- `RangeError`
if
unit
was given something other thanunit
possible values