Migrating angular-moment / Moment.js to modern Angular
angular-moment exposed Moment.js through filters like amDateFormat and amTimeAgo. Moment itself is in maintenance mode and its authors recommend alternatives for new work.
What replaces it
| Option | When to choose it |
|---|---|
| date-fns | Small functions, tree-shakeable, works with native Date. |
| Luxon | When time zones and durations are central to the product. |
| Angular DatePipe | Enough when you only format dates for display. |
How to migrate it
- Separate formatting (templates) from date maths (services); they migrate differently.
- Replace the am filters with DatePipe or a small custom pipe.
- Replace date arithmetic and parsing with date-fns or Luxon, with unit tests around time zones.
Watch out. Moment objects are mutable; the replacements are not. Code that called add or startOf without using the return value changes behavior silently.
Other libraries
Planning a migration or a micro-frontend platform?
In a 20-minute call you describe your situation and I tell you how I'd approach it. If it isn't worth doing yet, I'll say so.
Message me on LinkedIn