A Practical Guide to Dayjs Plugins

Learn how the plugin system keeps the core tiny, which official plugins earn a place in most projects and how to write one of your own.

Updated 15 November 20266 min readPlugins
Monitor displaying JavaScript used to load Dayjs plugins

The secret behind the small size of Dayjs is not that it does less, but that it asks you to choose what it does. Rather than bundling every feature into one large file, Dayjs keeps a lean core and offers optional behaviour through plugins. At the time of writing there are 37 official plugins, covering everything from time zones to ordinals to quarter calculations. This guide explains how the plugin system works, how to load plugins in different environments, which plugins most projects benefit from and how to write a simple plugin of your own.

How the Dayjs plugin system works

A plugin is a function that receives the Dayjs class and the dayjs factory, then adds or overrides methods. Calling dayjs.extend(plugin) runs that function once, after which every instance, past and future, gains the new behaviour.

import dayjs from 'dayjs'
import isLeapYear from 'dayjs/plugin/isLeapYear'

dayjs.extend(isLeapYear)
dayjs('2028-01-01').isLeapYear()   // true

Three properties of this design are worth remembering. First, plugins are global: extending once affects the entire application. Second, extending the same plugin twice is harmless, because Dayjs tracks which plugins are installed. Third, order occasionally matters, as some plugins build on others. The Timezone plugin, for example, requires the UTC plugin to be extended first.

Loading Dayjs plugins in different environments

Bundlers and ES modules

In projects built with Vite, webpack, Rollup or similar tools, import each plugin from dayjs/plugin/ followed by its name. Your bundler includes only the plugins you import.

import utc from 'dayjs/plugin/utc'
import timezone from 'dayjs/plugin/timezone'
dayjs.extend(utc)
dayjs.extend(timezone)

Node.js with CommonJS

The same paths work with require.

const dayjs = require('dayjs')
dayjs.extend(require('dayjs/plugin/relativeTime'))

Browsers via CDN

Each plugin file exposes a global named dayjs_plugin_ followed by the plugin name. Load the core first, then the plugin, then extend.

<script src="https://cdn.jsdelivr.net/npm/dayjs@1/dayjs.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/dayjs@1/plugin/isBetween.js"></script>
<script>dayjs.extend(window.dayjs_plugin_isBetween)</script>

Our installation guide describes each of these environments in more depth, including TypeScript configuration.

The plugins most projects need

Not every plugin earns a place in every project, but a handful appear in the majority of real applications.

UTC and Timezone

Any product used across regions needs these two. UTC enables a stable reference clock for storage and reporting; Timezone converts between IANA zones and interprets local times correctly. They are explained thoroughly in our time zones and UTC guide.

RelativeTime

Adds fromNow(), toNow(), from() and to() for phrases such as “3 hours ago”. It is essential for feeds, comments, notifications and activity logs.

CustomParseFormat

Allows parsing of non-ISO strings by declaring an explicit pattern, with an optional strict mode. Any application that accepts dates from users or imports should load it.

Duration

Models lengths of time for timers, countdowns, billing periods and elapsed-time reports. It pairs naturally with RelativeTime, as shown in our relative time and durations guide.

AdvancedFormat and LocalizedFormat

AdvancedFormat adds ordinals, quarters and Unix tokens to format(). LocalizedFormat adds locale-aware shortcuts such as L and LLL that adapt to each visitor's conventions.

Useful specialist plugins

Beyond the essentials, many smaller plugins solve specific problems neatly:

  • IsBetween checks whether a date falls within a range, with control over inclusive and exclusive bounds.
  • IsSameOrBefore and IsSameOrAfter express inclusive comparisons in readable form.
  • IsToday, IsTomorrow and IsYesterday answer everyday questions in one call.
  • MinMax finds the earliest or latest of several dates with dayjs.min() and dayjs.max().
  • WeekOfYear, IsoWeek, WeekYear and IsoWeeksInYear support week-based reporting and calendars.
  • QuarterOfYear reads and sets quarters and allows adding quarters as a unit.
  • DayOfYear returns or sets the day number within the year.
  • Weekday gives a locale-aware day of the week, respecting whether weeks start on Sunday or Monday.
  • Calendar produces output such as “Yesterday at 09:10”.
  • UpdateLocale customises the text and settings of an existing locale.
  • ObjectSupport and ArraySupport accept objects or arrays as input.
  • ToArray and ToObject export an instance as an array or object of units.
  • BuddhistEra adds the Buddhist calendar year token used in Thailand and elsewhere.
  • DevHelper prints warnings during development when an API is used incorrectly.

Most of these are only a few hundred bytes, so including two or three costs far less than writing and testing equivalent code yourself.

Organising Dayjs plugins in a real codebase

The cleanest approach is a single setup module that imports Dayjs, extends every plugin the project uses, sets the default locale and exports the configured function. Every other file imports from this module instead of from the package directly.

// src/lib/dayjs.js
import dayjs from 'dayjs'
import utc from 'dayjs/plugin/utc'
import timezone from 'dayjs/plugin/timezone'
import relativeTime from 'dayjs/plugin/relativeTime'
import customParseFormat from 'dayjs/plugin/customParseFormat'
import isBetween from 'dayjs/plugin/isBetween'

;[utc, timezone, relativeTime, customParseFormat, isBetween].forEach(p => dayjs.extend(p))

export default dayjs

This pattern has several advantages. It guarantees plugins are loaded before use, eliminating “is not a function” errors that depend on import order. It documents in one place which capabilities the project relies on. And it makes testing easier, since test files can import the same configured instance.

Plugins and TypeScript

Every official plugin ships with type declarations that augment the core Dayjs interface. Importing a plugin is enough for the compiler to recognise its methods; you do not need to declare anything manually. If a method appears untyped, check that the plugin is imported somewhere the compiler can see, typically in the setup module, and that your configuration includes that file.

Writing your own Dayjs plugin

Sometimes a project repeats the same date logic in many places, such as determining whether a date falls on a business day. Wrapping that logic in a plugin keeps calling code tidy and consistent.

// businessDay.js
export default function businessDay(option, dayjsClass, dayjsFactory) {
  dayjsClass.prototype.isBusinessDay = function () {
    const d = this.day()
    return d !== 0 && d !== 6
  }

  dayjsClass.prototype.addBusinessDays = function (n) {
    let result = this
    let added = 0
    while (added < n) {
      result = result.add(1, 'day')
      if (result.isBusinessDay()) added++
    }
    return result
  }
}
import businessDay from './businessDay'
dayjs.extend(businessDay)

dayjs('2026-11-13').addBusinessDays(1).format('ddd D MMM')  // 'Mon 16 Nov'

A plugin function receives three arguments: an options object passed as the second argument to extend(), the Dayjs class whose prototype you can enrich, and the factory function on which you can add static helpers. Keep the immutability principle intact by always returning new instances rather than modifying this. If you want to extend an existing method rather than add a new one, store a reference to the original prototype method and call it from your replacement.

For TypeScript users, add a declaration file that augments the dayjs module with your new methods so that editors offer autocompletion.

Performance and bundle considerations

Each plugin you import adds a little weight, typically between a few hundred bytes and a couple of kilobytes. Even a generous selection keeps the total well below the size of Moment.js, as discussed on our homepage performance section. The main discipline is to avoid importing plugins speculatively. Load what your code uses, review the list occasionally and remove anything that no longer earns its place.

For teams moving from Moment.js, the plugin list doubles as a migration checklist. Our migration guide maps common Moment.js features to the plugins that provide them.

Choosing plugins for a new project

Starting a fresh project is the ideal moment to decide which plugins belong in your setup module. A sensible baseline for most web applications is UTC, Timezone, RelativeTime and CustomParseFormat, because nearly every product eventually stores dates centrally, displays them to people in different places, shows recent activity and accepts input from forms. Add LocalizedFormat if you serve more than one region, and Duration if you display timers or elapsed time.

Resist the temptation to add everything at once. Each plugin you load becomes part of the vocabulary your team must understand, and unused capabilities create confusion during code review. A short list, documented with a comment explaining why each plugin is present, keeps the setup readable for newcomers.

Troubleshooting plugin problems

Most plugin issues fall into a few predictable categories. A “not a function” error almost always means the plugin was not extended before use, often because a component imported Dayjs directly instead of the configured setup module. Duplicate copies of the library in node_modules, which occur when packages request different versions, can also hide plugins, since each copy keeps its own list of extensions.

When two plugins appear to conflict, check the order in which they are extended and consult the documentation for dependencies. Timezone after UTC is the most common requirement, while formatting plugins generally work in any order. The DevHelper plugin can surface warnings during development that point directly to misuse, and it is worth enabling in development builds only.

Finally, remember that plugins modify behaviour globally. Tests that extend plugins should do so in a shared setup file so that every test runs against the same configuration, mirroring production as closely as possible.

Conclusion

Plugins are what allow Dayjs to remain tiny without feeling limited. A single call to extend() adds capabilities such as time zones, relative time, custom parsing and durations, while dozens of smaller plugins cover specialist needs from ISO weeks to Buddhist years. Gather your plugins in one setup module, rely on the bundled type declarations and write your own plugins when repeated logic deserves a home. The result is a date toolkit shaped precisely to your project, with nothing wasted.