DemocracyLab / CivicTechExchange

https://www.democracylab.org
MIT License
97 stars 64 forks source link

Replace moment.js with date-fns #973

Open PeterBreen opened 1 year ago

PeterBreen commented 1 year ago

Short version: load date-fns directly, replace functions which use moment.js with date-fns, remove moment from our package.json, double check that all existing datetime functions still work as expected.

Longer version:

Moment.js is quite large (the two biggest pieces of our bundle, per this analysis of package.json, are moment) and the maintainers themselves suggest moving to an alternative.

We use moment in quite a few places and any replacement must be able to handle all of them. The reason I specify date-fns is it's already a dependency of react-datepicker, which we also use and want to keep at this time. Unless there's a critical reason not to use it, loading one datetime library is better than two.

To sum up, in order for this issue to be resolved,

resources

These may help with the process:

PeterBreen commented 1 year ago

When tackling this issue, I'd suggest extending the use of our datetime utility component, seen here: https://github.com/DemocracyLab/CivicTechExchange/blob/master/common/components/utils/datetime.js - as you can see it already has a few functions, but there's more we could put in here.

If we can collect all our datetime needs and create reusable functions here and use them in the actual page components, future upgrades or changes to our datetime library will be editing one file in one place, not a dozen files in a dozen places.

BQingFan commented 1 year ago

Could I try to solve this issue? I just finished environment set up.

PeterBreen commented 1 year ago

Could I try to solve this issue? I just finished environment set up.

Absolutely. I'll assign you, feel free to reach out if you're having trouble. There's a lot of components we use moment for, but hopefully it'll make sense how they operate.

caveman0612 commented 1 year ago

I was wondering if I could try to work on this issue?

PeterBreen commented 1 year ago

I was wondering if I could try to work on this issue?

Sure, please do. I checked with Marlon and we think it's open for the taking so it's all yours.

Kive1ru commented 1 year ago

Is this issue solved? Can I try to work on this issue if not solved?

PeterBreen commented 1 year ago

PR #1035 solves this issue, pending a couple bugfixes. I believe Kyle's still working on it.