question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

datetime parsing does not handle generic ISO-8601 strings

See original GitHub issue

Currently the generated from_dict code calls datetime.fromisoformat():

https://github.com/Fatal1ty/mashumaro/blob/53cd94c34006aff7f8b4eaa29d7b5d7037ee4bfd/mashumaro/serializer/base/metaprogramming.py#L468-L471

fromisoformat is only designed to invert the strings generated by datetime.isoformat():

This does not support parsing arbitrary ISO 8601 strings - it is only intended as the inverse operation of datetime.isoformat(). A more full-featured ISO 8601 parser, dateutil.parser.isoparse is available in the third-party package dateutil.

According to mashumaro’s documentation:

use_datetime: False  # False - load datetime oriented objects from ISO 8601 formatted string, True - keep untouched

I believe it should be within mashumaro’s scope to handle generic ISO-8601 strings

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
movermeyercommented, Nov 21, 2022

As of Python 3.11, datetime.fromisoformat can handle all the important bits of the ISO 8601 spec.

I’ll be backporting its code in https://github.com/movermeyer/backports.datetime_fromisoformat/issues/21, so it’ll be available for earlier versions of Python 3.

FWIW, ciso8601 is still faster than any other parser.

0reactions
Bao-gxgcommented, Jan 5, 2021

Perfect. I’ll test it out soon, thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Generic support for ISO 8601 format in Java 6 - Stack Overflow
Can we parse all the offset formats using the same formatter? When reading mixed data, you don't want to handle each offset format...
Read more >
DateTime and DateTimeOffset support in System.Text.Json
NET's extensive support for parsing various DateTime and DateTimeOffset text formats, including non-ISO 8601 strings and ISO 8601 formats ...
Read more >
Parsing ISO8601 dates and times - the Tcler's Wiki!
The clock command has always asserted in the documentation of its free-form parser that it is capable of parsing ISO 8601 date/time strings....
Read more >
15 Formatting and Parsing - Racket Documentation
Parses a non-standard format, consisting of an ISO 8601 combined date and time representation and an IANA time zone ID in brackets, into...
Read more >
Formatting Dates and Times | ICU Documentation
Date/Time Format Syntax. A date pattern is a string of characters, where specific strings of characters are replaced with date and time data...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found