New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Chore: migrate away from moment.js #13372
Comments
i agree this issue. migrate from momentjs to dayjs |
Cool. Why dayjs specifically? Moment recommends the following options:
|
dayjs was almost the same as momentjs in usage.
it's not a coercion. just a suggestion. :) |
|
The 'dayjs' and 'date-fns' has differences seem to be in usage. |
This issue has been automatically marked as stale because it has been open for 7 days without activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment or remove the "stale" label. 🙂 |
@sdepold The bot said 7 days but closed it after 5. Not fair! 😂 |
The bot... Little liar :) I'll get back to you later today! |
This issue has been automatically marked as stale because it has been open for 14 days without activity. It will be closed if no further activity occurs within the next 14 days. If this is still an issue, just leave a comment or remove the "stale" label. 🙂 |
@sdepold Hi! Looks like we haven't made contact. |
@sdepold Please make a decision. Which dates library do we want to migrate to (if at all)? |
Personally I would go with date-fns. It manipulates the normale Date object. It is a bigger refactor than moving to Day.js but it has my personal preference |
Apparently this is also mentioned in the meetings backlog, not sure why GitHub did not show that; https://github.com/sequelize/meetings/projects/1#card-73600663 |
Any particular reasons against day.js? I don't have any strong opinion really, however I library that is 2kb and similar to the currently used lib seems relatively good to me |
Nothing in particular, date-fns just seems more interesting to me. But I'm fine with either. |
I know this discussion hasn't been commented on in a while, but I would advocate for day.js. Date-fns is great, but it can't handle timezones like moment and moment-timezone does. I just tried to convert all my moment objects over to Date objects and using date-fns to handle the manipulation part and it became a nightmare (Once your string is converted to a Date object it now has the server timezone which creates all kinds of problems when trying to format, parse, and manipulate). Day.js has it built into the package just like moment did and seems like would work better to help migrate away from moment. |
Also if you want I could see how it goes and make a PR with the migration to day.js? |
What about sticking with moment until native Temporal is shipped? Sounds like a lot of work for something that's going to be migrated again soon after. |
@ephys I can get on board with the Temporal Proposal, but I didn't know what kind of time frame it was going to be on. My goal was to just help migrate from moment, which has been deprecated for a while to something more supported and stable. |
I agree, we can't know how long it's going to be. And I'm not pro using the polyfill before Temporal gets unflagged in at least some engines (just in case). I suppose Dayjs (or alternative lib) it is |
Hearing this I think day.js would be better then. Looking forward to see a PR with the migration. Temporal would be nice but I don't think we can really use it until the end of 2022 (or later) |
Discussed in our Monthly Sequelize sync: Let's do the drop-in replacement with day.js. Given it's only 2kb in size, we will stay with it till the Temporal API is available. @bach942 Would you be interested in filing a PR? |
Nice one :) Yes please ping me or add a link to the PR here :) |
@sdepold I've been prepping to work on the story and noticed that we support moment objects being saved. This story would essentially remove that support for that (they would have to convert it to a date or string object?). Just wondering how I should proceed with this? |
Could we detect that this thing is a moment object and extract the respective core date object out of it? If it is too much hassle to support moment objects, we could also just drop support for that and a note on the v7 breaking changes list. @ephys please share your code to detect the moment object :) |
@sdepold I noticed we had lots of places that use the moment.isMoment. If we move to Dayjs we could check to see if the "typeof is an object" but couldn't use the "instance of Moment" since the class wouldn't exist in the repo anymore. Unless @ephys has a different way of detecting the Moment object. |
It's not perfect but since Moment is not going to change anymore it may be fine. We could detect something is a moment object by doing this:
And, if a specific method needs to be called on it, check whether it exists first:
But that's only if it's not too much work, otherwise we can just drop moment support. It's possible some of the places that use One of the places where it would be easy enough to preserve moment support would be here: |
|
That's true. and checking |
Why was Sequelize coupled to Moment in the first place? What is the functionality we're talking about dropping support of? |
Probably because it used to be the most popular way of handling dates in JS when this was introduced. The functionality in question is the ability to assign a moment object to an attribute, having it be serialized and saved to the database just like if it were a Date object. (you could also use them in |
I think it would be good to decouple Sequelize from Moment (has to be a date object or string to save), but also I didn't want to break functionality or change the roadmap if this was something that the team wanted to keep. |
This will be included starting with v7, so it's fine to drop moment support :) |
Agreed. Let's drop it! |
Seems that we have lost some traction here. What are we even using moment.js for? Should we just keep it as is until the Temporal API is implemented natively? Would Temporal actually be added to older versions of Node or only in the super latest version of Node? The core team is NOT going to work on this anymore but rather remove the external dependency altogether once Temporal lands in Node. |
So I was actually wondering if putting day.js for moment.js is the right path. There is some logic to apply a timezone using moment-timezone, but wondering why Sequelize does that at all. It might be better to just use Date or String classes to save data to various databases (Either using ISO or standard date formats). I started the process of conversion, but wondered why Sequelize is doing some of this logic. |
Quick search link for some of the moment objects: https://github.com/sequelize/sequelize/search?p=1&q=moment |
It's related to the
However, this second behavior has been part of the code base for a very long time and removing it will annoy a lot of people. I was already planning on deprecating
|
Another option would be to:
This will do a few things:
That is, assuming that the Sequelize API doesn't explicitly communicate in Moment objects. |
Moment isn't used in Sequelize enough to warrant implementing a delegation mechanism. It's only referenced 71 times in the source code, and 87 times in tests. The only part of the code that uses moment in any observable capacity is in DataTypes: It has built-in support for saving moment objects to the database. But we've already decided that this will be removed. No matter which solution we decide to use (but it seems settled that it will be dayjs), it needs to support time zones as I already plan on deprecating To sum things up a bit:
|
I wish we can move to dayjs instead, see the reason why.
|
As I said, we'll accept a PR to migrate to migrate to dayjs, and you're free to make one, but the final implementation will use Temporal once it's available for the simple reason that it's the built-in library |
Wise choice to choose both long run and sustainability! |
I agree that this change would be nice. |
Sure :) |
🎉 This issue has been resolved in version 7.0.0-alpha.13 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Issue Creation Checklist
Issue Description
Moment.JS is in maintenance mode, + it's a pretty old package which doesn't play well with modern build pipelines.
I propose we migrate away from MomentJS to something else, like date-fns or something else.
Additional context
Moment.JS docs say the following:
Issue Template Checklist
Is this issue dialect-specific?
Would you be willing to resolve this issue by submitting a Pull Request?
The text was updated successfully, but these errors were encountered: