Nov-15-2019, 06:37 PM
I have found the result of the datetime 'dst' funtion to be confusing. If I create a datetime object this way:
import datetime, pytz
myDate = datetime.datetime.now(tz=pytz.timezone("US/Eastern"))
and then type
print(myDate.timetuple().tm_isdt)
I get a '0', which correctly means that my date/time is not during daylight saving time. But then I create a new date with
newDate = myDate - datetime.timedelta(days=180)
which gives me a date/time on May 19, 2019. But if I type
print(newDate.timetuple().tm_isdt)
I still get a '0' even though my new date is during daylight saving time. Or, more practically, the statement
print(myDate.dst() == newDate.dst())
results in 'True' even though one date was during daylight saving time and the other wasn't. Is there a way to avoid this confusion (other than limiting any usage of the 'dst' function to the line immediately after a datetime object is created)?
import datetime, pytz
myDate = datetime.datetime.now(tz=pytz.timezone("US/Eastern"))
and then type
print(myDate.timetuple().tm_isdt)
I get a '0', which correctly means that my date/time is not during daylight saving time. But then I create a new date with
newDate = myDate - datetime.timedelta(days=180)
which gives me a date/time on May 19, 2019. But if I type
print(newDate.timetuple().tm_isdt)
I still get a '0' even though my new date is during daylight saving time. Or, more practically, the statement
print(myDate.dst() == newDate.dst())
results in 'True' even though one date was during daylight saving time and the other wasn't. Is there a way to avoid this confusion (other than limiting any usage of the 'dst' function to the line immediately after a datetime object is created)?