Prefer Temporal over libraries
Temporal covers parsing, time zones, date math and formatting. The library you import for that is code your users download for nothing.
12345{ "rules": { "systomic/prefer-temporal-over-libraries": "warn" }}See the difference
import { addDays, format } from "date-fns";
format(addDays(date, 7), "PP")import { addDays, format } from "date-fns"// Built in, nothing to import
date.add({ days: 7 }).toLocaleString()date.add({ days: 7 }).toLocaleString()What doesn't work
2 findings1234import { format } from "date-fns";import dayjs from "dayjs";
export const label = format(dayjs().toDate(), "PP");systomic/prefer-temporal-over-libraries date-fns: use Temporal instead. date-fns works on Date; Temporal has the same operations as methods (add, subtract, until, since, round, compare).
systomic/prefer-temporal-over-libraries dayjs: use Temporal instead. Temporal covers parsing, math (add, until, round) and formatting (toLocaleString) without plugins.
What works
No findings1234import type { Locale } from "date-fns";
export const locale: Locale | undefined = undefined;export const label = Temporal.Now.plainDateISO().toLocaleString("en", { dateStyle: "medium" });Details
Reports imports of date libraries, since Temporal covers parsing, time zones, math and formatting. Companion of prefer-temporal, split out so it can be switched off or narrowed down on its own during a migration.
12import { addDays, format } from "date-fns"; // reportedimport dayjs from "dayjs"; // reportedReported: import (also subpaths like date-fns/locale, dayjs/plugin/utc), export … from, import() and require(). Type-only imports are fine.
Default libraries: moment, moment-timezone, dayjs, date-fns, date-fns-tz, @date-fns/*, luxon, spacetime, timeago.js. The message names what Temporal offers instead of the library.
| Option | Default |
|---|---|
libraries |
the list above (replaces it; * globs) |
allow |
[]: libraries to keep for now |
ignore |
[]: file globs relative to the nearest package.json; see monorepos |