monty icon indicating copy to clipboard operation
monty copied to clipboard

datetime serialization/deserialization broken

Open shyamd opened this issue 3 years ago • 2 comments

datetime objects with time zone info break the serializatin because __str__ doesn't output in the format that monty expects. Example: datetime.datetime(2018, 12, 19, 21, 45, 41, 99000, tzinfo=datetime.timezone.utc).__str__() yields "2018-12-19 21:45:41.099000+00:00"

When deserializing, this causes monty to throw an error because the two datetime formatting strings it tries are:

  • "%Y-%m-%d %H:%M:%S.%f"
  • "%Y-%m-%d %H:%M:%S"

resulting in value error like this from within strptime: ValueError: unconverted data remains: .967000+00:00

We could just add the timezone format, or just use a formatting string when outputting from datetime to a string during serialization. There are also generic datetime parsing libraries like dateutil

shyamd avatar Jun 24 '21 04:06 shyamd