Migrating to Atemporal from other date libraries is straightforward. This guide provides side-by-side comparisons and highlights key differences to help you transition smoothly.
import dayjs from 'dayjs';import relativeTime from 'dayjs/plugin/relativeTime';import customParseFormat from 'dayjs/plugin/customParseFormat';dayjs.extend(relativeTime);dayjs.extend(customParseFormat);const ago = dayjs().subtract(2, 'hour').fromNow();const parsed = dayjs('25/12/2024', 'DD/MM/YYYY');
import atemporal from 'atemporal';import relativeTime from 'atemporal/plugins/relativeTime';import customParseFormat from 'atemporal/plugins/customParseFormat';atemporal.extend(relativeTime);atemporal.extend(customParseFormat);const ago = atemporal().subtract(2, 'hour').fromNow();const parsed = atemporal.fromFormat('25/12/2024', 'DD/MM/YYYY');
import atemporal from 'atemporal';// Load plugins on demand - reduces initial bundle sizeawait atemporal.lazyLoad('relativeTime');await atemporal.lazyLoad('customParseFormat');const ago = atemporal().subtract(2, 'hour').fromNow();const parsed = atemporal.fromFormat('25/12/2024', 'DD/MM/YYYY');
// Beforeimport dayjs from 'dayjs';import { DateTime } from 'luxon';import moment from 'moment';// Afterimport atemporal from 'atemporal';
3
Update Method Calls
Use the comparison tables above to update method names and parameters.
4
Check for Mutations (from Moment)
If migrating from Moment, search for places where you relied on mutation and ensure you capture the returned value:
// Before (Moment)date.add(1, 'day');// After (Atemporal)date = date.add(1, 'day');
5
Load Required Plugins
Identify which plugins you need and load them:
import atemporal from 'atemporal';import relativeTime from 'atemporal/plugins/relativeTime';atemporal.extend(relativeTime);// Or use lazy loadingawait atemporal.lazyLoad('relativeTime');
// ❌ Wrong - using plugin method before loadingconst ago = atemporal().subtract(2, 'hour').fromNow();// TypeError: fromNow is not a function// ✅ Correct - load plugin firstimport relativeTime from 'atemporal/plugins/relativeTime';atemporal.extend(relativeTime);const ago = atemporal().subtract(2, 'hour').fromNow();