![]() I’m using the native Intl for localization so you can create a DateTime and set its locale to whatever Intl.DateTimeFormat support like BCP 47 strings e.g. I’ve done my best to document the whole thing so hopefully it doesn’t need great explanation but I’ll highlight some things One quick note: A major difference between the two libraries moment.js is mutable vs day.js which is not.ĭay.add(1, day) //this is a “pure” function that returns a new instanceīecause the native date object is mutable, I decided to keep my class mutable as well. If you care about old dead browsers like Safari or IE you may want to make use of polyfills OR stop accepting requirements to use these. ![]() Note, this code works in evergreen browsers. class DateTime extends Date This is important because outside of using my DateTime class, the object is just a Date that means that all the things you can normally do with a date object, can be done to a DateTime object. Thanks to the latest version of javascript you can extend classes like the native Date class. ![]() This library doesn’t cover everything from moment.js but meets the needs of my picker, and it’s only 3kb. I decided to create my own small date library that could provide the functions from momentjs that I needed using native javascript date functions. If I was going to use these plugins in a web app or something I don’t think the additional weight would be an issue, however I didn’t think I should impose that on a developer who just wants a date picker. I ended up needing at least three additional plugins to get the same functionality in dayjs from moment. Originally, I decided to use dayjs as a replacement, I mean why not? Smaller, modern, basically drop in to replace momentjs. Dayjs (2kb) is lightweight and has nearly identical apis.Īs I am in the process of rewriting my date time picker library I’ve been evaluating my dependencies and the impact that they have on developers being able to use my picker and the pickers maintainability. Seems like a lot of people turn to dayjs as an alternative. Long live the king!īack on momentjs (18kb) added a new section to their homepage called “Project Status”, which details that the project is in maintenance mode, and they recommend against using it in new projects.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |