Skip to content
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

Use dayjs or date-fns instead of Moment.js #449

Open
konuch opened this issue Nov 29, 2019 · 6 comments
Open

Use dayjs or date-fns instead of Moment.js #449

konuch opened this issue Nov 29, 2019 · 6 comments

Comments

@konuch
Copy link

konuch commented Nov 29, 2019

Please describe the feature you would like to request.

Remove the moment.js library requirement. Allow usage of different datetime library, if necessary.

What is the use-case or motivation for this proposal?

Moment.js is a great library, but it has some problems, one of them being too huge. There are other libraries, like dayjs or date-fns that address moment.js issues and preserve pretty much the same API. See https://github.com/you-dont-need/You-Dont-Need-Momentjs

Is there anything else I should know?

@dalelotts
Copy link
Owner

dalelotts commented Nov 29, 2019

I have not actually implemented this myself but it should be done already. I designed this so you can use any library other than moment. Just write your own implementations of DlModelProvider for each of the views using any library you like. Then override the classes I provide with your own providers.

Given that I haven't actually done this, you may run into some issues but they should be easy to fix.

I would happily accept your merge request with some additional modules using other date libraries so that others can benefit from your work.

Since you mention size and not performance, I'm curious about your use case. How does a ~50k savings in gzip size impact your application?

@dalelotts dalelotts changed the title Moment.js library requirement Allow dayjs or date-fns instead of Moment.js Nov 29, 2019
@dalelotts dalelotts changed the title Allow dayjs or date-fns instead of Moment.js Use dayjs or date-fns instead of Moment.js Nov 29, 2019
@jenswet
Copy link

jenswet commented Dec 7, 2019

@konuch Did you try implementing another library? I have the same "problem". For me the size matters, because the project is deployed on the small ESP8266 storage.

@konuch
Copy link
Author

konuch commented Jan 21, 2020

Sorry for late answer, but unfortunately I haven't managed to solve it. I tried to separate momentJS from core logic by moving momentJS references to its own module and adapter files and created similar files for dayjs. I had hoped that if I import only these dayJS modules into my app, momentJS library wont be part of the final bundle, but sadly it was. As long as you export files which use momentjs lib in 'index.ts' file, momentjs becomes a required dependency of your app. Sadly, moment.js can not be tree shaken during the build process.

@dalelotts
Copy link
Owner

Hey @konuch thanks for the update. Do you have a fork of this project with your changes that you can share? I'm no expert on tree shaking but I'm happy to have a look and see if I get it working.

@dalelotts
Copy link
Owner

Waiting for some code from @konuch - will close if no response in the next week or so.

@dalelotts
Copy link
Owner

I've looked into this and know how to get this component working without moment, however, it seem to be more work than would be justified by the small number of requests I have at the moment. ha, ha! =)

Thumbs up the original post of you would like this feature.

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

No branches or pull requests

3 participants