-
Notifications
You must be signed in to change notification settings - Fork 721
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
How to create time zones by name? #369
Comments
Not a supported way, no. Can I ask why you need a Zone instance? |
The following explanation refers both to this issue and to #368. We're planning to use Luxon as part of an Enterprise solution. Our end users regularly travel between time zones, so we're doing a lot of time zone-based calculations. For example:
Most of these tasks can somehow be accomplished with the current interface. But our code would be much clearer if we could represent time zones as objects (in the OOP sense), not just strings. This is especially true since we're programming in TypeScript. If a Zone is modelled as an abstract base class with a number of concrete implementations, TypeScript can verify we're passing the correct kind of information. If a Zone is simply a string, TypeScript isn't much help. The thing is that most of the Zone API is already exposed. Luxon currently exports the abstract base class Almost everything is already exposed. Only two pieces are missing to make complete use of these classes:
|
I thought this over and I'm good with it. If you make a PR making the zone factory public and the zone accessor public, along with docs, I'll take it. |
Thanks, I'll do that! |
Fixed in #404 |
I need to create a
Zone
object based on the time zone name, e.g., "Europe/Berlin". Looking at Luxon's code, there is a convenient functionnormalizeZone
that does just that. Unfortunately, Luxon's main module doesn't re-export this function; what's more, it is marked as@private
.Is there another way to create a
Zone
instance based on a string (and, ideally, an explicit fallback value)?The text was updated successfully, but these errors were encountered: