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
{{ message }}
Repository navigation
datetime.utctimetuple() should not set tm_isdst flag to 0 #53250
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee='https://github.com/abalkin'closed_at=Nonecreated_at=<Date2010-06-16.03:36:41.910>labels= ['easy', 'type-bug', 'docs']
title='datetime.utctimetuple() should not set tm_isdst flag to 0'updated_at=<Date2019-10-03.09:54:22.605>user='https://github.com/abalkin'
>>> from datetime import datetime
>>> import time
>>> time.strftime('%c %z %Z', datetime.utcnow().utctimetuple())
'Wed Jun 16 03:26:26 2010 -0500 EST'
As far as I can tell, the only other function that uses the tm_isdst flag is time.mktime, but it expect a timetuple containing local time, not UTC time.
With timezone.utc available in datetime module, users should be encouraged to use dt.astimezone(timezone.utc).timetuple() instead of dt.utctimetuple(). Note that the later will set tm_isdst to -1. This observation can be used to argue for either of two ways to resolve this issue:
Since utctimetuple() is no longer necessary, and the alternative works correctly, there is no need to fix it. Just recommend the astimezone use in the docs and explain the subtle difference.
Having two ways to do the same thing which have a subtle difference is not a good idea.
I am leaning towards #1, but would like to hear from others.
Just recommend the astimezone use in the docs
and recommend creating tz-aware instances in the first time (i.e. calling now(utc) instead of utcnow()), +1.
Hi,
I am new to python and would like to contribute. I find this issue easy so changed the documentation of datetime module. I tested it with sphinx. Attaching a patch.
Please let me know if it is correct or needs changes.
Appreciate it!
Regards,
Gaurav
hobbestigrou commented on Dec 3, 2018
hobbestigroumannequin
Mannequin
More actions
Please can you convert your patch to a pull request on github.
Activity
abalkin commentedon Jun 16, 2010
I find the following quite misleading:
As far as I can tell, the only other function that uses the tm_isdst flag is time.mktime, but it expect a timetuple containing local time, not UTC time.
abalkin commentedon Jun 21, 2010
With timezone.utc available in datetime module, users should be encouraged to use dt.astimezone(timezone.utc).timetuple() instead of dt.utctimetuple(). Note that the later will set tm_isdst to -1. This observation can be used to argue for either of two ways to resolve this issue:
Since utctimetuple() is no longer necessary, and the alternative works correctly, there is no need to fix it. Just recommend the astimezone use in the docs and explain the subtle difference.
Having two ways to do the same thing which have a subtle difference is not a good idea.
I am leaning towards #1, but would like to hear from others.
merwok commentedon Jun 11, 2012
abalkin commentedon Jun 29, 2014
Reclassifying this as a doc issue.
GauravTatke commentedon Dec 27, 2016
Hi,
I am new to python and would like to contribute. I find this issue easy so changed the documentation of datetime module. I tested it with sphinx. Attaching a patch.
Please let me know if it is correct or needs changes.
Appreciate it!
Regards,
Gaurav
hobbestigrou commentedon Dec 3, 2018
Please can you convert your patch to a pull request on github.
abalkin commentedon Dec 3, 2018
I submitted Gaurav's patch as PR 10870. Please review.
karlcow commentedon Oct 3, 2019
@gaurav The pull request
#10870
has been closed in favor of
#15773
which has already been merged.
So we can probably close here.