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: datetime.date won't accept 08 or 09 as valid days.
Type: Stage:
Components: Library (Lib) Versions: Python 2.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: alanmcintyre, erikcw, fdrake
Priority: normal Keywords:

Created on 2007-05-08 21:49 by erikcw, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg31987 - (view) Author: Erik Wickstrom (erikcw) Date: 2007-05-08 21:49
The method won't accept 08 or 09 as valid days, but will accept 07.

Here is my output:

Python 2.5.1c1 (release25-maint, Apr 12 2007, 21:00:25)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> t = datetime.date(2007, 05, 07)
>>> print t
2007-05-07
>>> t = datetime.date(2007, 05, 08)
  File "<stdin>", line 1
    t = datetime.date(2007, 05, 08)
                                 ^
SyntaxError: invalid token
>>> t = datetime.date(2007, 05, 09)
  File "<stdin>", line 1
    t = datetime.date(2007, 05, 09)
                                 ^
SyntaxError: invalid token
>>> t = datetime.date(2007, 05, 10)
>>> print t
2007-05-10
>>>

I was able to reproduce this on another machine as well:
Python 2.4.3 (#1, Aug  6 2006, 20:52:01)
[GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
msg31988 - (view) Author: Alan McIntyre (alanmcintyre) * (Python committer) Date: 2007-05-08 22:24
Recommend closing this as not a bug.

A number with a leading zero is interpreted as octal literal, so trying to interpret 08 gives an error, since anything bigger than 7 isn't allowed in octal numbers.  For your examples above, you should do this:

t = datetime.date(2007, 5, 8)
t = datetime.date(2007, 5, 9)

and then it works as expected. 

msg31989 - (view) Author: Fred Drake (fdrake) (Python committer) Date: 2007-05-09 03:45
Agreed -- not a bug.
History
Date User Action Args
2022-04-11 14:56:24adminsetgithub: 44944
2007-05-08 21:49:32erikcwcreate