Datetime API: No atomic way to get "aware" current local datetime when moving between time zones

Thanks. I think one simple solution would be to support something like datetime.now(tz=timezone.local), where timezone.local is not an actual tzinfo instance but rather a sentinel value that tells now() that we want an aware instance of current local time (this also avoids having tzinfo objects that change their behavior depending on location, as
@pganssle has written about). This would produce the same behavior as now(tz=None) followed by astimezone(), except it would not require querying the system local time multiple times.

Edit: I just came across a similar discussion topic which proposed the same API improvement but without going into the problems associated with moving across time zones. I don’t know if it is possible to link discussions (apologies, I’m new here).

4 Likes