Skip to content

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

Closed
ThinkTransit wants to merge 3 commits into
micropython:masterfrom
ThinkTransit:datetime_now
Closed

datetime: Add default utc tz for datetime.now().#570
ThinkTransit wants to merge 3 commits into
micropython:masterfrom
ThinkTransit:datetime_now

Conversation

@ThinkTransit

Copy link
Copy Markdown
Contributor

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 patrick@joytech.com.au

Signed-off-by: Patrick Joy <patrick@joytech.com.au>
@stinos

stinos commented Dec 7, 2022

Copy link
Copy Markdown

+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()

@ThinkTransit

Copy link
Copy Markdown
Contributor Author

@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.

@lorcap

lorcap commented Sep 18, 2023

Copy link
Copy Markdown
Contributor

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.

@dpgeorge

dpgeorge commented Jul 1, 2026

Copy link
Copy Markdown
Member

This has been superseded by #1045. datetime.datetime.now() is now working.

@dpgeorge dpgeorge closed this Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants