You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Convert it to local time with a fixed offset (time_local)
Convert the local time with a fixed offset to a naïve local time.
Convert naïve local time to a local time with a fixed offset.
The problem is that step 3 doesn't work properly because step 2 isn't setting fold=1. This is understandable, since the fixed offset zone doesn't needfold=1, but because time_utc.astimezone(None) creates a fixed-offset aware local time, we're not really providing a good way to go from an aware local time to a naïve local time (one that you can, e.g. do wall-time arithmetic on). It seems like the best way to go from aware → naïve local time is via .timestamp:
It's not especially obvious that this is the right way to do it. I think the right way forward here is one of the following options:
Set fold on the result of .astimezone() so that .replace(tzinfo=None) gives you a "naïve local time".
Add some mechanism to get a naïve local time from an aware datetime (in retrospect, it seems like maybe the current behavior should be the result of calling .astimezone with some LOCAL sentinel object, and .astimezone() should do what I'm asking for here, but it seems that ship has sailed). I guess this could either be a special sentinel or a new method like .asnaive() or .aslocal() or something.
Both 1 and 2.
I'm leaning towards starting with 1 if there's no fundamental reason we can't do it that way.
At work today someone presented this problem (run with TZ=America/Los_Angeles):
I think this is supposed to be equivalent to:
time_utc
)time_local
)The problem is that step 3 doesn't work properly because step 2 isn't setting
fold=1
. This is understandable, since the fixed offset zone doesn't needfold=1
, but becausetime_utc.astimezone(None)
creates a fixed-offset aware local time, we're not really providing a good way to go from an aware local time to a naïve local time (one that you can, e.g. do wall-time arithmetic on). It seems like the best way to go from aware → naïve local time is via.timestamp
:It's not especially obvious that this is the right way to do it. I think the right way forward here is one of the following options:
fold
on the result of.astimezone()
so that.replace(tzinfo=None)
gives you a "naïve local time"..astimezone
with someLOCAL
sentinel object, and.astimezone()
should do what I'm asking for here, but it seems that ship has sailed). I guess this could either be a special sentinel or a new method like.asnaive()
or.aslocal()
or something.I'm leaning towards starting with 1 if there's no fundamental reason we can't do it that way.
@abalkin Any thoughts on this?
(Tangentially related: #83861)
The text was updated successfully, but these errors were encountered: