Skip to content

Replace moment.js with date-fns v3#87

Open
miokidk wants to merge 2 commits into
BAWES-Universe:masterfrom
miokidk:bounty/replace-moment-date-fns
Open

Replace moment.js with date-fns v3#87
miokidk wants to merge 2 commits into
BAWES-Universe:masterfrom
miokidk:bounty/replace-moment-date-fns

Conversation

@miokidk

@miokidk miokidk commented May 16, 2026

Copy link
Copy Markdown

Summary

  • upgrade date-fns to v3 and remove the direct moment.js dependency
  • remove the legacy ion2-calendar package that required moment as a peer dependency
  • add local compatibility shims for date formatting and existing calendar modal imports so Angular 15 / TypeScript 4.8 can still build

Verification

  • npm run build

Closes #31

Summary by CodeRabbit

  • Dependencies

    • Upgraded date-fns library from v2.29.3 to v3.6.0 for improved date handling and calendar features.
  • Refactoring

    • Enhanced internal date and calendar utility implementation for improved performance and maintainability.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 16, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@miokidk has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 36 minutes and 47 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 628244b1-8248-438a-b23b-db2dc36969c0

📥 Commits

Reviewing files that changed from the base of the PR and between 60bc071 and 62b5a12.

📒 Files selected for processing (2)
  • src/app/util/calendar-shim.ts
  • src/app/util/date-fns-shim.ts
📝 Walkthrough

Walkthrough

This PR upgrades date-fns from v2 to v3, removes moment.js dependency, and provides custom shim implementations for date utilities and calendar modal functionality via TypeScript path aliases to eliminate external calendar library dependencies.

Changes

moment.js to date-fns v3 Migration

Layer / File(s) Summary
Dependency upgrade and module resolution
package.json, tsconfig.json
date-fns upgraded to ^3.6.0, moment.js and ion2-calendar removed from dependencies. TypeScript paths configured to redirect date-fns and ion2-calendar imports to local shim modules at src/app/util/date-fns-shim and src/app/util/calendar-shim.
Date utility shim implementation
src/app/util/date-fns-shim.ts
Lightweight shim providing parseISO(), format() with token replacement, month boundaries (startOfMonth, endOfMonth), interval iteration (eachDayOfInterval), component extraction (getDate, getMonth, getYear), and comparisons (isSameDay, isSameMonth, isSameYear, isToday) with internal normalizers for `Date
Calendar modal component and module
src/app/util/calendar-shim.ts
Custom CalendarModal Angular component with Ionic ion-datetime inputs replaces ion2-calendar, supporting single-date and date-range modes, optional bounds, initialization from defaults, and modal dismissal with normalized yyyy-MM-dd result objects. Exports CalendarModule with declarations and Ionic/CommonModule imports.
Update existing code references
src/app/pages/logged-in/transfer/transfer-form/transfer-form.page.ts
Transfer form date-range configuration comment updated to remove moment from documented supported type variants.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Moment.js has hopped away,
date-fns v3 leads the way!
Calendar shims and utils shine,
Bundle size will feel divine. ✨📅

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Linked Issues check ❓ Inconclusive The PR addresses the core requirements from issue #31: upgrades date-fns to v3, sets up compatibility shims for calendar and date formatting, updates package.json, and updates imports. However, there is no explicit evidence that moment is completely removed from package.json or that all source files were checked for moment imports. Verify that moment.js is completely removed from package.json and confirm no moment imports remain anywhere in src/ via grep or similar search.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Replace moment.js with date-fns v3' directly and accurately summarizes the main change in the PR—upgrading to date-fns v3 and removing moment.js.
Out of Scope Changes check ✅ Passed All changes are directly related to the moment.js to date-fns v3 migration: package.json dependency upgrade, tsconfig path aliases, compatibility shims, and comment updates. No unrelated changes detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 60bc0714bc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/app/util/date-fns-shim.ts Outdated
Comment on lines +3 to +4
export function parseISO(value: string): Date {
return new Date(value);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Parse date-only ISO strings without UTC shift

parseISO now returns new Date(value), which treats 'YYYY-MM-DD' inputs as UTC midnight; in negative-offset timezones (e.g. US), formatting that Date with local getters produces the previous calendar day. This breaks the many flows that do format(parseISO(...), 'yyyy-MM-dd') for filters/forms and can send or display off-by-one dates for users west of UTC.

Useful? React with 👍 / 👎.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/app/util/calendar-shim.ts`:
- Around line 157-159: toDate currently calls new Date(value) which treats
date-only strings (yyyy-MM-dd from ion-datetime) as UTC midnight and causes
timezone drift; update toDate (used by toResult) to detect date-only strings
(match /^\d{4}-\d{2}-\d{2}$/) and parse them into a local Date via the Date
constructor with numeric components (new Date(year, monthIndex, day)) so the
resulting Date represents local midnight; for non-date-only strings keep the
existing fallback of new Date(value).

In `@src/app/util/date-fns-shim.ts`:
- Around line 3-5: The parseISO implementation incorrectly uses new Date(value)
which treats date-only strings as UTC; update parseISO to detect date-only ISO
strings (e.g., via /^\d{4}-\d{2}-\d{2}$/) and for those parse out year, month,
day and return new Date(year, monthIndex, day) so the resulting Date is
constructed in local time; for all other ISO inputs (datetime with time or
timezone) fall back to new Date(value) to preserve existing behavior. Ensure you
reference and modify the parseISO function accordingly and compute monthIndex as
month - 1.
- Around line 64-66: The isSameMonth function only compares the month number and
omits the year, causing dates like Dec 2025 and Dec 2026 to be considered equal;
modify isSameMonth (and use toDate) to also compare the full year (e.g., compare
toDate(left).getFullYear() === toDate(right).getFullYear() in addition to
getMonth()) so both year and month must match to return true.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8126ae93-7f7b-486f-9144-d8af6719b9ad

📥 Commits

Reviewing files that changed from the base of the PR and between 39a33ff and 60bc071.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (5)
  • package.json
  • src/app/pages/logged-in/transfer/transfer-form/transfer-form.page.ts
  • src/app/util/calendar-shim.ts
  • src/app/util/date-fns-shim.ts
  • tsconfig.json

Comment thread src/app/util/calendar-shim.ts
Comment thread src/app/util/date-fns-shim.ts
Comment thread src/app/util/date-fns-shim.ts
@miokidk

miokidk commented May 16, 2026

Copy link
Copy Markdown
Author

Addressed the CodeRabbit review feedback in commit 62b5a12:\n\n- date-only strings are now parsed into local Date values in both shims to avoid UTC date drift\n- isSameMonth now compares both year and month\n- reran npm run build successfully after the changes

@miokidk

miokidk commented May 16, 2026

Copy link
Copy Markdown
Author

Additional verification for the linked-issue check:

  • rg -n "moment" package.json package-lock.json src returns no matches.
  • package.json / package-lock.json no longer include moment or ion2-calendar dependencies.
  • Remaining source imports from ion2-calendar are intentionally routed through the tsconfig.json path alias to the local src/app/util/calendar-shim.ts compatibility shim.
  • npm run build passed after the latest commit (62b5a12).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[UPGRADE] Replace moment.js with date-fns v3

1 participant