Skip to content

Extract format from ISO 8601 string date #1119

Answered by icambron
StephaneAlie asked this question in Q&A
Discussion options

You must be logged in to vote

Luxon doesn't have anything like that built in. The ISO parser, as you noticed, is a big regex. It doesn't have a way to translate the matching parts back to format tokens because the regex only captures as much information as is needed to build the DateTime. So the info of exactly which ISO variant was used is lost.

So I think you'll need a non-Luxon-based approach, where you separately parse the format and keep that format with the DateTime until you need to serialize. I'll leave it to other commenters to suggest how to best do that, and whether there are good libraries to do it with.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by StephaneAlie
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants