luxon icon indicating copy to clipboard operation
luxon copied to clipboard

DateTime.now() with timezone parameter

Open adamreisnz opened this issue 3 years ago • 3 comments

Is your feature request related to a problem? Please describe. We often work with specific timezones, and need to create DateTime instances in a specific timezone. As far as I understand, the only way to currently do that would be something like: DateTime.now().setZone(zone)

However, this is inefficient as it always requires an extra call to setZone() and always causes a redundant instance of DateTime to be created in local time only to be thrown away right after.

Describe the solution you'd like Ideally, I'd like to see something like DateTime.now(zone), e.g. allowing you to pass in a zone parameter into the now() method.

Describe alternatives you've considered AFAIK the only current alternative is simply DateTime.now().setZone(zone)

adamreisnz avatar May 07 '21 21:05 adamreisnz

If it's a perf thing, this does it in one go:

const zone = "Europe/London"
DateTime.fromObject({zone})

Since that's not a very obvious API, I think we can consider adding this option to now into 2.0, which reconsiders how to use options like zone (I don't want to add it now and then just have to change it in 2.0).

icambron avatar May 14 '21 04:05 icambron

Happy for it to go into 2.0. What's the current timeline on that, or is that still far off?

adamreisnz avatar May 14 '21 04:05 adamreisnz

@icambron Is there any information (milestones, blog posts, etc) about 2.0? I'm curious what the major changes will be.

9mm avatar May 14 '21 16:05 9mm