Replaces deprecated moment.js usages with Temporal API equivalents.
AugustinMauroy·5 executions
transformation
migration
moment.js
temporal
moment to Temporal
This codemod migrates common moment and moment-timezone usage to Temporal equivalents. It rewrites frequently used patterns such as “now”, add/subtract chains, simple formatting, parsing, durations, timezone conversion, and validation checks.
It also supports migrating a limited Luxon entrypoint (DateTime.local()) to Temporal in mixed codebases.
Goal
Replace common moment APIs with Temporal equivalents.
Remove moment / moment-timezone / luxon imports when transformed.
Keep transformed code explicit and readable.
Cover common migration paths while surfacing edge cases for review.
Example
Replace moment() + .format()
diff
- import moment from 'moment';
- const now = moment();
- console.log(now.format());
+ const now = Temporal.Now.zonedDateTimeISO();
+ console.log(now.toString());
Replace add/subtract chaining
diff
- import moment from 'moment';
- const m = moment().add(3, 'days').subtract(4, 'hours');
- console.log(m.format());
+ let z = Temporal.Now.zonedDateTimeISO();
+ z = z.plus({ days: 3 });
+ z = z.minus({ hours: 4 });
+ console.log(z.toString());
Replace simple date formatting (YYYY-MM-DD)
diff
- import moment from 'moment';
- const s = moment().format('YYYY-MM-DD');
+ const s = Temporal.Now.plainDateISO().toString();