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
Let's say, I want to compare the result from tzstr.transitions() I get a TypeError (Tested with Python3.10):
fromdatetimeimportdatetime, timezoneimportdateutil.tznow=datetime.now(timezone.utc) # recommended to replace utcnow()posix_zone=dateutil.tz.tzstr("CET-1CEST,M3.5.0,M10.5.0/3")
start, end=posix_zone.transitions(2023)
now>start
Also the output of start.timestamp() will depend on the timezone the code is running.
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[27], line 7
5 posix_zone = dateutil.tz.tzstr("CET-1CEST,M3.5.0,M10.5.0/3")
6 start, end = posix_zone.transitions(2023)
----> 7 now > start
TypeError: can't compare offset-naive and offset-aware datetimes
This makes sense, as I don't want to compare UTC times with a unspecified time. A workaround for me is to set UTC manually for the returned objects. I have to assume that the native datetime object represents UTC.
start = start.astimezone(timezone.utc)
end = end.astimezone(timezone.utc)
Should dateutil return time zone aware datetime objects, now that it looks like the naive type will be phased out sooner or later?
The text was updated successfully, but these errors were encountered:
The Python
datetime
module from the standard lib supports so called "naive" and "time zone aware"datetime
objects: https://docs.python.org/3/library/datetime.html#aware-and-naive-objectsAs far as I can see,
dateutil
returns in some (all?) cases naive datetime objects. Using naive objects is discouraged (is it?) and deprecated since version 3.12 (https://blog.miguelgrinberg.com/post/it-s-time-for-a-change-datetime-utcnow-is-now-deprecated).Let's say, I want to compare the result from
tzstr.transitions()
I get a TypeError (Tested with Python3.10):Also the output of
start.timestamp()
will depend on the timezone the code is running.This makes sense, as I don't want to compare UTC times with a unspecified time. A workaround for me is to set UTC manually for the returned objects. I have to assume that the native
datetime
object represents UTC.Should
dateutil
return time zone awaredatetime
objects, now that it looks like the naive type will be phased out sooner or later?The text was updated successfully, but these errors were encountered: