'How to use luxon Datetime.fromFormat when time zone is in the date string?

We have run into a bug in our UI using luxon.DateTime. currently the code looks like this:

DateTime.fromFormat(input, "yyyy-MM-dd'T'TT 'GMT'").toFormat(format);

The problem is that this is explicitly looking for GMT time. We also get UTC times and when that happens the code fails to generate a proper time.

I'm trying to figure out the cleanest way to specify the section of the input time that corresponds to 'GMT' or 'UTC' should be treated as a zone.

The best option I could come up with is a regex to pull out the zone from the input string, and then specify it in the options passed to fromFormat, but that seems cumbersome. Surely there is a cleaner solution I'm just too incompetent to find in the luxon API?

...this would be so much easier if the backend just passed us Linux time instead of a random string for a timestamp. Linux time is your friend people, use it!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source