Is there no way to parse an ISO datetime object in MicroPython? My Raspberry Pi Pico calls a REST API that contains date items in the ISO 8601 format:
{"title":"Green","date":"2023-10-18T00:00:00"}
but MicroPython only appears to have a time function, not a datetime function and the time function doesn't seem to be capable of parsing strings.
I basically need to turn ISO strings into "Wednesday 18" for example.
There's an algorithm for determining the day of the week for a given date that works for dates back to 1753.
Output:
EDIT: There is a simpler way to solve this using the
time
module in Python orutime
in Micropython. January 1 2000 fell on a Saturday. This piece of information along with the number of days to the date to be parsed can be used to calculate the week day.Python's
time.mktime()
function takes a tuple containing 9 elements corresponding tostruct_time
as an argument and returns the seconds passed since epoch (1 January 1970).Saturday, 1 January 2000 was 10,957 days after Thursday, 1 January 1970. The
86400
and10957
constants can be used to save a little bit of computing power on the micro processor.