Migrate from Day.js
yuga has the API of Day.js core and the parts of its plugins most apps load. For most code, migrating is swapping the import and calling yuga where the code called dayjs; the methods, formats and units are the same:
import dayjs from "dayjs";import { yuga } from "yugajs";
dayjs().add(1, "month").format("D MMMM YYYY");yuga().add(1, "month").format("D MMMM YYYY");Types are renamed the same way: an instance is a Yuga (import type { Yuga } from "yugajs"), where Day.js has Dayjs.
Every Day.js core API is implemented and tested against Day.js. Differences are only in edge cases where yuga follows Moment.js or Temporal instead of a Day.js quirk; they’re listed below.
Before you start
Section titled “Before you start”- yuga needs
Temporal. Check the requirements for the runtimes you support. - yuga is ESM only.
- Locale files go away: delete the
dayjs/locale/*imports,yuga().locale("fr")works without them.
Plugins
Section titled “Plugins”Several Day.js plugins are part of yuga’s core. The others map to an extension (yuga.extend) or a plugin (yuga.plug) under the same name in kebab case.
| Day.js plugin | yuga |
|---|---|
utc, timezone |
Core: yuga.utc, yuga.tz, instance.tz |
isSameOrBefore, isSameOrAfter |
Core |
quarterOfYear |
Core: quarter(), the Q token |
isoWeek (the unit), weekOfYear (week()) |
Core: startOf("isoWeek"), week() |
customParseFormat |
yugajs/extension/custom-parse-format |
advancedFormat |
yugajs/extension/advanced-format (Q, Do are core) |
localizedFormat |
yugajs/extension/localized-format |
relativeTime |
yugajs/extension/relative-time |
calendar |
yugajs/extension/calendar |
isBetween |
yugajs/extension/is-between |
isToday, isTomorrow, isYesterday |
yugajs/extension/is-today, all three |
isLeapYear |
yugajs/extension/is-leap-year |
dayOfYear |
yugajs/extension/day-of-year |
weekday, weekYear, isoWeek (the rest), isoWeeksInYear |
yugajs/extension/weeks |
arraySupport, objectSupport |
yugajs/extension/array-support, yugajs/extension/object-support |
toArray, toObject |
yugajs/extension/to-array, yugajs/extension/to-object |
pluralGetSet |
yugajs/extension/plural-get-set |
buddhistEra |
yugajs/extension/buddhist-era |
bigIntSupport |
yugajs/extension/big-int-support |
preParsePostFormat |
yugajs/extension/pre-parse-post-format |
duration |
yugajs/plugin/duration, with yuga.plug |
minMax |
yugajs/plugin/min-max, with yuga.plug |
localeData, updateLocale |
yugajs/plugin/locale-data, with yuga.plug |
import { customParseFormat } from "yugajs/extension/custom-parse-format";import { minMax } from "yugajs/plugin/min-max";
yuga.extend(customParseFormat);yuga.plug(minMax);Extensions add to instances; plugins add to yuga itself. The order they’re installed in never changes a result.
Your own Day.js plugins won’t run unchanged: they reach into Day.js’s internals ($d, $utils), which yuga doesn’t have. yuga’s internals are on yuga.$, and porting a plugin usually means registering a format token or a parse handler there.
Intentional differences
Section titled “Intentional differences”The ones you’re most likely to meet:
toString()is the local string in the instance’s time zone. Day.js’s istoUTCString().- Years
0000–0099stay as written. Day.js reads them as 1900–1999. - The literal text of a parsing format has to match. Day.js skips separators that don’t.
- Lowercase
qin a format is a quarter. In Day.js core it’s milliseconds. diffwith an invalid instance isNaNin every unit. Day.js gives0for months, quarters and years.- In the hour repeated when clocks go back,
startOfand the setters keep the instance’s offset, the same as Moment.js and Temporal. yuga.tz.setDefault(zone)is the time zone of every new instance, not just ofyuga.tz.isToday()and its siblings compare with today in the instance’s time zone, not the system’s.- Month and weekday names come from
Intl, not Day.js’s locale files. duration.format()prints0for a missing part where Day.js prints “undefined”.
The Day.js parity document has every API, its status and all 32 differences, each tested against Day.js.
From Moment.js
Section titled “From Moment.js”Day.js’s API is Moment.js’s, so the same steps apply. Where Day.js and Moment.js disagree, yuga mostly sides with Moment.js: toISOString(true) keeps the offset, utcOffset("+05") is +05:00, and changes of clocks keep the offset Moment.js keeps.