msgspec
msgspec copied to clipboard
Parse dates as datetimes
trafficstars
Is it possible to get the decoder to parse dates as datetimes?
Basically I'd like to be able to run
>>> from datetime import datetime
>>> msgspec.json.decode('"2024-01-01"', type=datetime)
and have it return
datetime.datetime(2024, 1, 1, 0, 0)
instead of raising
msgspec.ValidationError: Invalid RFC3339 encoded datetime
The documentation suggests that using a union of datetime | date may be possible with some work - what would this involve?