yugajs
Imported from yugajs.
Classes
Section titled “Classes”Extends
Section titled “Extends”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Yuga(config): Yuga;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
config |
yuga.Config |
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”yuga.Yuga.constructor
Properties
Section titled “Properties”| Property | Modifier | Type | Inherited from |
|---|---|---|---|
d |
readonly |
number |
yuga.Yuga.d |
D |
readonly |
number |
yuga.Yuga.D |
date |
readonly |
{ (): number; (value): yuga.Yuga; } |
yuga.Yuga.date |
day |
readonly |
{ (): number; (value): yuga.Yuga; } |
yuga.Yuga.day |
h |
readonly |
number |
yuga.Yuga.h |
hour |
readonly |
{ (): number; (value): yuga.Yuga; } |
yuga.Yuga.hour |
m |
readonly |
number |
yuga.Yuga.m |
M |
readonly |
number |
yuga.Yuga.M |
millisecond |
readonly |
{ (): number; (value): yuga.Yuga; } |
yuga.Yuga.millisecond |
minute |
readonly |
{ (): number; (value): yuga.Yuga; } |
yuga.Yuga.minute |
month |
readonly |
{ (): number; (value): yuga.Yuga; } |
yuga.Yuga.month |
ms |
readonly |
number |
yuga.Yuga.ms |
quarter |
readonly |
{ (): number; (value): yuga.Yuga; } |
yuga.Yuga.quarter |
s |
readonly |
number |
yuga.Yuga.s |
second |
readonly |
{ (): number; (value): yuga.Yuga; } |
yuga.Yuga.second |
week |
readonly |
{ (): number; (value): yuga.Yuga; } |
yuga.Yuga.week |
y |
readonly |
number |
yuga.Yuga.y |
year |
readonly |
{ (): number; (value): yuga.Yuga; } |
yuga.Yuga.year |
Accessors
Section titled “Accessors”Get Signature
Section titled “Get Signature”get q(): number;The quarter and week are computed on access since they are rarely used.
Returns
Section titled “Returns”number
Inherited from
Section titled “Inherited from”Get Signature
Section titled “Get Signature”get w(): number;The ISO week of the year (weeks start on Monday, the first week contains January 4th).
Returns
Section titled “Returns”number
Inherited from
Section titled “Inherited from”Methods
Section titled “Methods”add(value, unit?): yuga.Yuga;Adds an amount of a unit (milliseconds by default), Day.js’s add.
y,QandMmove the wall clock and clamp the date to the end of the month (Jan 31 + 1 month is Feb 29 in 2024), fractions are truncated.wandd(orD) move the wall clock by whole days (fractions are rounded), keeping the time of day across DST.h,m,sandmsare absolute time (an hour across DST is 60 minutes later).
Units are case-insensitive. Lowercase q is a quarter (Day.js adds milliseconds).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number |
unit? |
yuga.Unit |
Returns
Section titled “Returns”Example
Section titled “Example”yuga("2024-01-31").add(1, "month"); // 2024-02-29Inherited from
Section titled “Inherited from”calendar()
Section titled “calendar()”calendar(referenceTime?, formats?): string;The instance in calendar words relative to a reference time ("Today at 10:20 AM", "Last Monday at 9:00 AM", "05/15/2024"), Day.js’s calendar plugin. The bucket is the day
difference from the start of the reference’s day, in the instance’s time zone.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
referenceTime? |
yuga.Parsable |
What to compare with, now by default. |
formats? |
CalendarFormats |
The format of each bucket, a template or a function; they win over the locale’s. |
Returns
Section titled “Returns”string
Inherited from
Section titled “Inherited from”clone()
Section titled “clone()”clone(): yuga.Yuga;Creates a clone of the current Yuga class.
Yuga doesn’t support mutability, this function is ported from Moment.js & Day.js.
While Day.js does default to immutability, plugins such as badMutable allow it, Yuga
does not provide such plugins.
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”dates()
Section titled “dates()”Call Signature
Section titled “Call Signature”dates(): number;An alias of date(), the day of the month.
Returns
Section titled “Returns”number
Inherited from
Section titled “Inherited from”Call Signature
Section titled “Call Signature”dates(value): yuga.Yuga;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number |
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”dayOfYear()
Section titled “dayOfYear()”Call Signature
Section titled “Call Signature”dayOfYear(): number;The day of the year in the instance’s time zone, 1 to 366 (Day.js’s dayOfYear plugin).
The setter moves to that day of the year, the same as add(n - dayOfYear(), "day").
Returns
Section titled “Returns”number
Inherited from
Section titled “Inherited from”Call Signature
Section titled “Call Signature”dayOfYear(value): yuga.Yuga;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number |
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”days()
Section titled “days()”Call Signature
Section titled “Call Signature”days(): number;An alias of day(), the day of the week.
Returns
Section titled “Returns”number
Inherited from
Section titled “Inherited from”Call Signature
Section titled “Call Signature”days(value): yuga.Yuga;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number |
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”daysInMonth()
Section titled “daysInMonth()”daysInMonth(): number;Get the number of days in the current month.
NaN when invalid.
Returns
Section titled “Returns”number
Inherited from
Section titled “Inherited from”diff()
Section titled “diff()”diff( that?, unit?, options?): number;The difference from a parsable (now when omitted) to the instance in a unit, milliseconds by
default. NaN when either is invalid (for every unit, Day.js gives 0 for months).
By default it matches Day.js: months, quarters and years use Moment.js’s month difference
(2024-05-15 to 2024-01-31 is 3.48 months), days and weeks discount the change of the UTC
offset, and the result is truncated toward zero.
The parsable is compared in the instance’s time zone, the same as Moment.js.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
that? |
yuga.Parsable |
- |
unit? |
yuga.Unit |
- |
options? |
boolean | yuga.DiffOptions |
true keeps the fraction (Day.js’s float), see DiffOptions. |
Returns
Section titled “Returns”number
Example
Section titled “Example”yuga("2024-05-15").diff("2024-01-31", "month", true); // 3.48…Inherited from
Section titled “Inherited from”endOf()
Section titled “endOf()”endOf(unit): yuga.Yuga;The end of a unit, the start of the next one minus 1 ms (endOf("day") is 23:59:59.999).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
unit |
yuga.Unit | "isoWeek" |
Returns
Section titled “Returns”startOf
Inherited from
Section titled “Inherited from”format()
Section titled “format()”format(template?): string;Formats with a template, Day.js’s format and its advancedFormat tokens, in the instance’s
locale. Text in brackets is escaped ("[Today is] dddd").
YY YYYY M MM MMM MMMM D DD Do d dd ddd dddd H HH h hh a A m mm s ss SSS Z ZZ Qw wwthe week of the locale (itsweekStartandyearStart),W WWthe ISO week.
With no template it is ISO 8601 with the offset ("2024-05-15T06:00:00-04:00", and
"…Z" in UTC), invalid instances are the locale’s invalidDate ("Invalid Date").
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
template? |
string |
Returns
Section titled “Returns”string
Example
Section titled “Example”yuga("2024-05-15").format("dddd, MMMM Do YYYY"); // "Wednesday, May 15th 2024"Inherited from
Section titled “Inherited from”from()
Section titled “from()”from(date?, withoutSuffix?): string;The time from a date to the instance in words, yuga("2024-01-01").from("2024-01-03") is
"2 days ago".
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
date? |
yuga.Parsable |
withoutSuffix? |
boolean |
Returns
Section titled “Returns”string
Inherited from
Section titled “Inherited from”fromNow()
Section titled “fromNow()”fromNow(withoutSuffix?): string;The time from now to the instance in words ("2 hours ago", "in a day"), Day.js’s
relativeTime plugin. Past is “ago”, future is “in”.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
withoutSuffix? |
boolean |
Drop the “ago” / “in” ("2 hours"). |
Returns
Section titled “Returns”string
Inherited from
Section titled “Inherited from”Call Signature
Section titled “Call Signature”get(): string;Get the string value of the class.
Equivalent to yuga().toString()
Returns
Section titled “Returns”string
Inherited from
Section titled “Inherited from”Call Signature
Section titled “Call Signature”get(unit): number;Get the numeric value of the provided unit.
Equivalent to yuga()unit.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
unit |
yuga.Unit |
The unit of the desired value to get. |
Returns
Section titled “Returns”number
Inherited from
Section titled “Inherited from”hours()
Section titled “hours()”Call Signature
Section titled “Call Signature”hours(): number;An alias of hour().
Returns
Section titled “Returns”number
Inherited from
Section titled “Inherited from”Call Signature
Section titled “Call Signature”hours(value): yuga.Yuga;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number |
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”isAfter()
Section titled “isAfter()”isAfter(that, unit?): boolean;Checks if the instance is after a parsable, with a unit: if the parsable is before the start of the instance’s unit.
The unit is in the instance’s time zone and locale (see startOf).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
that |
yuga.Parsable |
unit? |
yuga.Unit | "isoWeek" |
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”isBefore()
Section titled “isBefore()”isBefore(that, unit?): boolean;Checks if the instance is before a parsable, with a unit: if the end of the instance’s unit
is before it (isBefore(x, "day") is true when x is on a later day).
The unit is in the instance’s time zone and locale (see startOf).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
that |
yuga.Parsable |
unit? |
yuga.Unit | "isoWeek" |
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”isBetween()
Section titled “isBetween()”isBetween( a, b, unit?, inclusivity?): boolean;Checks if the instance is between two parsables, given in either order. Exclusive by
default ("()"), "[" and "]" include the lower and upper bound ("[]", "[)",
"(]"). With a unit the comparison is by unit (see isBefore and isAfter).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
a |
yuga.Parsable |
b |
yuga.Parsable |
unit? |
yuga.Unit | "isoWeek" |
inclusivity? |
"()" | "[]" | "[)" | "(]" |
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”isLeapYear()
Section titled “isLeapYear()”isLeapYear(): boolean;Checks if the instance’s year (in its time zone) is a leap year (Day.js’s isLeapYear
plugin). false when invalid.
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”isoWeek()
Section titled “isoWeek()”Call Signature
Section titled “Call Signature”isoWeek(): number;The ISO week of the year, an alias of week() for Day.js code.
Returns
Section titled “Returns”number
Inherited from
Section titled “Inherited from”Call Signature
Section titled “Call Signature”isoWeek(value): yuga.Yuga;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number |
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”isoWeekday()
Section titled “isoWeekday()”Call Signature
Section titled “Call Signature”isoWeekday(): number;The ISO day of the week, Monday is 1 and Sunday is 7. The setter moves within the Monday to Sunday week.
Returns
Section titled “Returns”number
Inherited from
Section titled “Inherited from”Call Signature
Section titled “Call Signature”isoWeekday(value): yuga.Yuga;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number |
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”isoWeeks()
Section titled “isoWeeks()”Call Signature
Section titled “Call Signature”isoWeeks(): number;An alias of isoWeek(), the ISO week of the year.
Returns
Section titled “Returns”number
Inherited from
Section titled “Inherited from”Call Signature
Section titled “Call Signature”isoWeeks(value): yuga.Yuga;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number |
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”isoWeeksInYear()
Section titled “isoWeeksInYear()”isoWeeksInYear(): 52 | 53;The number of ISO weeks in the year, 52 or 53.
Returns
Section titled “Returns”52 | 53
Inherited from
Section titled “Inherited from”isoWeekYear()
Section titled “isoWeekYear()”isoWeekYear(): number;The year the ISO week belongs to (December 30th 2024 is in 2025).
Returns
Section titled “Returns”number
Inherited from
Section titled “Inherited from”isSame()
Section titled “isSame()”isSame(that, unit?): boolean;Checks if the instance is the same moment as a parsable, with a unit: if the parsable is
within the instance’s unit (isSame(x, "week") is the same Sunday to Saturday week in
en).
The unit is in the instance’s time zone and locale (see startOf).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
that |
yuga.Parsable |
unit? |
yuga.Unit | "isoWeek" |
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”isSameOrAfter()
Section titled “isSameOrAfter()”isSameOrAfter(that, unit?): boolean;Checks if the instance is the same as or after a parsable (by unit, see isAfter).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
that |
yuga.Parsable |
unit? |
yuga.Unit | "isoWeek" |
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”isSameOrBefore()
Section titled “isSameOrBefore()”isSameOrBefore(that, unit?): boolean;Checks if the instance is the same as or before a parsable (by unit, see isBefore).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
that |
yuga.Parsable |
unit? |
yuga.Unit | "isoWeek" |
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”isToday()
Section titled “isToday()”isToday(): boolean;Checks if the instance is today, in its time zone (Day.js’s isToday plugin).
Day.js compares with the system’s time zone, yugajs with the instance’s, the same as
isSame(…, "day"). It’s false when invalid.
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”isTomorrow()
Section titled “isTomorrow()”isTomorrow(): boolean;Checks if the instance is tomorrow, in its time zone (Day.js’s isTomorrow plugin).
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”isUTC()
Section titled “isUTC()”isUTC(): boolean;Check if the instance is in UTC (the "UTC" time zone, and its names "Etc/UTC",
"Etc/GMT" and "+00:00").
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”isValid()
Section titled “isValid()”isValid(): boolean;Get the validity of the class, opposite of “Invalid Date” in the JS Date object.
Equivalent to !isNaN(yuga().$e).
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”isYesterday()
Section titled “isYesterday()”isYesterday(): boolean;Checks if the instance is yesterday, in its time zone (Day.js’s isYesterday plugin).
Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”local()
Section titled “local()”local(keepLocalTime?): yuga.Yuga;The same moment in the system’s time zone.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
keepLocalTime? |
boolean |
Keep the wall clock rather than the moment. A yugajs addition, mirroring utc(true) and tz(zone, true). |
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”locale()
Section titled “locale()”Call Signature
Section titled “Call Signature”locale(): string;Get the name of the instance’s locale ("en").
Returns
Section titled “Returns”string
Inherited from
Section titled “Inherited from”Call Signature
Section titled “Call Signature”locale(preset, object?): yuga.Yuga;A clone in another locale, Day.js’s locale. Names are any BCP 47 tag (built out of Intl)
or registered locales, an object registers it under the name. An unknown locale keeps the
current one.
The global locale stays as is, see yuga.locale.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
preset |
string | yuga.Locale |
object? |
yuga.Locale |
Returns
Section titled “Returns”Example
Section titled “Example”yuga("2024-05-15").locale("fr").format("dddd D MMMM"); // "mercredi 15 mai"Inherited from
Section titled “Inherited from”localeData()
Section titled “localeData()”localeData(): yuga.LocaleData;The data of the instance’s locale: names, first day of the week, formats, meridiem and
ordinal. months(instance) and its siblings return the name for that instance.
Available with yugajs/extension/locale-data.
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”milliseconds()
Section titled “milliseconds()”Call Signature
Section titled “Call Signature”milliseconds(): number;An alias of millisecond().
Returns
Section titled “Returns”number
Inherited from
Section titled “Inherited from”Call Signature
Section titled “Call Signature”milliseconds(value): yuga.Yuga;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number |
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”minutes()
Section titled “minutes()”Call Signature
Section titled “Call Signature”minutes(): number;An alias of minute().
Returns
Section titled “Returns”number
Inherited from
Section titled “Inherited from”Call Signature
Section titled “Call Signature”minutes(value): yuga.Yuga;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number |
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”months()
Section titled “months()”Call Signature
Section titled “Call Signature”months(): number;An alias of month().
Returns
Section titled “Returns”number
Inherited from
Section titled “Inherited from”Call Signature
Section titled “Call Signature”months(value): yuga.Yuga;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number |
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”offsetName()
Section titled “offsetName()”offsetName(type?): string;The name of the instance’s time zone at its moment, always in en-US like Day.js: "EDT"
("short", the default) or "Eastern Daylight Time" ("long").
Throws a RangeError when invalid, the same as Day.js. UTC instances are "UTC"
(Day.js gives the system’s name).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
type? |
"short" | "long" |
Returns
Section titled “Returns”string
Inherited from
Section titled “Inherited from”quarters()
Section titled “quarters()”Call Signature
Section titled “Call Signature”quarters(): number;An alias of quarter().
Returns
Section titled “Returns”number
Inherited from
Section titled “Inherited from”Call Signature
Section titled “Call Signature”quarters(value): yuga.Yuga;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number |
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”seconds()
Section titled “seconds()”Call Signature
Section titled “Call Signature”seconds(): number;An alias of second().
Returns
Section titled “Returns”number
Inherited from
Section titled “Inherited from”Call Signature
Section titled “Call Signature”seconds(value): yuga.Yuga;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number |
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”set(uglyUnit, value?): yuga.Yuga;Set the numeric value of the provided unit.
Equivalent to yuga()[unit](value).
In the repeated hour of a DST fall back the instance’s offset is kept when it’s valid for the
new wall clock (set("minute", 0) of the second 01:30 is the second 01:00), the same as
Temporal’s with and Luxon. Other wall clocks the time zone repeats are the earlier offset,
and ones it skips move forward.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
uglyUnit |
yuga.Unit |
The unit of the desired value to set. |
value? |
number |
The new value. |
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”startOf()
Section titled “startOf()”startOf(unit): yuga.Yuga;The start of a unit in the instance’s time zone (startOf("month") is the 1st at 00:00).
"week"starts on theweekStartof the instance’s locale (Sunday foren, Monday foren-gb),"isoWeek"always starts on Monday.- Calendar units are wall-clock midnights, a midnight the time zone skips moves forward.
h,mandsround the wall clock down, Temporal’sroundwith"floor": they keep the instance’s offset when it’s valid (the repeated hour of a DST fall back starts at its own 01:00, the same as Moment.js), and start at the top of the wall-clock hour across a 30-minute offset change (Lord Howe).
Milliseconds, unknown and missing units return the same moment.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
unit |
yuga.Unit | "isoWeek" |
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”subtract()
Section titled “subtract()”subtract(value, unit?): yuga.Yuga;Subtracts an amount of a unit, add with the value negated.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number |
unit? |
yuga.Unit |
Returns
Section titled “Returns”Example
Section titled “Example”yuga("2024-03-31").subtract(1, "M"); // 2024-02-29Inherited from
Section titled “Inherited from”to(date?, withoutSuffix?): string;The time from the instance to a date in words, yuga("2024-01-01").to("2024-01-03") is
"in 2 days".
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
date? |
yuga.Parsable |
withoutSuffix? |
boolean |
Returns
Section titled “Returns”string
Inherited from
Section titled “Inherited from”toArray()
Section titled “toArray()”toArray(): [number, number, number, number, number, number, number];[year, month, date, hour, minute, second, millisecond] in the instance’s time zone, the
month is 0-based (Day.js’s toArray plugin).
Returns
Section titled “Returns”[number, number, number, number, number, number, number]
Inherited from
Section titled “Inherited from”toDate()
Section titled “toDate()”toDate(): Date;Formats to a Date class equivalent value of the class.
Returns
Section titled “Returns”Date
Inherited from
Section titled “Inherited from”toInstant()
Section titled “toInstant()”toInstant(): Instant;The Temporal.Instant of the instance, throws a RangeError when invalid.
Returns
Section titled “Returns”Instant
Inherited from
Section titled “Inherited from”toISOString()
Section titled “toISOString()”toISOString(keepOffset?): string;Formats to an ISO 8601 string in UTC with milliseconds ("2024-05-15T10:00:00.000Z"), or at
the instance’s own offset with keepOffset ("2024-05-15T12:00:00.000+02:00", Moment.js’s
toISOString(true)).
Equivalent to yuga().toDate().toISOString(), throws a RangeError when invalid. For
the time zone too, RFC 9557’s "2024-05-15T12:00:00+02:00[Europe/Paris]", use
toTemporal().toString(): yuga() parses it back to the same instance.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
keepOffset? |
boolean |
Returns
Section titled “Returns”string
Inherited from
Section titled “Inherited from”toJSON()
Section titled “toJSON()”toJSON(): string | null;Serializes to the ISO 8601 string, or null when invalid (used by JSON.stringify).
Returns
Section titled “Returns”string | null
Inherited from
Section titled “Inherited from”toNow()
Section titled “toNow()”toNow(withoutSuffix?): string;The time from the instance to now in words ("in 2 hours" for an instance in the past).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
withoutSuffix? |
boolean |
Returns
Section titled “Returns”string
Inherited from
Section titled “Inherited from”toObject()
Section titled “toObject()”toObject(): object;The date and time fields in the instance’s time zone, the month is 0-based (Day.js’s
toObject plugin).
Returns
Section titled “Returns”object
| Name | Type |
|---|---|
date |
number |
hours |
number |
milliseconds |
number |
minutes |
number |
months |
number |
seconds |
number |
years |
number |
Inherited from
Section titled “Inherited from”toPlainDate()
Section titled “toPlainDate()”toPlainDate(): PlainDate;The Temporal.PlainDate of the instance’s date in its time zone, throws a RangeError when
invalid.
Returns
Section titled “Returns”PlainDate
Inherited from
Section titled “Inherited from”toString()
Section titled “toString()”toString(): string;Formats to a string in the instance’s time zone ("Wed May 15 2024 06:00:00 GMT-0400 (Eastern Daylight Time)"), “Invalid Date” when invalid.
Equivalent to yuga().toDate().toString() in the system’s time zone. Day.js returns
the UTC string instead, see toUTCString.
Returns
Section titled “Returns”string
Inherited from
Section titled “Inherited from”toTemporal()
Section titled “toTemporal()”toTemporal(): ZonedDateTime;The Temporal.ZonedDateTime of the instance (its time zone, the system’s when it has none).
The same object as $T, built once. Throws a RangeError when invalid.
Returns
Section titled “Returns”ZonedDateTime
Inherited from
Section titled “Inherited from”toUTCString()
Section titled “toUTCString()”toUTCString(): string;Formats to a UTC string ("Wed, 15 May 2024 10:00:00 GMT"), “Invalid Date” when invalid.
Equivalent to yuga().toDate().toUTCString() and Day.js’s toString().
Returns
Section titled “Returns”string
Inherited from
Section titled “Inherited from”Call Signature
Section titled “Call Signature”tz(): string;Get the IANA time zone of the instance (the system’s when it has none of its own).
Returns
Section titled “Returns”string
Inherited from
Section titled “Inherited from”Call Signature
Section titled “Call Signature”tz(zone, keepLocalTime?): yuga.Yuga;The same moment in another time zone (an IANA name, or an offset such as "+05:30").
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
zone |
string |
- |
keepLocalTime? |
boolean |
Keep the wall clock rather than the moment (10:00 in New York becomes 10:00 in Tokyo). |
Returns
Section titled “Returns”Example
Section titled “Example”yuga("2024-05-15T10:00:00Z").tz("Asia/Tokyo").hour(); // 19Throws
Section titled “Throws”When the time zone is unknown.
Inherited from
Section titled “Inherited from”unix()
Section titled “unix()”unix(): number;Get the number of seconds since the Unix Epoch, floored.
Equivalent to Math.floor(yuga().valueOf() / 1000).
Returns
Section titled “Returns”number
Inherited from
Section titled “Inherited from”utc(keepLocalTime?): yuga.Yuga;The same moment in UTC, tz("UTC").
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
keepLocalTime? |
boolean |
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”utcOffset()
Section titled “utcOffset()”Call Signature
Section titled “Call Signature”utcOffset(): number;Get the offset from UTC in minutes, rounded to 15 minutes like Day.js (-240 for New York in
summer).
NaN when invalid.
Returns
Section titled “Returns”number
Inherited from
Section titled “Inherited from”Call Signature
Section titled “Call Signature”utcOffset(offset, keepLocalTime?): yuga.Yuga;The same moment in a fixed offset from UTC, DST doesn’t apply to it.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
offset |
string | number |
Minutes (-240), hours when 16 or less in absolute value (-4), or a string ("-04:00", "+0530", an unparsable one returns the same instance). 0 is utc(). |
keepLocalTime? |
boolean |
Keep the wall clock rather than the moment. |
Returns
Section titled “Returns”Example
Section titled “Example”yuga("2024-05-15T10:00:00Z").utcOffset(-240).format(); // "2024-05-15T06:00:00-04:00"Inherited from
Section titled “Inherited from”valueOf()
Section titled “valueOf()”valueOf(): number;Get the number of milliseconds since the Unix Epoch of the Yuga class.
Equivalent to yuga().toDate().valueOf(), NaN when invalid.
Returns
Section titled “Returns”number
Inherited from
Section titled “Inherited from”weekday()
Section titled “weekday()”Call Signature
Section titled “Call Signature”weekday(): number;The day of the week by the locale’s weekStart, 0 is the first day of the locale’s week
(Sunday in en, Monday in en-gb). The setter moves within the week the same as
day(n).
Returns
Section titled “Returns”number
Inherited from
Section titled “Inherited from”Call Signature
Section titled “Call Signature”weekday(value): yuga.Yuga;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number |
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”weeks()
Section titled “weeks()”Call Signature
Section titled “Call Signature”weeks(): number;An alias of week().
Returns
Section titled “Returns”number
Inherited from
Section titled “Inherited from”Call Signature
Section titled “Call Signature”weeks(value): yuga.Yuga;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number |
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”weekYear()
Section titled “weekYear()”weekYear(): number;The year the week belongs to by the locale’s weekStart and yearStart.
Returns
Section titled “Returns”number
Inherited from
Section titled “Inherited from”years()
Section titled “years()”Call Signature
Section titled “Call Signature”years(): number;An alias of year().
Returns
Section titled “Returns”number
Inherited from
Section titled “Inherited from”Call Signature
Section titled “Call Signature”years(value): yuga.Yuga;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number |
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”create()
Section titled “create()”static create( epoch, zone, localeName?, temporal?): yuga.Yuga;Creates an instance straight from epoch milliseconds (NaN for invalid) in a time zone
(undefined for the system’s), skipping parsing. This is how every method that returns a new
instance creates it.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
epoch |
number |
- |
zone |
string | undefined |
- |
localeName? |
string |
The name of a registered locale, the global locale by default. |
temporal? |
ZonedDateTime | null |
The zoned date time of the same epoch and time zone if one was already built, it becomes the $T cache. |
Returns
Section titled “Returns”Internals
Section titled “Internals”readonly $e: number;Milliseconds since the Unix Epoch, NaN when invalid. Along with $z it is the whole state of
the instance, the unit fields below are derived from both by yuga.$.cascade.
Inherited from
Section titled “Inherited from”$isYugaClass
Section titled “$isYugaClass”readonly $isYugaClass: true;Inherited from
Section titled “Inherited from”readonly $l: string;The name of the instance’s locale ("en"), the global locale when it was created.
Inherited from
Section titled “Inherited from”readonly $z: string | undefined;The IANA time zone of the instance, undefined is the system’s (which Date follows).
Inherited from
Section titled “Inherited from”Get Signature
Section titled “Get Signature”get $T(): ZonedDateTime | null;The zoned date time of the instance, null when invalid.
Built on first access and cached, the hot paths (parsing, getters, comparisons and most setters in the system’s time zone or UTC) don’t need it.
Returns
Section titled “Returns”ZonedDateTime | null
Inherited from
Section titled “Inherited from”Get Signature
Section titled “Get Signature”get $v(): boolean;Returns
Section titled “Returns”boolean
Inherited from
Section titled “Inherited from”Interfaces
Section titled “Interfaces”yuga.Config
Section titled “yuga.Config”Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
format? |
string | readonly string[] |
The format of a string parsable ("DD/MM/YYYY HH:mm"), or a list of formats where the first that parses wins. Needs yugajs/extension/custom-parse-format, strings with a format are invalid without it (see yuga.$.parseFormatted). |
locale? |
string | yuga.Locale |
The locale of the instance, a name or an object to register (see yuga.locale). The global locale by default, or the locale of a parsed instance. |
parsable? |
yuga.Parsable |
- |
strict? |
boolean |
Strict format parsing, a string that doesn’t format back to itself is invalid (see format). |
utc? |
boolean |
Use the "UTC" time zone instead of the system’s, parsables that have a time zone of their own (Yuga instances, Temporal.ZonedDateTime) keep it. |
zone? |
string |
The time zone of the instance (an IANA name, or an offset such as "+05:30"), it takes precedence over utc and the time zone of the parsable. Wall-clock values are read in it. |
yuga.DiffOptions
Section titled “yuga.DiffOptions”The options of diff, a boolean is the same as { float } (Day.js’s third argument).
Properties
Section titled “Properties”yuga.Duration
Section titled “yuga.Duration”An amount of time, immutable. Lengths are fixed (a week is 7 days, a year 365 days and a month 365 / 12 days), the same as Day.js.
Methods
Section titled “Methods”add(value, unit?): yuga.Duration;A new duration with a value added (a number of the unit, an object, a string or a duration), balanced like a number.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
yuga.DurationInput |
unit? |
yuga.Unit |
Returns
Section titled “Returns”as(unit): number;The whole duration in a unit (duration(90, "minutes").as("hours") is 1.5).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
unit |
yuga.Unit |
Returns
Section titled “Returns”number
asDays()
Section titled “asDays()”asDays(): number;Returns
Section titled “Returns”number
asHours()
Section titled “asHours()”asHours(): number;Returns
Section titled “Returns”number
asMilliseconds()
Section titled “asMilliseconds()”asMilliseconds(): number;Returns
Section titled “Returns”number
asMinutes()
Section titled “asMinutes()”asMinutes(): number;Returns
Section titled “Returns”number
asMonths()
Section titled “asMonths()”asMonths(): number;Returns
Section titled “Returns”number
asSeconds()
Section titled “asSeconds()”asSeconds(): number;Returns
Section titled “Returns”number
asWeeks()
Section titled “asWeeks()”asWeeks(): number;Returns
Section titled “Returns”number
asYears()
Section titled “asYears()”asYears(): number;Returns
Section titled “Returns”number
clone()
Section titled “clone()”clone(): yuga.Duration;Returns
Section titled “Returns”days()
Section titled “days()”days(): number;Returns
Section titled “Returns”number
format()
Section titled “format()”format(template?): string;The duration with tokens Y YY YYYY M MM D DD H HH m mm s ss SSS and [escaped text],
"YYYY-MM-DDTHH:mm:ss" by default.
A part the duration doesn’t have is 0 (Day.js prints “undefined”).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
template? |
string |
Returns
Section titled “Returns”string
get(unit): number;A part of the duration: milliseconds is the total modulo 1000, weeks the total divided
by 7 days (truncated), others are the part (balanced for a number, as given for an
object).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
unit |
yuga.Unit |
Returns
Section titled “Returns”number
hours()
Section titled “hours()”hours(): number;Returns
Section titled “Returns”number
humanize()
Section titled “humanize()”humanize(withSuffix?): string;The duration in words ("2 hours", "in 2 hours"), Day.js’s humanize with the
thresholds of relativeTime.
Months and years use the fixed lengths, Day.js measures them from today.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
withSuffix? |
boolean |
Add the “in” / “ago” ("in 2 hours", "2 hours ago" when negative). |
Returns
Section titled “Returns”string
locale()
Section titled “locale()”Call Signature
Section titled “Call Signature”locale(): string;The locale name of the duration (humanize uses it), the global locale when it was
created.
Returns
Section titled “Returns”string
Call Signature
Section titled “Call Signature”locale(preset): yuga.Duration;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
preset |
string | yuga.Locale |
Returns
Section titled “Returns”milliseconds()
Section titled “milliseconds()”milliseconds(): number;Returns
Section titled “Returns”number
minutes()
Section titled “minutes()”minutes(): number;Returns
Section titled “Returns”number
months()
Section titled “months()”months(): number;Returns
Section titled “Returns”number
seconds()
Section titled “seconds()”seconds(): number;Returns
Section titled “Returns”number
subtract()
Section titled “subtract()”subtract(value, unit?): yuga.Duration;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
yuga.DurationInput |
unit? |
yuga.Unit |
Returns
Section titled “Returns”toISOString()
Section titled “toISOString()”toISOString(): string;ISO 8601 ("P1DT2H"), weeks become days, "P0D" when empty.
Returns
Section titled “Returns”string
toJSON()
Section titled “toJSON()”toJSON(): string;Returns
Section titled “Returns”string
toTemporal()
Section titled “toTemporal()”toTemporal(): Duration;A Temporal.Duration with the same parts. A number’s balanced parts are all of the same
sign.
Temporal needs whole years, months, weeks and days (a RangeError otherwise, as it
is for parts of different signs, an invalid duration is empty); fractions of hours, minutes
and seconds go to the smaller parts.
Returns
Section titled “Returns”Duration
valueOf()
Section titled “valueOf()”valueOf(): number;The milliseconds, so durations compare and subtract.
Returns
Section titled “Returns”number
weeks()
Section titled “weeks()”weeks(): number;Returns
Section titled “Returns”number
years()
Section titled “years()”years(): number;Returns
Section titled “Returns”number
yuga.ExpandableParsable
Section titled “yuga.ExpandableParsable”Every value yuga() can parse, see yuga.$.parse for how each is read.
Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
array |
readonly number[] |
The wall-clock values [year, month, date, hour, minute, second, millisecond], the same order as the Date constructor’s arguments (the month is 0-indexed), read in the instance’s time zone. Missing values are the start ([2024, 4] is May 1st), [] is now. Available with yugajs/extension/array-support. |
bigInt |
bigint |
Epoch milliseconds as a BigInt (yuga(1715767200000n)), out of range is invalid. Available with yugajs/extension/big-int-support. |
dateClass |
Date |
- |
dateString |
string |
Can be used to parse custom strings. |
instant |
Instant |
- |
itself |
yuga.Yuga |
- |
null |
null |
Returns yuga representation of an Invalid Date equivalent to yuga(new Date(NaN)). Backport from moment, moment sees it as parsing an invalid moment object. TODO: Should this even be allowed? should it be Invalid? |
object |
yuga.UnitValues |
A plain object of values by unit ({ year: 2024, month: 4, date: 15, hour: 10 }), read in the instance’s time zone. Missing parts are the start, except that the ones above the greatest unit given are the current ones ({ hour: 10 } is today at 10:00). {} is now. Available with yugajs/extension/object-support. |
plainDate |
PlainDate |
A wall-clock date at midnight, read in the instance’s time zone. Available with yugajs/extension/plain-date-support. |
plainDateTime |
PlainDateTime |
A wall-clock date and time, read in the instance’s time zone. Available with yugajs/extension/plain-date-support. |
timestamp |
number |
- |
undefined |
undefined |
Returns yuga representation of now equivalent to yuga(new Date()). |
zonedDateTime |
ZonedDateTime |
- |
yuga.Factory()
Section titled “yuga.Factory()”Call Signature
Section titled “Call Signature”Factory(parsable?): yuga.Yuga;Create an instance, now by default (see Parsable). Strings without a format are ISO 8601
and Day.js’s loose YYYY-MM-DD HH:mm:ss.SSS in the system’s time zone.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
parsable? |
yuga.Parsable |
Returns
Section titled “Returns”Example
Section titled “Example”yuga("2024-05-15 10:20");Call Signature
Section titled “Call Signature”Factory( parsable, format, locale?, strict?): yuga.Yuga;Create an instance from a string in a format (Day.js’s customParseFormat), and optionally
in a locale (for the names of months and weekdays, and the instance’s locale).
Needs yugajs/extension/custom-parse-format (yuga.extend(customParseFormat)), strings with
a format are invalid without it.
Tokens: Y YYYY YY M MM MMM MMMM D DD Do d dd ddd dddd w ww H HH h hh m mm s ss S SS SSS A a Q Z ZZ X x, text in brackets is literal. Missing fields default the same as Day.js (the
current year, the 1st of the month, midnight), strings that don’t match are invalid, and so
are unknown weekday and month names.
A list of formats tries each in order and keeps the first valid result. Strict parsing
(true as the last argument) makes strings that don’t format back to themselves invalid:
overflowing values ("2024-02-30") and weekdays that don’t match the date.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
parsable |
yuga.Parsable |
format |
string | readonly string[] |
locale? |
string | yuga.Locale |
strict? |
boolean |
Returns
Section titled “Returns”Examples
Section titled “Examples”yuga("15/05/2024", "DD/MM/YYYY");yuga("15 mai 2024", "D MMMM YYYY", "fr");yuga("2024-02-30", "YYYY-MM-DD", true).isValid(); // falseyuga("2024-05-15", ["DD/MM/YYYY", "YYYY-MM-DD"]);Call Signature
Section titled “Call Signature”Factory( parsable, format, strict): yuga.Yuga;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
parsable |
yuga.Parsable |
format |
string | readonly string[] |
strict |
boolean |
Returns
Section titled “Returns”Call Signature
Section titled “Call Signature”Factory(parsable, options): yuga.Yuga;Create an instance with options, Day.js’s dayjs(date, { utc, locale }).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
parsable |
yuga.Parsable |
options |
yuga.Options |
Returns
Section titled “Returns”Examples
Section titled “Examples”yuga("2024-05-15 10:20", { utc: true });yuga("2024-05-15", { locale: "es" });Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
en |
yuga.Locale |
The built-in English locale (Day.js’s en). |
locales |
Record<string, yuga.Locale> |
Every registered locale, keyed by name (built-in en, and every locale resolved so far). |
Ls |
Record<string, yuga.Locale> |
Day.js’s name of locales. |
tz |
{ (parsable, zone?): yuga.Yuga; (parsable, format, zone): yuga.Yuga; guess(): string; setDefault(zone?): void; } |
Create an instance in a time zone (Day.js’s dayjs.tz): wall-clock values (strings without an offset, plain Temporal values) are read in it, moments (numbers, dates, instants, strings with an offset) keep their moment. Example yuga.tz("2024-05-15 10:20", "Asia/Tokyo").toISOString(); // "2024-05-15T01:20:00.000Z" Throws When the time zone is unknown. |
tz.guess |
() => string |
The system’s time zone id ("America/New_York"). |
tz.setDefault |
(zone?) => void |
The time zone of new instances that don’t set one (undefined resets to the system’s). A zone is kept even when it is the system’s, it doesn’t follow runtime changes to TZ. Throws When the time zone is unknown. |
Methods
Section titled “Methods”duration()
Section titled “duration()”duration(value?, unit?): yuga.Duration;A duration of a number of a unit (milliseconds by default), an object, an ISO 8601 string,
a Temporal.Duration or another duration, Day.js’s duration plugin.
A number is balanced into parts (duration(90, "minutes") is 1 hour 30 minutes), an object
or string keeps its parts as given (duration({ minutes: 90 }).minutes() is 90).
Passing a duration is a yugajs addition (Day.js gives NaN).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value? |
yuga.DurationInput |
unit? |
yuga.Unit |
Returns
Section titled “Returns”Example
Section titled “Example”yuga.duration({ hours: 1, minutes: 30 }).asMinutes(); // 90extend()
Section titled “extend()”extend<T>(extension, ...args): void;Extend an extension into the yuga class.
Type Parameters
Section titled “Type Parameters”| Type Parameter | Default type |
|---|---|
T |
never |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
extension |
yuga.Extension<T> |
…args |
[T] extends [never] ? [] : [T] extends [undefined] ? [] : undefined extends T ? [config?: T] : [config: T] |
Returns
Section titled “Returns”void
isDuration()
Section titled “isDuration()”isDuration(value): value is yuga.Duration;Whether a value is a duration.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
unknown |
Returns
Section titled “Returns”value is yuga.Duration
isYuga()
Section titled “isYuga()”isYuga(that): that is yuga.Yuga;Check if a value is an Yuga class.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
that |
unknown |
Returns
Section titled “Returns”that is yuga.Yuga
locale()
Section titled “locale()”Call Signature
Section titled “Call Signature”locale(): string;Get the global locale’s name ("en").
Returns
Section titled “Returns”string
Call Signature
Section titled “Call Signature”locale(preset, object?): string;Set the global locale (the one new instances use) and return its name. Names are any BCP 47
tag (built out of Intl, lowercased: "en-GB" is "en-gb") or registered locales, a name
with an object registers the object (overriding Intl), and a locale object registers it
under its own name. Unknown locales keep the global one.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
preset |
string | yuga.Locale |
object? |
yuga.Locale |
Returns
Section titled “Returns”string
Call Signature
Section titled “Call Signature”locale( preset, object, isLocal): string | undefined;Resolve (and register) a locale without setting the global one, its name or undefined when
unknown.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
preset |
string | yuga.Locale |
object |
yuga.Locale | undefined |
isLocal |
true |
Returns
Section titled “Returns”string | undefined
localeData()
Section titled “localeData()”localeData(): yuga.LocaleData;The data of the global locale (Day.js’s localeData). Its months() and siblings ignore
an instance and return the list of names.
Returns
Section titled “Returns”Call Signature
Section titled “Call Signature”max(...instances): yuga.Yuga | null;The latest of the instances (or parsables), the same object that was passed in (the first
one on ties). null with no input, and an invalid instance as soon as one input is
invalid.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
…instances |
yuga.Parsable[] |
Returns
Section titled “Returns”yuga.Yuga | null
Call Signature
Section titled “Call Signature”max(instances): yuga.Yuga | null;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
instances |
yuga.Parsable[] |
Returns
Section titled “Returns”yuga.Yuga | null
median()
Section titled “median()”Call Signature
Section titled “Call Signature”median(...instances): yuga.Yuga | null;The middle instance by time, the same object that was passed in. With an even count it’s
the earlier of the two middle ones (so it’s always one of the inputs), and the first one on
ties (equal instances keep their input order, so the middle one of three equal inputs is
the second). null with no input, and an invalid instance as soon as one input is
invalid.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
…instances |
yuga.Parsable[] |
Returns
Section titled “Returns”yuga.Yuga | null
Call Signature
Section titled “Call Signature”median(instances): yuga.Yuga | null;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
instances |
yuga.Parsable[] |
Returns
Section titled “Returns”yuga.Yuga | null
Call Signature
Section titled “Call Signature”min(...instances): yuga.Yuga | null;The earliest of the instances (or parsables), the same object that was passed in (the first
one on ties). null with no input, and an invalid instance as soon as one input is
invalid.
Parsables are a yugajs addition, Day.js’s minMax throws on non-instances.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
…instances |
yuga.Parsable[] |
Returns
Section titled “Returns”yuga.Yuga | null
Call Signature
Section titled “Call Signature”min(instances): yuga.Yuga | null;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
instances |
yuga.Parsable[] |
Returns
Section titled “Returns”yuga.Yuga | null
months()
Section titled “months()”months(): string[];The month names of the global locale, January first.
Returns
Section titled “Returns”string[]
monthsShort()
Section titled “monthsShort()”monthsShort(): string[];The short month names of the global locale.
Returns
Section titled “Returns”string[]
plug()
Section titled “plug()”plug<T>(extension, ...args): void;Plug a plugin into the yuga factory.
Type Parameters
Section titled “Type Parameters”| Type Parameter | Default type |
|---|---|
T |
never |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
extension |
yuga.Plugin<T> |
…args |
[T] extends [never] ? [] : [T] extends [undefined] ? [] : [config: T] |
Returns
Section titled “Returns”void
unix()
Section titled “unix()”unix(value): yuga.Yuga;Create a Yuga object from a Unix timestamp, 10 digits, seconds since the Unix Epoch.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number | bigint |
Returns
Section titled “Returns”updateLocale()
Section titled “updateLocale()”updateLocale(name, partial): yuga.Locale | undefined;Merges a partial locale into a loaded locale (a locale already used, registered, or en),
so instances in it (new or existing) see the change, and returns it. Does nothing (and
returns undefined) for a locale that isn’t loaded, the same as Day.js.
Objects (formats) are merged, anything else is replaced. Names of Intl locales are
replaced too, with plain properties.
yuga.updateLocale("en", { months: ["Jan.", "Feb.", …] });Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
name |
string |
partial |
Partial<yuga.Locale> |
Returns
Section titled “Returns”yuga.Locale | undefined
utc( parsable?, format?, locale?, strict?): yuga.Yuga;Create an instance in UTC, the same as yuga(parsable, format, locale, strict) with utc: true (Day.js’s dayjs.utc). A format needs yugajs/extension/custom-parse-format.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
parsable? |
yuga.Parsable |
format? |
string |
locale? |
string | boolean | yuga.Locale |
strict? |
boolean |
Returns
Section titled “Returns”weekdays()
Section titled “weekdays()”weekdays(localeOrder?): string[];The weekday names of the global locale, Sunday first, or starting on the locale’s first day
of the week with localeOrder.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
localeOrder? |
boolean |
Returns
Section titled “Returns”string[]
weekdaysMin()
Section titled “weekdaysMin()”weekdaysMin(localeOrder?): string[];The minimal weekday names of the global locale (see weekdays).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
localeOrder? |
boolean |
Returns
Section titled “Returns”string[]
weekdaysShort()
Section titled “weekdaysShort()”weekdaysShort(localeOrder?): string[];The short weekday names of the global locale (see weekdays).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
localeOrder? |
boolean |
Returns
Section titled “Returns”string[]
Internals
Section titled “Internals”| Property | Type |
|---|---|
$ |
yuga.Utils |
yuga.LocaleData
Section titled “yuga.LocaleData”A locale’s data, Day.js’s localeData object.
Methods
Section titled “Methods”firstDayOfWeek()
Section titled “firstDayOfWeek()”firstDayOfWeek(): number;The first day of the week, 0 is Sunday.
Returns
Section titled “Returns”number
longDateFormat()
Section titled “longDateFormat()”longDateFormat(token): string | undefined;The template of a localized format ("LT", "LTS", "L", "LL", "LLL", "LLLL", and
their short forms), undefined for any other token.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
token |
string |
Returns
Section titled “Returns”string | undefined
meridiem()
Section titled “meridiem()”meridiem( hour, minute, isLowercase): string;The meridiem of an hour ("AM" / "PM" by default).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
hour |
number |
minute |
number |
isLowercase |
boolean |
Returns
Section titled “Returns”string
months()
Section titled “months()”Call Signature
Section titled “Call Signature”months(): string[];The month names, January first. With an instance, that instance’s month name (MMMM).
Returns
Section titled “Returns”string[]
Call Signature
Section titled “Call Signature”months(instance): string;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
instance |
yuga.Yuga |
Returns
Section titled “Returns”string
monthsShort()
Section titled “monthsShort()”Call Signature
Section titled “Call Signature”monthsShort(): string[];The short month names. With an instance, that instance’s short month name (MMM).
Returns
Section titled “Returns”string[]
Call Signature
Section titled “Call Signature”monthsShort(instance): string;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
instance |
yuga.Yuga |
Returns
Section titled “Returns”string
ordinal()
Section titled “ordinal()”ordinal(number, token?): string | number;The ordinal of a number ("1st" in English).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
number |
number |
token? |
string |
Returns
Section titled “Returns”string | number
weekdays()
Section titled “weekdays()”Call Signature
Section titled “Call Signature”weekdays(): string[];The weekday names, Sunday first. With an instance, that instance’s weekday name (dddd).
Returns
Section titled “Returns”string[]
Call Signature
Section titled “Call Signature”weekdays(instance): string;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
instance |
yuga.Yuga |
Returns
Section titled “Returns”string
weekdaysMin()
Section titled “weekdaysMin()”Call Signature
Section titled “Call Signature”weekdaysMin(): string[];The minimal weekday names. With an instance, that instance’s minimal weekday name (dd).
Returns
Section titled “Returns”string[]
Call Signature
Section titled “Call Signature”weekdaysMin(instance): string;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
instance |
yuga.Yuga |
Returns
Section titled “Returns”string
weekdaysShort()
Section titled “weekdaysShort()”Call Signature
Section titled “Call Signature”weekdaysShort(): string[];The short weekday names. With an instance, that instance’s short weekday name (ddd).
Returns
Section titled “Returns”string[]
Call Signature
Section titled “Call Signature”weekdaysShort(instance): string;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
instance |
yuga.Yuga |
Returns
Section titled “Returns”string
yuga.Unit.Map
Section titled “yuga.Unit.Map”Properties
Section titled “Properties”| Property | Type |
|---|---|
d |
"day" |
D |
"date" |
h |
"hour" |
m |
"minute" |
M |
"month" |
ms |
"millisecond" |
q |
"quarter" |
s |
"second" |
w |
"week" |
y |
"year" |
yuga.Yuga
Section titled “yuga.Yuga”Extends
Section titled “Extends”Extended by
Section titled “Extended by”Properties
Section titled “Properties”| Property | Type | Inherited from |
|---|---|---|
d |
number |
yuga.Fields.d |
D |
number |
yuga.Fields.D |
h |
number |
yuga.Fields.h |
m |
number |
yuga.Fields.m |
M |
number |
yuga.Fields.M |
ms |
number |
yuga.Fields.ms |
q |
number |
yuga.Fields.q |
s |
number |
yuga.Fields.s |
w |
number |
yuga.Fields.w |
y |
number |
yuga.Fields.y |
Methods
Section titled “Methods”Call Signature
Section titled “Call Signature”add(value, unit?): yuga.Yuga;Adds an amount of a unit (milliseconds by default), Day.js’s add.
y,QandMmove the wall clock and clamp the date to the end of the month (Jan 31 + 1 month is Feb 29 in 2024), fractions are truncated.wandd(orD) move the wall clock by whole days (fractions are rounded), keeping the time of day across DST.h,m,sandmsare absolute time (an hour across DST is 60 minutes later).
Units are case-insensitive. Lowercase q is a quarter (Day.js adds milliseconds).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number |
unit? |
yuga.Unit |
Returns
Section titled “Returns”Example
Section titled “Example”yuga("2024-01-31").add(1, "month"); // 2024-02-29Call Signature
Section titled “Call Signature”add(value, unit?): yuga.Yuga;Adds several units in the order of the object’s keys ({ months: 1, days: 1 } and { days: 1, months: 1 } differ on January 30th).
Available with yugajs/extension/object-support.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
| number | Partial<Record<yuga.Unit, number>> |
unit? |
yuga.Unit |
Returns
Section titled “Returns”Call Signature
Section titled “Call Signature”add(duration): yuga.Yuga;Adds a duration: years and months, then weeks and days, then the time, the same as adding each part.
Day.js drops a duration’s weeks, yugajs adds them.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
duration |
number | yuga.Duration |
Returns
Section titled “Returns”calendar()
Section titled “calendar()”calendar(referenceTime?, formats?): string;The instance in calendar words relative to a reference time ("Today at 10:20 AM", "Last Monday at 9:00 AM", "05/15/2024"), Day.js’s calendar plugin. The bucket is the day
difference from the start of the reference’s day, in the instance’s time zone.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
referenceTime? |
yuga.Parsable |
What to compare with, now by default. |
formats? |
CalendarFormats |
The format of each bucket, a template or a function; they win over the locale’s. |
Returns
Section titled “Returns”string
clone()
Section titled “clone()”clone(): yuga.Yuga;Creates a clone of the current Yuga class.
Yuga doesn’t support mutability, this function is ported from Moment.js & Day.js.
While Day.js does default to immutability, plugins such as badMutable allow it, Yuga
does not provide such plugins.
Returns
Section titled “Returns”date()
Section titled “date()”Call Signature
Section titled “Call Signature”date(): number;Returns
Section titled “Returns”number
Call Signature
Section titled “Call Signature”date(value): yuga.Yuga;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number |
Returns
Section titled “Returns”dates()
Section titled “dates()”Call Signature
Section titled “Call Signature”dates(): number;An alias of date(), the day of the month.
Returns
Section titled “Returns”number
Call Signature
Section titled “Call Signature”dates(value): yuga.Yuga;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number |
Returns
Section titled “Returns”Call Signature
Section titled “Call Signature”day(): number;Returns
Section titled “Returns”number
Call Signature
Section titled “Call Signature”day(value): yuga.Yuga;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number |
Returns
Section titled “Returns”dayOfYear()
Section titled “dayOfYear()”Call Signature
Section titled “Call Signature”dayOfYear(): number;The day of the year in the instance’s time zone, 1 to 366 (Day.js’s dayOfYear plugin).
The setter moves to that day of the year, the same as add(n - dayOfYear(), "day").
Returns
Section titled “Returns”number
Call Signature
Section titled “Call Signature”dayOfYear(value): yuga.Yuga;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number |
Returns
Section titled “Returns”days()
Section titled “days()”Call Signature
Section titled “Call Signature”days(): number;An alias of day(), the day of the week.
Returns
Section titled “Returns”number
Call Signature
Section titled “Call Signature”days(value): yuga.Yuga;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number |
Returns
Section titled “Returns”daysInMonth()
Section titled “daysInMonth()”daysInMonth(): number;Get the number of days in the current month.
NaN when invalid.
Returns
Section titled “Returns”number
diff()
Section titled “diff()”diff( that?, unit?, options?): number;The difference from a parsable (now when omitted) to the instance in a unit, milliseconds by
default. NaN when either is invalid (for every unit, Day.js gives 0 for months).
By default it matches Day.js: months, quarters and years use Moment.js’s month difference
(2024-05-15 to 2024-01-31 is 3.48 months), days and weeks discount the change of the UTC
offset, and the result is truncated toward zero.
The parsable is compared in the instance’s time zone, the same as Moment.js.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
that? |
yuga.Parsable |
- |
unit? |
yuga.Unit |
- |
options? |
boolean | yuga.DiffOptions |
true keeps the fraction (Day.js’s float), see DiffOptions. |
Returns
Section titled “Returns”number
Example
Section titled “Example”yuga("2024-05-15").diff("2024-01-31", "month", true); // 3.48…endOf()
Section titled “endOf()”endOf(unit): yuga.Yuga;The end of a unit, the start of the next one minus 1 ms (endOf("day") is 23:59:59.999).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
unit |
yuga.Unit | "isoWeek" |
Returns
Section titled “Returns”startOf
format()
Section titled “format()”format(template?): string;Formats with a template, Day.js’s format and its advancedFormat tokens, in the instance’s
locale. Text in brackets is escaped ("[Today is] dddd").
YY YYYY M MM MMM MMMM D DD Do d dd ddd dddd H HH h hh a A m mm s ss SSS Z ZZ Qw wwthe week of the locale (itsweekStartandyearStart),W WWthe ISO week.
With no template it is ISO 8601 with the offset ("2024-05-15T06:00:00-04:00", and
"…Z" in UTC), invalid instances are the locale’s invalidDate ("Invalid Date").
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
template? |
string |
Returns
Section titled “Returns”string
Example
Section titled “Example”yuga("2024-05-15").format("dddd, MMMM Do YYYY"); // "Wednesday, May 15th 2024"from()
Section titled “from()”from(date?, withoutSuffix?): string;The time from a date to the instance in words, yuga("2024-01-01").from("2024-01-03") is
"2 days ago".
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
date? |
yuga.Parsable |
withoutSuffix? |
boolean |
Returns
Section titled “Returns”string
fromNow()
Section titled “fromNow()”fromNow(withoutSuffix?): string;The time from now to the instance in words ("2 hours ago", "in a day"), Day.js’s
relativeTime plugin. Past is “ago”, future is “in”.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
withoutSuffix? |
boolean |
Drop the “ago” / “in” ("2 hours"). |
Returns
Section titled “Returns”string
Call Signature
Section titled “Call Signature”get(): string;Get the string value of the class.
Equivalent to yuga().toString()
Returns
Section titled “Returns”string
Call Signature
Section titled “Call Signature”get(unit): number;Get the numeric value of the provided unit.
Equivalent to yuga()unit.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
unit |
yuga.Unit |
The unit of the desired value to get. |
Returns
Section titled “Returns”number
hour()
Section titled “hour()”Call Signature
Section titled “Call Signature”hour(): number;Returns
Section titled “Returns”number
Call Signature
Section titled “Call Signature”hour(value): yuga.Yuga;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number |
Returns
Section titled “Returns”hours()
Section titled “hours()”Call Signature
Section titled “Call Signature”hours(): number;An alias of hour().
Returns
Section titled “Returns”number
Call Signature
Section titled “Call Signature”hours(value): yuga.Yuga;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number |
Returns
Section titled “Returns”isAfter()
Section titled “isAfter()”isAfter(that, unit?): boolean;Checks if the instance is after a parsable, with a unit: if the parsable is before the start of the instance’s unit.
The unit is in the instance’s time zone and locale (see startOf).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
that |
yuga.Parsable |
unit? |
yuga.Unit | "isoWeek" |
Returns
Section titled “Returns”boolean
isBefore()
Section titled “isBefore()”isBefore(that, unit?): boolean;Checks if the instance is before a parsable, with a unit: if the end of the instance’s unit
is before it (isBefore(x, "day") is true when x is on a later day).
The unit is in the instance’s time zone and locale (see startOf).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
that |
yuga.Parsable |
unit? |
yuga.Unit | "isoWeek" |
Returns
Section titled “Returns”boolean
isBetween()
Section titled “isBetween()”isBetween( a, b, unit?, inclusivity?): boolean;Checks if the instance is between two parsables, given in either order. Exclusive by
default ("()"), "[" and "]" include the lower and upper bound ("[]", "[)",
"(]"). With a unit the comparison is by unit (see isBefore and isAfter).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
a |
yuga.Parsable |
b |
yuga.Parsable |
unit? |
yuga.Unit | "isoWeek" |
inclusivity? |
"()" | "[]" | "[)" | "(]" |
Returns
Section titled “Returns”boolean
isLeapYear()
Section titled “isLeapYear()”isLeapYear(): boolean;Checks if the instance’s year (in its time zone) is a leap year (Day.js’s isLeapYear
plugin). false when invalid.
Returns
Section titled “Returns”boolean
isoWeek()
Section titled “isoWeek()”Call Signature
Section titled “Call Signature”isoWeek(): number;The ISO week of the year, an alias of week() for Day.js code.
Returns
Section titled “Returns”number
Call Signature
Section titled “Call Signature”isoWeek(value): yuga.Yuga;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number |
Returns
Section titled “Returns”isoWeekday()
Section titled “isoWeekday()”Call Signature
Section titled “Call Signature”isoWeekday(): number;The ISO day of the week, Monday is 1 and Sunday is 7. The setter moves within the Monday to Sunday week.
Returns
Section titled “Returns”number
Call Signature
Section titled “Call Signature”isoWeekday(value): yuga.Yuga;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number |
Returns
Section titled “Returns”isoWeeks()
Section titled “isoWeeks()”Call Signature
Section titled “Call Signature”isoWeeks(): number;An alias of isoWeek(), the ISO week of the year.
Returns
Section titled “Returns”number
Call Signature
Section titled “Call Signature”isoWeeks(value): yuga.Yuga;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number |
Returns
Section titled “Returns”isoWeeksInYear()
Section titled “isoWeeksInYear()”isoWeeksInYear(): 52 | 53;The number of ISO weeks in the year, 52 or 53.
Returns
Section titled “Returns”52 | 53
isoWeekYear()
Section titled “isoWeekYear()”isoWeekYear(): number;The year the ISO week belongs to (December 30th 2024 is in 2025).
Returns
Section titled “Returns”number
isSame()
Section titled “isSame()”isSame(that, unit?): boolean;Checks if the instance is the same moment as a parsable, with a unit: if the parsable is
within the instance’s unit (isSame(x, "week") is the same Sunday to Saturday week in
en).
The unit is in the instance’s time zone and locale (see startOf).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
that |
yuga.Parsable |
unit? |
yuga.Unit | "isoWeek" |
Returns
Section titled “Returns”boolean
isSameOrAfter()
Section titled “isSameOrAfter()”isSameOrAfter(that, unit?): boolean;Checks if the instance is the same as or after a parsable (by unit, see isAfter).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
that |
yuga.Parsable |
unit? |
yuga.Unit | "isoWeek" |
Returns
Section titled “Returns”boolean
isSameOrBefore()
Section titled “isSameOrBefore()”isSameOrBefore(that, unit?): boolean;Checks if the instance is the same as or before a parsable (by unit, see isBefore).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
that |
yuga.Parsable |
unit? |
yuga.Unit | "isoWeek" |
Returns
Section titled “Returns”boolean
isToday()
Section titled “isToday()”isToday(): boolean;Checks if the instance is today, in its time zone (Day.js’s isToday plugin).
Day.js compares with the system’s time zone, yugajs with the instance’s, the same as
isSame(…, "day"). It’s false when invalid.
Returns
Section titled “Returns”boolean
isTomorrow()
Section titled “isTomorrow()”isTomorrow(): boolean;Checks if the instance is tomorrow, in its time zone (Day.js’s isTomorrow plugin).
Returns
Section titled “Returns”boolean
isUTC()
Section titled “isUTC()”isUTC(): boolean;Check if the instance is in UTC (the "UTC" time zone, and its names "Etc/UTC",
"Etc/GMT" and "+00:00").
Returns
Section titled “Returns”boolean
isValid()
Section titled “isValid()”isValid(): boolean;Get the validity of the class, opposite of “Invalid Date” in the JS Date object.
Equivalent to !isNaN(yuga().$e).
Returns
Section titled “Returns”boolean
isYesterday()
Section titled “isYesterday()”isYesterday(): boolean;Checks if the instance is yesterday, in its time zone (Day.js’s isYesterday plugin).
Returns
Section titled “Returns”boolean
local()
Section titled “local()”local(keepLocalTime?): yuga.Yuga;The same moment in the system’s time zone.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
keepLocalTime? |
boolean |
Keep the wall clock rather than the moment. A yugajs addition, mirroring utc(true) and tz(zone, true). |
Returns
Section titled “Returns”locale()
Section titled “locale()”Call Signature
Section titled “Call Signature”locale(): string;Get the name of the instance’s locale ("en").
Returns
Section titled “Returns”string
Call Signature
Section titled “Call Signature”locale(preset, object?): yuga.Yuga;A clone in another locale, Day.js’s locale. Names are any BCP 47 tag (built out of Intl)
or registered locales, an object registers it under the name. An unknown locale keeps the
current one.
The global locale stays as is, see yuga.locale.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
preset |
string | yuga.Locale |
object? |
yuga.Locale |
Returns
Section titled “Returns”Example
Section titled “Example”yuga("2024-05-15").locale("fr").format("dddd D MMMM"); // "mercredi 15 mai"localeData()
Section titled “localeData()”localeData(): yuga.LocaleData;The data of the instance’s locale: names, first day of the week, formats, meridiem and
ordinal. months(instance) and its siblings return the name for that instance.
Available with yugajs/extension/locale-data.
Returns
Section titled “Returns”millisecond()
Section titled “millisecond()”Call Signature
Section titled “Call Signature”millisecond(): number;Get the current millisecond.
Returns
Section titled “Returns”number
Call Signature
Section titled “Call Signature”millisecond(value): yuga.Yuga;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number |
Returns
Section titled “Returns”milliseconds()
Section titled “milliseconds()”Call Signature
Section titled “Call Signature”milliseconds(): number;An alias of millisecond().
Returns
Section titled “Returns”number
Call Signature
Section titled “Call Signature”milliseconds(value): yuga.Yuga;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number |
Returns
Section titled “Returns”minute()
Section titled “minute()”Call Signature
Section titled “Call Signature”minute(): number;Returns
Section titled “Returns”number
Call Signature
Section titled “Call Signature”minute(value): yuga.Yuga;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number |
Returns
Section titled “Returns”minutes()
Section titled “minutes()”Call Signature
Section titled “Call Signature”minutes(): number;An alias of minute().
Returns
Section titled “Returns”number
Call Signature
Section titled “Call Signature”minutes(value): yuga.Yuga;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number |
Returns
Section titled “Returns”month()
Section titled “month()”Call Signature
Section titled “Call Signature”month(): number;Returns
Section titled “Returns”number
Call Signature
Section titled “Call Signature”month(value): yuga.Yuga;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number |
Returns
Section titled “Returns”months()
Section titled “months()”Call Signature
Section titled “Call Signature”months(): number;An alias of month().
Returns
Section titled “Returns”number
Call Signature
Section titled “Call Signature”months(value): yuga.Yuga;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number |
Returns
Section titled “Returns”offsetName()
Section titled “offsetName()”offsetName(type?): string;The name of the instance’s time zone at its moment, always in en-US like Day.js: "EDT"
("short", the default) or "Eastern Daylight Time" ("long").
Throws a RangeError when invalid, the same as Day.js. UTC instances are "UTC"
(Day.js gives the system’s name).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
type? |
"short" | "long" |
Returns
Section titled “Returns”string
quarter()
Section titled “quarter()”Call Signature
Section titled “Call Signature”quarter(): number;Returns
Section titled “Returns”number
Call Signature
Section titled “Call Signature”quarter(value): yuga.Yuga;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number |
Returns
Section titled “Returns”quarters()
Section titled “quarters()”Call Signature
Section titled “Call Signature”quarters(): number;An alias of quarter().
Returns
Section titled “Returns”number
Call Signature
Section titled “Call Signature”quarters(value): yuga.Yuga;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number |
Returns
Section titled “Returns”second()
Section titled “second()”Call Signature
Section titled “Call Signature”second(): number;Returns
Section titled “Returns”number
Call Signature
Section titled “Call Signature”second(value): yuga.Yuga;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number |
Returns
Section titled “Returns”seconds()
Section titled “seconds()”Call Signature
Section titled “Call Signature”seconds(): number;An alias of second().
Returns
Section titled “Returns”number
Call Signature
Section titled “Call Signature”seconds(value): yuga.Yuga;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number |
Returns
Section titled “Returns”Call Signature
Section titled “Call Signature”set(unit, value): yuga.Yuga;Set the numeric value of the provided unit.
Equivalent to yuga()[unit](value).
In the repeated hour of a DST fall back the instance’s offset is kept when it’s valid for the
new wall clock (set("minute", 0) of the second 01:30 is the second 01:00), the same as
Temporal’s with and Luxon. Other wall clocks the time zone repeats are the earlier offset,
and ones it skips move forward.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
unit |
yuga.Unit |
The unit of the desired value to set. |
value |
number |
The new value. |
Returns
Section titled “Returns”Call Signature
Section titled “Call Signature”set(unit, value?): yuga.Yuga;Sets several units in the order of the object’s keys (set({ hour: 1, minute: 2 }), no
value).
Available with yugajs/extension/object-support.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
unit |
| yuga.Unit | Partial<Record<yuga.Unit, number>> |
value? |
number |
Returns
Section titled “Returns”startOf()
Section titled “startOf()”startOf(unit): yuga.Yuga;The start of a unit in the instance’s time zone (startOf("month") is the 1st at 00:00).
"week"starts on theweekStartof the instance’s locale (Sunday foren, Monday foren-gb),"isoWeek"always starts on Monday.- Calendar units are wall-clock midnights, a midnight the time zone skips moves forward.
h,mandsround the wall clock down, Temporal’sroundwith"floor": they keep the instance’s offset when it’s valid (the repeated hour of a DST fall back starts at its own 01:00, the same as Moment.js), and start at the top of the wall-clock hour across a 30-minute offset change (Lord Howe).
Milliseconds, unknown and missing units return the same moment.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
unit |
yuga.Unit | "isoWeek" |
Returns
Section titled “Returns”subtract()
Section titled “subtract()”Call Signature
Section titled “Call Signature”subtract(value, unit?): yuga.Yuga;Subtracts an amount of a unit, add with the value negated.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number |
unit? |
yuga.Unit |
Returns
Section titled “Returns”Example
Section titled “Example”yuga("2024-03-31").subtract(1, "M"); // 2024-02-29Call Signature
Section titled “Call Signature”subtract(value, unit?): yuga.Yuga;Subtracts several units in the order of the object’s keys.
Available with yugajs/extension/object-support.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
| number | Partial<Record<yuga.Unit, number>> |
unit? |
yuga.Unit |
Returns
Section titled “Returns”Call Signature
Section titled “Call Signature”subtract(duration): yuga.Yuga;Subtracts a duration, add with every part negated.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
duration |
number | yuga.Duration |
Returns
Section titled “Returns”to(date?, withoutSuffix?): string;The time from the instance to a date in words, yuga("2024-01-01").to("2024-01-03") is
"in 2 days".
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
date? |
yuga.Parsable |
withoutSuffix? |
boolean |
Returns
Section titled “Returns”string
toArray()
Section titled “toArray()”toArray(): [number, number, number, number, number, number, number];[year, month, date, hour, minute, second, millisecond] in the instance’s time zone, the
month is 0-based (Day.js’s toArray plugin).
Returns
Section titled “Returns”[number, number, number, number, number, number, number]
toDate()
Section titled “toDate()”toDate(): Date;Formats to a Date class equivalent value of the class.
Returns
Section titled “Returns”Date
toInstant()
Section titled “toInstant()”toInstant(): Instant;The Temporal.Instant of the instance, throws a RangeError when invalid.
Returns
Section titled “Returns”Instant
toISOString()
Section titled “toISOString()”toISOString(keepOffset?): string;Formats to an ISO 8601 string in UTC with milliseconds ("2024-05-15T10:00:00.000Z"), or at
the instance’s own offset with keepOffset ("2024-05-15T12:00:00.000+02:00", Moment.js’s
toISOString(true)).
Equivalent to yuga().toDate().toISOString(), throws a RangeError when invalid. For
the time zone too, RFC 9557’s "2024-05-15T12:00:00+02:00[Europe/Paris]", use
toTemporal().toString(): yuga() parses it back to the same instance.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
keepOffset? |
boolean |
Returns
Section titled “Returns”string
toJSON()
Section titled “toJSON()”toJSON(): string | null;Serializes to the ISO 8601 string, or null when invalid (used by JSON.stringify).
Returns
Section titled “Returns”string | null
toNow()
Section titled “toNow()”toNow(withoutSuffix?): string;The time from the instance to now in words ("in 2 hours" for an instance in the past).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
withoutSuffix? |
boolean |
Returns
Section titled “Returns”string
toObject()
Section titled “toObject()”toObject(): object;The date and time fields in the instance’s time zone, the month is 0-based (Day.js’s
toObject plugin).
Returns
Section titled “Returns”object
| Name | Type |
|---|---|
date |
number |
hours |
number |
milliseconds |
number |
minutes |
number |
months |
number |
seconds |
number |
years |
number |
toPlainDate()
Section titled “toPlainDate()”toPlainDate(): PlainDate;The Temporal.PlainDate of the instance’s date in its time zone, throws a RangeError when
invalid.
Returns
Section titled “Returns”PlainDate
toString()
Section titled “toString()”toString(): string;Formats to a string in the instance’s time zone ("Wed May 15 2024 06:00:00 GMT-0400 (Eastern Daylight Time)"), “Invalid Date” when invalid.
Equivalent to yuga().toDate().toString() in the system’s time zone. Day.js returns
the UTC string instead, see toUTCString.
Returns
Section titled “Returns”string
toTemporal()
Section titled “toTemporal()”toTemporal(): ZonedDateTime;The Temporal.ZonedDateTime of the instance (its time zone, the system’s when it has none).
The same object as $T, built once. Throws a RangeError when invalid.
Returns
Section titled “Returns”ZonedDateTime
toUTCString()
Section titled “toUTCString()”toUTCString(): string;Formats to a UTC string ("Wed, 15 May 2024 10:00:00 GMT"), “Invalid Date” when invalid.
Equivalent to yuga().toDate().toUTCString() and Day.js’s toString().
Returns
Section titled “Returns”string
Call Signature
Section titled “Call Signature”tz(): string;Get the IANA time zone of the instance (the system’s when it has none of its own).
Returns
Section titled “Returns”string
Call Signature
Section titled “Call Signature”tz(zone, keepLocalTime?): yuga.Yuga;The same moment in another time zone (an IANA name, or an offset such as "+05:30").
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
zone |
string |
- |
keepLocalTime? |
boolean |
Keep the wall clock rather than the moment (10:00 in New York becomes 10:00 in Tokyo). |
Returns
Section titled “Returns”Example
Section titled “Example”yuga("2024-05-15T10:00:00Z").tz("Asia/Tokyo").hour(); // 19Throws
Section titled “Throws”When the time zone is unknown.
unix()
Section titled “unix()”unix(): number;Get the number of seconds since the Unix Epoch, floored.
Equivalent to Math.floor(yuga().valueOf() / 1000).
Returns
Section titled “Returns”number
utc(keepLocalTime?): yuga.Yuga;The same moment in UTC, tz("UTC").
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
keepLocalTime? |
boolean |
Returns
Section titled “Returns”utcOffset()
Section titled “utcOffset()”Call Signature
Section titled “Call Signature”utcOffset(): number;Get the offset from UTC in minutes, rounded to 15 minutes like Day.js (-240 for New York in
summer).
NaN when invalid.
Returns
Section titled “Returns”number
Call Signature
Section titled “Call Signature”utcOffset(offset, keepLocalTime?): yuga.Yuga;The same moment in a fixed offset from UTC, DST doesn’t apply to it.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
offset |
string | number |
Minutes (-240), hours when 16 or less in absolute value (-4), or a string ("-04:00", "+0530", an unparsable one returns the same instance). 0 is utc(). |
keepLocalTime? |
boolean |
Keep the wall clock rather than the moment. |
Returns
Section titled “Returns”Example
Section titled “Example”yuga("2024-05-15T10:00:00Z").utcOffset(-240).format(); // "2024-05-15T06:00:00-04:00"valueOf()
Section titled “valueOf()”valueOf(): number;Get the number of milliseconds since the Unix Epoch of the Yuga class.
Equivalent to yuga().toDate().valueOf(), NaN when invalid.
Returns
Section titled “Returns”number
week()
Section titled “week()”Call Signature
Section titled “Call Signature”week(): number;Returns
Section titled “Returns”number
Call Signature
Section titled “Call Signature”week(value): yuga.Yuga;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number |
Returns
Section titled “Returns”weekday()
Section titled “weekday()”Call Signature
Section titled “Call Signature”weekday(): number;The day of the week by the locale’s weekStart, 0 is the first day of the locale’s week
(Sunday in en, Monday in en-gb). The setter moves within the week the same as
day(n).
Returns
Section titled “Returns”number
Call Signature
Section titled “Call Signature”weekday(value): yuga.Yuga;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number |
Returns
Section titled “Returns”weeks()
Section titled “weeks()”Call Signature
Section titled “Call Signature”weeks(): number;An alias of week().
Returns
Section titled “Returns”number
Call Signature
Section titled “Call Signature”weeks(value): yuga.Yuga;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number |
Returns
Section titled “Returns”weekYear()
Section titled “weekYear()”weekYear(): number;The year the week belongs to by the locale’s weekStart and yearStart.
Returns
Section titled “Returns”number
year()
Section titled “year()”Call Signature
Section titled “Call Signature”year(): number;Returns
Section titled “Returns”number
Call Signature
Section titled “Call Signature”year(value): yuga.Yuga;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number |
Returns
Section titled “Returns”years()
Section titled “years()”Call Signature
Section titled “Call Signature”years(): number;An alias of year().
Returns
Section titled “Returns”number
Call Signature
Section titled “Call Signature”years(value): yuga.Yuga;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
number |
Returns
Section titled “Returns”Internals
Section titled “Internals”| Property | Type | Inherited from |
|---|---|---|
$e |
number |
yuga.Fields.$e |
$isYugaClass |
true |
yuga.Fields.$isYugaClass |
$l |
string |
yuga.Fields.$l |
$T |
ZonedDateTime | null |
yuga.Fields.$T |
$v |
boolean |
yuga.Fields.$v |
$z |
string | undefined |
yuga.Fields.$z |
Type Aliases
Section titled “Type Aliases”yuga.DurationInput
Section titled “yuga.DurationInput”type "yuga.DurationInput" = | number | string | yuga.DurationObject | Temporal.Duration | yuga.Duration;What yuga.duration and duration.add take: a number (of milliseconds, or of a unit), an
object, an ISO 8601 string ("P1DT2H"), a Temporal.Duration or another duration.
yuga.DurationObject
Section titled “yuga.DurationObject”type "yuga.DurationObject" = { [K in yuga.Unit.Short | yuga.Unit.Long | yuga.Unit.Plural]?: number };The parts of a duration by unit ({ hours: 1, minutes: 30 }), any spelling of a unit
(hours, hour, h) the same as Day.js.
yuga.Extension
Section titled “yuga.Extension”type "yuga.Extension"<TConfig> = (extensionConfig, yugaClass) => void;An extension is used to extend the existing yuga structure.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
TConfig |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
extensionConfig |
TConfig |
yugaClass |
yuga.YugaClass |
Returns
Section titled “Returns”void
yuga.Options
Section titled “yuga.Options”type "yuga.Options" = Omit<yuga.Config, "parsable">;The options of yuga(parsable, options), a config without the parsable.
yuga.Parsable
Section titled “yuga.Parsable”type "yuga.Parsable" = yuga.ExpandableParsable[keyof yuga.ExpandableParsable];yuga.Plugin
Section titled “yuga.Plugin”type "yuga.Plugin"<TConfig> = (pluginConfig, yugaFactory) => void;A plugin is used to create separate structures to the yuga.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
TConfig |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
pluginConfig |
TConfig |
yugaFactory |
yuga.Factory |
Returns
Section titled “Returns”void
yuga.Unit
Section titled “yuga.Unit”type "yuga.Unit" = | yuga.Unit.Short | yuga.Unit.Long | yuga.Unit.Plural | yuga.Unit.Loose;Units are case-insensitive ("Year", "MONTHS"), except the short D (date) and M (month).
yuga.Unit.Long
Section titled “yuga.Unit.Long”type "yuga.Unit.Long" = yuga.Unit.Map[keyof yuga.Unit.Map];yuga.Unit.Loose
Section titled “yuga.Unit.Loose”type "yuga.Unit.Loose" = | Capitalize< | yuga.Unit.Long | yuga.Unit.Plural> | Uppercase< | yuga.Unit.Long | yuga.Unit.Plural> | "Q";yuga.Unit.Plural
Section titled “yuga.Unit.Plural”type "yuga.Unit.Plural" = `${yuga.Unit.Long}s`;yuga.Unit.Short
Section titled “yuga.Unit.Short”type "yuga.Unit.Short" = keyof yuga.Unit.Map;yuga.UnitValues
Section titled “yuga.UnitValues”type "yuga.UnitValues" = Partial<Record<yuga.Unit, number>>;Values by unit, in the order they are applied. Inside a parsed object day and d are the
date of the month (date and D too), as in Day.js.
yuga.YugaClass
Section titled “yuga.YugaClass”type "yuga.YugaClass" = new (config) => yuga.Yuga;Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
config |
yuga.Config |
Returns
Section titled “Returns”Variables
Section titled “Variables”const yuga: yuga.Factory;Internals
Section titled “Internals”yuga.Fields
Section titled “yuga.Fields”Extends
Section titled “Extends”Readonly<Record<yuga.Fields.Marker,true> &Record<yuga.Fields.Epoch,number> &Record<yuga.Fields.Zone,string|undefined> &Record<yuga.Fields.Locale,string> &Record<yuga.Fields.Temporal,globalThis.Temporal.ZonedDateTime|null> &Record<yuga.Fields.Valid,boolean> &yuga.Fields.Values&yuga.Fields.Mutators&yuga.Fields.Accessors>
Extended by
Section titled “Extended by”Properties
Section titled “Properties”| Property | Type | Inherited from |
|---|---|---|
d |
number |
yuga.Yuga.d |
D |
number |
yuga.Yuga.D |
date |
((value) => yuga.Yuga) & (() => number) |
yuga.Fields.date |
day |
((value) => yuga.Yuga) & (() => number) |
yuga.Fields.day |
h |
number |
yuga.Yuga.h |
hour |
((value) => yuga.Yuga) & (() => number) |
yuga.Fields.hour |
m |
number |
yuga.Yuga.m |
M |
number |
yuga.Yuga.M |
millisecond |
((value) => yuga.Yuga) & (() => number) |
yuga.Fields.millisecond |
minute |
((value) => yuga.Yuga) & (() => number) |
yuga.Fields.minute |
month |
((value) => yuga.Yuga) & (() => number) |
yuga.Fields.month |
ms |
number |
yuga.Yuga.ms |
q |
number |
yuga.Yuga.q |
quarter |
((value) => yuga.Yuga) & (() => number) |
yuga.Fields.quarter |
s |
number |
yuga.Yuga.s |
second |
((value) => yuga.Yuga) & (() => number) |
yuga.Fields.second |
w |
number |
yuga.Yuga.w |
week |
((value) => yuga.Yuga) & (() => number) |
yuga.Fields.week |
y |
number |
yuga.Yuga.y |
year |
((value) => yuga.Yuga) & (() => number) |
yuga.Fields.year |
Internals
Section titled “Internals”| Property | Type | Inherited from |
|---|---|---|
$e |
number |
yuga.Yuga.$e |
$isYugaClass |
true |
yuga.Yuga.$isYugaClass |
$l |
string |
yuga.Yuga.$l |
$T |
ZonedDateTime | null |
yuga.Yuga.$T |
$v |
boolean |
yuga.Yuga.$v |
$z |
string | undefined |
yuga.Yuga.$z |
yuga.Locale
Section titled “yuga.Locale”A locale, the same shape as Day.js’s locale objects (the parts format uses).
Locales are built out of Intl for any BCP 47 tag, en is built in. Optional names fall
back to slicing the long ones, the same as Day.js ("Jan", "Sun", "Su").
Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
calendar? |
CalendarFormats |
The formats of calendar(), the same as Day.js’s locales’ calendar. They win over the words built from Intl. Available with yugajs/extension/calendar. |
formats? |
Partial<Record<string, string>> |
The templates of the localized formats (LT, LTS, L, LL, LLL, LLLL), the same as Day.js’s locales’ formats. They win over the ones derived from Intl. A short form (l, ll, lll, llll) is its long one with shorter names (MMM, ddd) and numbers (M, D), unless it has a template of its own. Available with yugajs/extension/localized-format. |
postformat? |
(output) => string |
Rewrites the result of format ("2024-05-15" to "٢٠٢٤-٠٥-١٥"), Day.js’s postformat. Needs the preParsePostFormat extension. |
preparse? |
(input) => string |
Rewrites a string before it’s parsed ("٢٠٢٤-٠٥-١٥" to "2024-05-15"), Day.js’s preparse. Needs the preParsePostFormat extension. |
relativeTime? |
RelativeTimeStrings |
The strings of relative time (fromNow, from, toNow, to), the same shape as Day.js’s relativeTime. Locales without it use Intl (en has Day.js’s English ones). |
Internals
Section titled “Internals”yuga.Utils
Section titled “yuga.Utils”Properties
Section titled “Properties”Methods
Section titled “Methods”parseTwoDigitYear()
Section titled “parseTwoDigitYear()”parseTwoDigitYear(input): number;The year of a two-digit year (YY) as written, "69" is 1969 and "68" is 2068 by
default (the same as Day.js and Moment.js). Replace it to change the pivot, Day.js’s
parseTwoDigitYear option.
Available with yugajs/extension/custom-parse-format.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
input |
string |
Returns
Section titled “Returns”number
Internals
Section titled “Internals”format
Section titled “format”readonly format: string;The default display format, ISO 8601 with the local offset (the same as Day.js).
Constant
Section titled “Constant”“YYYY-MM-DDTHH:mm:ssZ”
fromWall
Section titled “fromWall”readonly fromWall: (wall, timeZone) => number;The epoch milliseconds of wall-clock values [y, M, D, h, m, s, ms] (see wall) in a time
zone (undefined is the system’s), NaN when invalid. Overflowing values carry (M: 12
is January of the next year) and years 0-99 stay as written, the same as parse reads a
string without an offset.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
wall |
number[] |
timeZone |
string | undefined |
Returns
Section titled “Returns”number
handlers
Section titled “handlers”readonly handlers: Map<object, { add?: (instance, value, sign) => yuga.Yuga; parse?: (config, timeZone) => number;}>;How core reads the values of extensions, by constructor. Each constructor has one handler, setting it again replaces it, so the order extensions are installed in doesn’t change any result.
parsereads parsablesparsedoesn’t read itself (Arrayfor any array, otherwise the parsable’sconstructor:Objectfor plain objects only), right before reading the rest as theDateconstructor would. It returns the epoch milliseconds,NaNwhen invalid (or when it throws), and can callyuga.$.parsewith a parsable core knows. Abigintis looked up byBigInt.undefined,null, numbers, strings, dates, instances,Temporal.ZonedDateTimes andTemporal.Instants never get here.addmoves an instance by an object value ofadd(sign1) andsubtract(sign-1), by the value’sconstructor(Objectfor plain objects, a class). Numbers never get here, and objects without one are read as numbers.
yuga.$.handlers.set(Array, { parse: (config, timeZone) => yuga.$.parse({ ...config, parsable: … }, timeZone),});yuga.$.handlers.set(Duration, { add: (instance, duration: Duration, sign) => instance.add(duration.asMilliseconds() * sign),});localeOf
Section titled “localeOf”readonly localeOf: (that) => yuga.Locale;The locale of an instance, or of a config (its locale, the locale of the instance it
parses, or the global one), en when unknown. Extensions use it rather than looking
locales up.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
that |
| yuga.Yuga | yuga.Config |
Returns
Section titled “Returns”parseFormat?
Section titled “parseFormat?”parseFormat?: (format, config) => string;Rewrites each format of a string parsable before it is read (yugajs/extension/ localized-format expands L, LT…), unset by default. Called by
yugajs/extension/custom-parse-format.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
format |
string |
config |
yuga.Config |
Returns
Section titled “Returns”string
parseFormatted?
Section titled “parseFormatted?”parseFormatted?: (input, config, timeZone) => number;Reads a string parsable in the config’s format (each of them, when a list), the epoch
milliseconds or NaN when invalid. Wall-clock values are read in timeZone, input is
the string after preparse. parse calls it for every string with a format, they’re
invalid when it is unset (the default). Set by yugajs/extension/custom-parse-format
(Day.js’s customParseFormat).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
input |
string |
config |
yuga.Config |
timeZone |
string | undefined |
Returns
Section titled “Returns”number
parseString?
Section titled “parseString?”parseString?: (input, config, timeZone) => number | undefined;Reads a string parse can’t read itself (yugajs/extension/iso’s RFC 9557 strings, week
dates…), unset by default. Strings that don’t match Day.js’s loose regex get here before
Date reads them, strings in UTC or with an offset only when Date finds them invalid. It
returns the epoch milliseconds (NaN when invalid), or undefined to leave the string to
Date, and can call yuga.$.parse with another parsable.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
input |
string |
config |
yuga.Config |
timeZone |
string | undefined |
Returns
Section titled “Returns”number | undefined
parseTokens?
Section titled “parseTokens?”parseTokens?: Record<string, [pattern: string, apply: (wall, raw, locale) => void]>;The format parsing tokens of extensions, read by yugajs/extension/custom-parse-format,
unset until one adds a token (yugajs/extension/weeks adds w and ww). Each token has
the regex of its single capturing group, and how the text it matched changes the parsed
wall-clock values ([y, M, D, h, m, s, ms], see wall), once the format’s own fields and
their defaults are read (before A / a moves the hour). They come before the built-in
tokens (tokensMap) in the alternation, in the order they’re added: a longer one must be
added before a shorter one that shares its prefix. They don’t replace the built-in tokens.
Either extension can be installed first.
// The week of the year (`weekOf` stands for the extension's code).(yuga.$.parseTokens ??= {}).w = [ "(\\d{1,2})", (wall, raw, locale) => (wall[2] += (+raw - weekOf(wall, locale)) * 7),];Formats are compiled once, tokens only apply to formats not used yet.
postformat?
Section titled “postformat?”postformat?: (output, instance) => string;Rewrites the result of format (Day.js’s postformat), unset by default. Tokens that
format again (LT, L…) use the formatter they’re given (see formatToken), so only the
outermost result goes through it.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
output |
string |
instance |
yuga.Yuga |
Returns
Section titled “Returns”string
preparse?
Section titled “preparse?”preparse?: (input, config) => string;Rewrites a string parsable before parse reads it (Day.js’s preparse), unset by default.
The config keeps the string as given.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
input |
string |
config |
yuga.Config |
Returns
Section titled “Returns”string
readonly short: object;Converts any unit into the short variation of it.
| Name | Type |
|---|---|
d |
"d" |
D |
"D" |
date |
"D" |
dates |
"D" |
day |
"d" |
days |
"d" |
h |
"h" |
hour |
"h" |
hours |
"h" |
m |
"m" |
M |
"M" |
millisecond |
"ms" |
milliseconds |
"ms" |
minute |
"m" |
minutes |
"m" |
month |
"M" |
months |
"M" |
ms |
"ms" |
q |
"q" |
quarter |
"q" |
quarters |
"q" |
s |
"s" |
second |
"s" |
seconds |
"s" |
w |
"w" |
week |
"w" |
weeks |
"w" |
y |
"y" |
year |
"y" |
years |
"y" |
readonly unit: (name) => keyof Map | undefined;The short unit of any unit spelling, case-insensitively ("Days" is "d", "M" is
"M"), undefined when unknown. The same normalization as add, startOf, get… (see
short).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
name |
string |
Returns
Section titled “Returns”keyof Map | undefined
readonly wall: object;The index of each settable unit in the wall-clock values [y, M, D, h, m, s, ms], the same
order as the Date constructor’s arguments (the month is 0-indexed).
| Name | Type |
|---|---|
D |
2 |
h |
3 |
m |
4 |
M |
1 |
ms |
6 |
s |
5 |
y |
0 |
weekOfYear
Section titled “weekOfYear”readonly weekOfYear: (instance, weekStart, yearStart) => number;The week of the year of an instance, for weeks starting on weekStart (0 is Sunday) whose
first week of the year has at least yearStart days in it (a locale’s weekStart and
yearStart, ISO weeks are 1 and 4). NaN when invalid.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
instance |
yuga.Yuga |
weekStart |
number |
yearStart |
number |
Returns
Section titled “Returns”number
zoneOf?
Section titled “zoneOf?”zoneOf?: (config) => string | undefined;The time zone of a parsable that isn’t an object (yugajs/extension/iso reads the RFC 9557
annotation of a string), unset by default. zone asks it only when the config has no
zone and isn’t utc, undefined is the default time zone.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
config |
yuga.Config |
Returns
Section titled “Returns”string | undefined
cascade()
Section titled “cascade()”cascade(yuga): yuga.Yuga;Computes every cached unit field (y M D d h m s ms, then the UTC offset in minutes) from
the instance’s $e in its $z, all of them are NaN when invalid. Instances call it on
the first read of any of them, it returns the instance.
The system’s time zone and UTC are read off a Date, other time zones add their
offset (cached between transitions) without building $T.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
yuga |
yuga.Mutable |
Returns
Section titled “Returns”formatToken()
Section titled “formatToken()”formatToken(token, formatter): void;Adds a format token, or replaces one: format calls formatter with the instance and its
locale. This is how plugins and extensions add tokens (e.g. k, the hour from 1 to 24):
yuga.$.formatToken("k", ({ h }) => h || 24);Templates already used are compiled again, they may have read the token as literal text.
Parsing doesn’t read the token (see parseTokens).
A token that stands for a template in each locale (LT is h:mm A in en) formats it
with the format it’s given (instance.format would apply postformat to the inner
result):
yuga.$.formatToken("LT", (instance, locale, format) => format(instance, templateOf(locale), locale));Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
token |
string |
formatter |
(instance, locale, format) => string | number |
Returns
Section titled “Returns”void
parse()
Section titled “parse()”parse(config, timeZone): number;Extracts the epoch milliseconds out of the provided config, NaN when invalid. Wall-clock
values are read in timeZone (see zone).
undefinedis now,nullis invalid, numbers are epoch milliseconds.- Yuga instances,
Temporal.ZonedDateTimeandTemporal.Instantkeep their epoch. - Strings with a format go to
parseFormatted(yugajs/extension/custom-parse-format), they’re invalid without it. Strings without one use Day.js core’s looseYYYY-MM-DD HH:mm:ss.SSSregex as wall-clock values (unless they end inZor an offset). Years 0000-0099 stay as is. - Strings go through
preparsefirst, when set. - The parsables of extensions (arrays, plain objects,
bigints,Temporal.PlainDate…) go to theirhandlers. - Everything else is read the same as the
Dateconstructor, and is invalid where it would throw (abigintor aTemporal.PlainDatewithout its extension).
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
config |
yuga.Config |
timeZone |
string | undefined |
Returns
Section titled “Returns”number
zone()
Section titled “zone()”zone(config): string | undefined;The time zone an instance of the config is in, undefined is the system’s.
config.zone comes first (validated, a RangeError when unknown), then Yuga instances and
Temporal.ZonedDateTimes keep theirs, and config.utc is "UTC".
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
config |
yuga.Config |
Returns
Section titled “Returns”string | undefined
yuga.Fields.Accessors
Section titled “yuga.Fields.Accessors”type "yuga.Fields.Accessors" = Record<yuga.Unit.Long, () => number>;yuga.Fields.Epoch
Section titled “yuga.Fields.Epoch”type "yuga.Fields.Epoch" = "$e";Milliseconds since the Unix Epoch, NaN when invalid (yuga(null), “Invalid Date”).
yuga.Fields.Locale
Section titled “yuga.Fields.Locale”type "yuga.Fields.Locale" = "$l";The name of the locale ("en"), the global locale when the instance was created.
yuga.Fields.Marker
Section titled “yuga.Fields.Marker”type "yuga.Fields.Marker" = "$isYugaClass";The marker of the class, made to check if a type provided is an instance of Yuga.
Constant
Section titled “Constant”true
yuga.Fields.Mutators
Section titled “yuga.Fields.Mutators”type "yuga.Fields.Mutators" = Record<yuga.Unit.Long, (value) => yuga.Yuga>;yuga.Fields.Temporal
Section titled “yuga.Fields.Temporal”type "yuga.Fields.Temporal" = "$T";The zoned date time of $e in $z, null when invalid. Built on first access and cached.
yuga.Fields.Valid
Section titled “yuga.Fields.Valid”type "yuga.Fields.Valid" = "$v";yuga.Fields.Values
Section titled “yuga.Fields.Values”type "yuga.Fields.Values" = Record<yuga.Unit.Short, number>;yuga.Fields.Zone
Section titled “yuga.Fields.Zone”type "yuga.Fields.Zone" = "$z";The IANA time zone, undefined is the system’s (followed the same as Date does).
yuga.Mutable
Section titled “yuga.Mutable”type "yuga.Mutable" = { -readonly [K in keyof yuga.Yuga]: yuga.Yuga[K] };