dalelotts / angular-bootstrap-datetimepicker

Native Angular date/time picker component styled by Twitter Bootstrap
http://dalelotts.github.io/angular-bootstrap-datetimepicker/
MIT License
1.28k stars 409 forks source link

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

Open konuch opened 4 years ago

konuch commented 4 years ago

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 commented 4 years ago

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?

jenswet commented 4 years ago

@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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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

dalelotts commented 4 years ago

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.