msgspec icon indicating copy to clipboard operation
msgspec copied to clipboard

Parse dates as datetimes

Open joouha opened this issue 7 months ago • 0 comments
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?

joouha avatar Apr 18 '25 10:04 joouha