relative-time
Imported from yugajs/extension/relative-time.
Interfaces
Section titled “Interfaces”RelativeTimeConfig
Section titled “RelativeTimeConfig”Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
rounding? |
(value) => number |
Rounds the count of a step, Math.round by default. |
thresholds? |
readonly RelativeTimeThreshold[] |
The steps, Day.js’s defaults: 44 seconds, 89 seconds, 44 minutes, 89 minutes, 21 hours, 35 hours, 25 days, 45 days, 10 months and 17 months. |
RelativeTimeStrings
Section titled “RelativeTimeStrings”A locale’s relativeTime, Day.js’s object: future and past wrap the words, the other keys
are the words (s seconds, m a minute, mm minutes, h, hh, d, dd, M, MM, y,
yy).
Indexable
Section titled “Indexable”[key: string]: | string | ((count, withoutSuffix, key, isFuture) => string) | ((words) => string) | undefinedProperties
Section titled “Properties”| Property | Type |
|---|---|
d? |
RelativeTimeFormatter |
dd? |
RelativeTimeFormatter |
future |
RelativeTimeWrapper |
h? |
RelativeTimeFormatter |
hh? |
RelativeTimeFormatter |
m? |
RelativeTimeFormatter |
M? |
RelativeTimeFormatter |
mm? |
RelativeTimeFormatter |
MM? |
RelativeTimeFormatter |
past |
RelativeTimeWrapper |
s? |
RelativeTimeFormatter |
y? |
RelativeTimeFormatter |
yy? |
RelativeTimeFormatter |
RelativeTimeThreshold
Section titled “RelativeTimeThreshold”A step of the thresholds, the first one that fits is used. The same as Day.js’s.
Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
d? |
yuga.Unit |
The unit the count is measured in, the following steps without one reuse it. |
l |
string |
The key of the words, "s", "m", "mm", "h", "hh", "d", "dd", "M", "MM", "y" or "yy". Singular keys (“a minute”) never show their count. |
r? |
number |
The largest rounded count the step fits, the last step has none. |
Type Aliases
Section titled “Type Aliases”RelativeTimeFormatter
Section titled “RelativeTimeFormatter”type RelativeTimeFormatter = string | ((count, withoutSuffix, key, isFuture) => string);A word of a locale’s relativeTime, %d is the count. A function gets the count,
withoutSuffix, the key ("mm") and whether it’s the future.
RelativeTimeWrapper
Section titled “RelativeTimeWrapper”type RelativeTimeWrapper = string | ((words) => string);What future and past wrap the words with, %s is the words ("in %s"). A function gets the
finished words ("2 hours"), the same as Day.js.
Variables
Section titled “Variables”relativeTime
Section titled “relativeTime”const relativeTime: yuga.Extension< | RelativeTimeConfig| undefined>;Relative time, Day.js’s relativeTime plugin: fromNow, from, toNow and to.
yuga.extend(relativeTime, { thresholds, rounding });en is Day.js’s English (“a few seconds ago”), other locales use Intl.RelativeTimeFormat
(“il y a 2 heures”) unless they have a relativeTime object.
relativeWords
Section titled “relativeWords”const relativeWords: (measure, localeName, withoutSuffix?, config?) => string;A difference in words, what fromNow, from, toNow and to use (and what a duration’s
humanize can reuse).
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
measure |
(unit) => number |
The signed difference in a unit ("second", "minute", "hour", "day", "month", "year"), positive is the future. Fractions are rounded by the thresholds. It is only called for the units the steps reach. |
localeName |
string |
A registered locale (an unknown one is English). |
withoutSuffix? |
boolean |
Drop the “ago” / “in”. |
config? |
RelativeTimeConfig |
The thresholds and rounding, the ones relativeTime was installed with when omitted (Day.js’s defaults without them). |
Returns
Section titled “Returns”string
The words, or the locale’s invalidDate when the difference is NaN. The same as
Day.js’s fromToBase, including a step without a unit reusing the previous count, and a count
of 1 or less using the previous step (“1 minute” is “a minute”).
const rtfOf: (name, auto?) => Intl.RelativeTimeFormat;The cached Intl.RelativeTimeFormat of a locale, auto says “yesterday” and “tomorrow” for a
day (numeric: "auto"). Throws for a name Intl rejects.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
name |
string |
auto? |
boolean |
Returns
Section titled “Returns”Intl.RelativeTimeFormat