micropython-lib icon indicating copy to clipboard operation
micropython-lib copied to clipboard

datetime: Add default utc tz for datetime.now().

Open ThinkTransit opened this issue 2 years ago • 3 comments

This is a reauthor of #561

The datetime module doesn't support naive datetimes and throws an unimplemented error when calling some of the methods such as datetime.now().

Rather than passing a tz object to these methods on each call I feel it would be best to use a default tz (utc) when a tz isn't provided. This would be more CPython compliant for the end user.

This pr adds a default utc timezone in fromtimestamp() if no tz is supplied.

Signed-off-by: Patrick Joy [email protected]

ThinkTransit avatar Nov 09 '22 03:11 ThinkTransit

+1, it would be good to have at least something, like the previous implementation which also had shortcomings but at least had a functioning now()

stinos avatar Dec 07 '22 15:12 stinos

@jimmo @dpgeorge any chance we can get this one reviewed/merged? I imagine datetime.now() would be one of the more common methods in the datetime library and it would be good to support it and match cpython.

ThinkTransit avatar Feb 12 '23 12:02 ThinkTransit

I'm not in favor of this merge. From CPython 3.11.5 documentation, datetime.now() is expected to return the current local date and time. MicroPhython doesn't have any notion of local timezone, yet. Current library behaviour is correct, IMHO. User shall provide a valid date and time. Or, if/when discussion 12378 leads to a proper timezone support, datetime.now() results will be different.

lorcap avatar Sep 18 '23 19:09 lorcap