This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: strptime: wrong default values used to fill in missing data
Type: Stage:
Components: Library (Lib) Versions: Python 2.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: brett.cannon Nosy List: brett.cannon, markus_gritsch
Priority: normal Keywords:

Created on 2006-05-28 09:26 by markus_gritsch, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg28665 - (view) Author: Markus Gritsch (markus_gritsch) Date: 2006-05-28 09:26
The documentation of strptime() says: """The default
values used to fill in any missing data are (1900, 1,
1, 0, 0, 0, 0, 1, -1)""".  As the example below shows,
this is not the case.

Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310
32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for
more information.
>>> import time
>>> time.strptime('', '')
(1900, 1, 1, 0, 0, 0, 0, 1, -1)
>>> time.strptime('2006', '%Y')
(2006, 1, 1, 0, 0, 0, 6, 1, -1)
>>> time.strptime('2006-05', '%Y-%m')
(2006, 5, 1, 0, 0, 0, 0, 121, -1)
>>> time.strptime('2006-05-26', '%Y-%m-%d')
(2006, 5, 26, 0, 0, 0, 4, 146, -1)
>>> time.strptime('2006-05-26 21', '%Y-%m-%d %H')
(2006, 5, 26, 21, 0, 0, 4, 146, -1)
>>> time.strptime('2006-05-26 21:06', '%Y-%m-%d %H:%M')
(2006, 5, 26, 21, 6, 0, 4, 146, -1)
>>> time.strptime('2006-05-26 21:06:11', '%Y-%m-%d
%H:%M:%S')
(2006, 5, 26, 21, 6, 11, 4, 146, -1)
msg28666 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2006-05-28 18:29
Logged In: YES 
user_id=357491

The docs need to be fixed to say those are the default
values except when strptime() can infer better ones.  There
is a lot of smarts in the algorithm that do calculations to
fill in missing data as best as possible, and that is what
is happening here.

Thanks for the bug report.  I will try to fix this some time
this week.
msg28667 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2006-05-31 02:22
Logged In: YES 
user_id=357491

Rev. 46569 has more clear wording for HEAD and rev. 46570
has it for 2.4 .
msg28668 - (view) Author: Markus Gritsch (markus_gritsch) Date: 2006-06-04 16:57
Logged In: YES 
user_id=553904

Thank you
History
Date User Action Args
2022-04-11 14:56:17adminsetgithub: 43425
2006-05-28 09:26:13markus_gritschcreate