Skip to content

refactor: replace moment with dayjs#1856

Merged
UnschooledGamer merged 19 commits intoAcode-Foundation:mainfrom
hyperz111:replace-moment
Feb 15, 2026
Merged

refactor: replace moment with dayjs#1856
UnschooledGamer merged 19 commits intoAcode-Foundation:mainfrom
hyperz111:replace-moment

Conversation

@hyperz111
Copy link
Contributor

moment is unmaintained, so i replace it with dayjs.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @hyperz111, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the project's date handling by replacing the moment.js library with dayjs. The primary motivation is to move away from an unmaintained dependency to a more actively developed and performant alternative. This change involves updating package dependencies and migrating existing date manipulation code to use the dayjs API, ensuring continued functionality with improved maintainability.

Highlights

  • Dependency Update: Replaced the unmaintained moment.js library with dayjs for date manipulation. This change addresses the maintenance status of moment.js and introduces a more modern, lightweight alternative.
  • Package Management: Updated package.json and package-lock.json to reflect the removal of moment and the addition of dayjs as a dependency.
  • Code Migration: Migrated date formatting logic in src/pages/plugin/plugin.view.js from moment to dayjs, including importing necessary dayjs plugins (relativeTime, updateLocale) and adapting API calls.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 2, 2026

Greptile Summary

Replaces the unmaintained moment library with dayjs for date formatting. The migration correctly updates dependencies and moves locale configuration to module initialization (addressing the global mutation concern from previous reviews).

Key changes:

  • Replaced moment with dayjs in package.json
  • Imported dayjs ESM modules with required plugins (relativeTime, updateLocale, utc)
  • Moved updateLocale configuration to module-level scope (preventing repeated execution)
  • Updated formatUpdatedDate to use dayjs API

Note: Previous review comments mentioned that fromNow(true) removes the "ago" suffix. The current code uses fromNow() without arguments, which should preserve the expected behavior.

Confidence Score: 4/5

  • Safe to merge with minor verification recommended
  • The migration from moment to dayjs is well-executed with proper plugin setup and module-level configuration. The locale configuration was correctly moved to prevent repeated execution. The main concern is that previous reviews flagged the fromNow(true) vs fromNow() behavior difference, though the current code appears to use fromNow() without arguments which should work correctly. Manual testing of the date display would be prudent to verify the "ago" suffix appears as expected.
  • Verify src/pages/plugin/plugin.view.js displays dates correctly in the UI (e.g., "5m ago" not just "5m")

Important Files Changed

Filename Overview
package.json Replaced moment (^2.30.1) with dayjs (^1.11.19), both are MIT licensed and the migration is straightforward
package-lock.json Lock file correctly updated to reflect the dependency change from moment to dayjs
src/pages/plugin/plugin.view.js Migrated from moment to dayjs with ESM imports; locale config moved to module level (good); but fromNow() call may have different behavior than original

Flowchart

flowchart TD
    A[Module Load] --> B[Import dayjs ESM]
    B --> C[Extend relativeTime plugin]
    C --> D[Extend utc plugin]
    D --> E[Extend updateLocale plugin]
    E --> F[Configure custom relativeTime locale]
    F --> G[Module Ready]
    
    H[formatUpdatedDate called] --> I{dateString exists?}
    I -->|No| J[Return null]
    I -->|Yes| K[dayjs.utc parse dateString]
    K --> L{Valid date?}
    L -->|No| J
    L -->|Yes| M[Call fromNow]
    M --> N[Return relative time string]
    
    style F fill:#e1f5e1
    style K fill:#e1f5e1
    style M fill:#e1f5e1
Loading

Last reviewed commit: e87700f

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 2, 2026

Additional Comments (1)

src/pages/plugin/plugin.view.js
[P1] fromNow(true) drops the “ago/in …” suffix, changing UI text

In formatUpdatedDate, moment.utc(dateString).fromNow() previously returned strings including the suffix (e.g., "5m ago"). With Day.js you’re currently doing updateTime.fromNow(true), which returns only the distance (e.g., "5m") and will never append past/future strings (so the past: "%s ago" config won’t apply). This changes the displayed packageUpdatedAt text.

Also, moment.utc(dateString) preserved UTC semantics; dayjs(dateString) will parse in local time unless the input includes a timezone offset. If package_updated_at is UTC and doesn’t include an offset, this can skew the relative time.

A minimal fix is to use fromNow() (no arg) and, if UTC is required, dayjs.utc(dateString) with the utc plugin.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/pages/plugin/plugin.view.js
Line: 52:80

Comment:
[P1] `fromNow(true)` drops the “ago/in …” suffix, changing UI text

In `formatUpdatedDate`, `moment.utc(dateString).fromNow()` previously returned strings including the suffix (e.g., `"5m ago"`). With Day.js you’re currently doing `updateTime.fromNow(true)`, which returns *only* the distance (e.g., `"5m"`) and will never append `past`/`future` strings (so the `past: "%s ago"` config won’t apply). This changes the displayed `packageUpdatedAt` text.

Also, `moment.utc(dateString)` preserved UTC semantics; `dayjs(dateString)` will parse in local time unless the input includes a timezone offset. If `package_updated_at` is UTC and doesn’t include an offset, this can skew the relative time.

A minimal fix is to use `fromNow()` (no arg) and, if UTC is required, `dayjs.utc(dateString)` with the `utc` plugin.


How can I resolve this? If you propose a fix, please make it concise.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request successfully replaces the unmaintained moment library with dayjs. The dependency changes in package.json and package-lock.json are correct. However, I've identified a critical issue in src/pages/plugin/plugin.view.js where replacing moment.utc() with dayjs() could lead to incorrect date parsing due to timezone differences. I've also pointed out an opportunity to improve performance and fix a minor display bug by moving the dayjs locale configuration out of a frequently called function. Overall, a good refactoring with a couple of important adjustments needed.

@UnschooledGamer
Copy link
Member

While Moment.js is unmaintained it's API is pretty much good considerably. The Moment.js is a Pretty Much Done on its base Feature set. Also, Moment.js explained this better in their docs here -> https://momentjs.com/docs/#/-project-status/

@hyperz111
Copy link
Contributor Author

hyperz111 commented Feb 2, 2026

I get the moment replacement from this

@bajrangCoder
Copy link
Member

I don't think there is need for this change.

@hyperz111
Copy link
Contributor Author

hyperz111 commented Feb 2, 2026

I don't think there is need for this change.

I get this build size difference.

Before:

$ du -sh www/build
5.9M    www/build

After:

$ du -sh www/build
5.6M    www/build

@UnschooledGamer
Copy link
Member

I don't think there is need for this change.

@bajrangCoder, I think you should read https://momentjs.com/docs/#/-project-status/ before making a decision, also considering the package of moment.js (~4 mb) and dayjs being <1 mb

@hyperz111
Copy link
Contributor Author

@bajrangCoder, what about this?

@UnschooledGamer

This comment has been minimized.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@UnschooledGamer
Copy link
Member

@greptileai

Copy link
Member

@UnschooledGamer UnschooledGamer left a comment

Choose a reason for hiding this comment

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

LGTM, Great.

@UnschooledGamer UnschooledGamer merged commit 250acd0 into Acode-Foundation:main Feb 15, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants