you-dont-need / You-Dont-Need-Momentjs

List of functions which you can use to replace moment.js + ESLint Plugin
MIT License
13.27k stars 318 forks source link

Equivalent for moment.utc APIs #73

Open stof opened 5 years ago

stof commented 5 years ago

momentjs supports using it either in the local timezone or in the UTC timezone. But this repo only gives alternatives for the local timezone case. It would be great to have alternatives for the UTC case too.

tracker1 commented 5 years ago

This will give you a date as the UTC equivolent, which you can then format to your liking.

new Date(originalDate.toJSON().replace(/Z/,''))
stof commented 5 years ago

Well, the thing is, a startOfDay working in UTC is not meant to give the same result than a startOfDay running in local timezone (as one would put it at midnight UTC and the other one at midnight local time). That kind of things is working fine with moment.utc APIs (and you can still get an ISO string out of it after all the manipulations)

tracker1 commented 5 years ago

Well, this being an open project on Github, you're more than welcome to contribute a more thorough pull request, since you understand the underlying library's behavior better.

tracker1 commented 5 years ago

Also, there are lots of examples of Luxon, which is a successor to MomentJS.

stof commented 5 years ago

well, the thing is, I don't know what the equivalent of these moment.js APIs are for each of the alternative libraries (which I don't know well). I was hoping that your website could give me the answer :smile:

In the current state of my knowledge, I do need momentjs to achieve my goal.

tracker1 commented 5 years ago

I'd suggest at least looking at Luxon and see if it does what you need. It's by the moment js developers, just newer, safer, smaller and cleaner.

I don't work on this library, just one of many repositories I watch