Overview
Remove moment.js (~300KB bundle cost) and replace all usages with date-fns v3 which is already in package.json at v2. This issue upgrades date-fns to v3 and removes moment entirely.
Can be done independently
This issue has no dependency on the Angular upgrade path and can be worked on in parallel.
Scope
1. Upgrade date-fns to v3
npm install date-fns@3
npm uninstall moment
2. Find all moment usages
grep -r "moment" src/ --include="*.ts" --include="*.html" -l
3. Replace common patterns
| moment.js |
date-fns v3 equivalent |
moment().format('DD/MM/YYYY') |
format(new Date(), 'dd/MM/yyyy') |
moment(date).fromNow() |
formatDistanceToNow(date, { addSuffix: true }) |
moment(date).diff(other, 'days') |
differenceInDays(date, other) |
moment(date).add(7, 'days') |
addDays(date, 7) |
moment(date).isBefore(other) |
isBefore(date, other) |
moment(date).startOf('month') |
startOfMonth(date) |
moment(date).isValid() |
isValid(date) |
moment(str, 'YYYY-MM-DD') |
parse(str, 'yyyy-MM-dd', new Date()) |
4. Note on date-fns v2 → v3 breaking changes
date-fns v3 is ESM-first — all imports must be named imports from date-fns
date-fns/esm sub-path no longer exists in v3
- Some locale imports changed:
import { enUS } from 'date-fns/locale'
Acceptance Criteria
Overview
Remove
moment.js(~300KB bundle cost) and replace all usages withdate-fnsv3 which is already inpackage.jsonat v2. This issue upgrades date-fns to v3 and removes moment entirely.Can be done independently
This issue has no dependency on the Angular upgrade path and can be worked on in parallel.
Scope
1. Upgrade date-fns to v3
2. Find all moment usages
3. Replace common patterns
moment().format('DD/MM/YYYY')format(new Date(), 'dd/MM/yyyy')moment(date).fromNow()formatDistanceToNow(date, { addSuffix: true })moment(date).diff(other, 'days')differenceInDays(date, other)moment(date).add(7, 'days')addDays(date, 7)moment(date).isBefore(other)isBefore(date, other)moment(date).startOf('month')startOfMonth(date)moment(date).isValid()isValid(date)moment(str, 'YYYY-MM-DD')parse(str, 'yyyy-MM-dd', new Date())4. Note on date-fns v2 → v3 breaking changes
date-fnsv3 is ESM-first — all imports must be named imports fromdate-fnsdate-fns/esmsub-path no longer exists in v3import { enUS } from 'date-fns/locale'Acceptance Criteria
momentremoved frompackage.jsonimport momentorimport * as momentanywhere insrc/ng buildcompletes successfullynpx source-map-explorer dist/)