-
Hi all! The docs mention custom zones and say this is an advanced topic. I've searched this repo and elsewhere and can't find any examples. I'm porting some C# code from my company to typescript and using luxon as a replacement for dotnet's DateTime. We have custom time zones for some of the energy markets we work with, so in our code we can use specify a "MISO" or "SPP" time zone. Some of these are fixed zones. MISO uses US Eastern Standard Time year round. Is it possible to define these zones for use with luxon, and if so, how would I do that? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
To make a custom zone, you write an implementation of the Zone interface. Then you can pass instances of that object anywhere that takes zone for an argument. Luxon's own zones do the same thing, with additional convenience that we've aliased strings to them so that, say, If you are OK passing a different kind of thing, you might not have to do much of anything, except something like: const MISO = FixedOffsetZone.instance(-4 * 60);
const SPP = "America/Chicago"; and then pass those values into anything that accepts zone as an argument. However, if what you're after is being able to pass the strings "MISO" and "SPP" as args, then that isn't currently possible to customize. I hope that helps! |
Beta Was this translation helpful? Give feedback.
To make a custom zone, you write an implementation of the Zone interface. Then you can pass instances of that object anywhere that takes zone for an argument. Luxon's own zones do the same thing, with additional convenience that we've aliased strings to them so that, say,
setZone("utc")
is equivalent tosetZone(anInstanceOfUTCZone)
.If you are OK passing a different kind of thing, you might not have to do much of anything, except something like:
and then pass those values into anything that accepts zone as an argument.
However, if what you're after is being able to pass the strings "MISO" and "SPP" as args, the…