time.strftime in 2.4.1 claims data out of range when not

Tim Peters tim.peters at gmail.com
Fri Apr 22 09:51:54 EDT 2005


[Sheila King]
> I have a web app that has been running just fine for several months under
> Python 2.2.2.
>
> We are preparing to upgrade the server to run Python 2.4.1.
>
> However, part of my web app is throwing an error on this code (that has
> previously worked without exception):
>
> >>> time.strftime("%Y-%m-%d", (Y, M, D, 0,0,0,0,0,0))
> Traceback (most recent call last):
>  File "<stdin>", line 1, in ?
> ValueError: day of year out of range
> >>> Y
> 2005
> >>> M
> 5
> >>> D
> 15L
>
> I don't see what parts of the date that I have submitted to strftime are out
> of range?
>
> Also, the phrasing of the error message is a bit odd?
> "day of year out of range"

That was explained already, so I won't again.  The NEWS file for
Python 2.4a1 explains why:

"""
- time.strftime() now checks that the values in its time tuple argument
  are within the proper boundaries to prevent possible crashes from the
  platform's C library implementation of strftime().  Can possibly
  break code that uses values outside the range that didn't cause
  problems previously (such as sitting day of year to 0).  Fixes bug
  #897625.
"""

See the referenced bug report for examples of platforms whose
strftime()s crashed the app, or just returned utter gibberish, when
passed senseless values.  Python's strftime wrapper now verifies that
all passed-in values are in range, no longer trusting the platform C's
strftime() to do error-checking.



More information about the Python-list mailing list