473,749 Members | 2,443 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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"

I'm not sure what the
day of a year

would be???

Sheila King
http://www.thinkspot.net/sheila/
Jul 19 '05 #1
5 2943
Sheila King said unto the world upon 2005-04-22 02:45:
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.strfti me("%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"

I'm not sure what the
day of a year

would be???

Sheila King
http://www.thinkspot.net/sheila/


The day of the year is the ordinal number of the day, counting from
Jan. 1st. So, Feb. 1st is the 32nd day, Dec 31 the 365/6 (depending on
leap year).

The docs for the time module indicate that the 8th (counting from 1)
position of a struct_time is the day of the year, and that it can
range from 1-366. So, naturally, the 0 value in your 8th position is
the problem.

That does leave the mystery of why your code worked on 2.2.2; I've no
idea. The docs do seem to indicate that there were a number of changes
at 2.2, though.

Best,

Brian vdB
Jul 19 '05 #2
[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


From the docs for time.strptime:
"The default values used to fill in any missing data are (1900, 1, 1, 0, 0,
0, 0, 1, -1) ".

So, you could change the offending code line to:
strftime("%Y-%m-%d", (Y, M, D, 0, 0, 0, 0, 1, -1) ) '2005-05-15'

Since the rules for handling missing, inconsistent, or out-of-range tuple fields
are not defined, even that revision has some risk. To future-proof the code,
use strptime() to generate a well-formed time tuple:
strptime('%d-%d-%d' % (y,m,d), '%Y-%m-%d') (2005, 5, 15, 0, 0, 0, 6, 135, -1) strftime("%Y-%m-%d", _)

'2005-05-15'

This somewhat circular technique sticks with the documented API but allows you
to access all of the time module's options (like accessing the locale's names
for days of the week and months of the year).
Raymond Hettinger



Jul 19 '05 #3
Raymond Hettinger wrote:
Since the rules for handling missing, inconsistent, or out-of-range tuple fields
are not defined, even that revision has some risk. To future-proof the code,
use strptime() to generate a well-formed time tuple:
strptime('% d-%d-%d' % (y,m,d), '%Y-%m-%d')
(2005, 5, 15, 0, 0, 0, 6, 135, -1)
strftime("% Y-%m-%d", _)
'2005-05-15'


or use datetime.date which only needs y, m, d:
from datetime import date
d=date(2005, 5, 15)
d.strftime("%Y-%m-%d")

'2005-05-15'

Kent
Jul 19 '05 #4
[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.
Jul 19 '05 #5
Hello,

Thank you to all who replied. Yes, obviously the extra values I'm passing are
out of range, such as the ordinal day-number of the year. Oy.

I've been having a number of issues with switching from 2.2.2 to 2.4.1 and
last night when I started trying to address this problem (at a late hour) I'm
afraid my thunker sure wasn't thunking.

I like the datetime.date suggestion best, probably.

Again, thanks, and this will help me to get through this niggle...

Sheila King
http://www.thinkspot.net/sheila/

On Fri, 22 Apr 2005 05:26:02 -0700, Kent Johnson wrote
(in article <42**********@n ewspeer2.tds.ne t>):
Raymond Hettinger wrote:
Since the rules for handling missing, inconsistent, or out-of-range tuple
fields
are not defined, even that revision has some risk. To future-proof the
code,
use strptime() to generate a well-formed time tuple:
> strptime('%d-%d-%d' % (y,m,d), '%Y-%m-%d')


(2005, 5, 15, 0, 0, 0, 6, 135, -1)
> strftime("%Y-%m-%d", _)


'2005-05-15'


or use datetime.date which only needs y, m, d:
>>> from datetime import date
>>> d=date(2005, 5, 15)
>>> d.strftime("%Y-%m-%d")

'2005-05-15'

Kent

Jul 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
9443
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $ Last-Modified: $Date: 2003/10/28 19:48:44 $ Author: A.M. Kuchling <amk@amk.ca> Status: Draft Type: Standards Track
1
2256
by: Allen Unueco | last post by:
I feel that the '%Z' format specifier from strftime() returns the wrong value when daylight savings is in effect. Today the following is always true: time.strftime('%Z') == time.tzname Shouldn't it be: time.strftime('%Z') == time.tzname -allen
4
9340
by: John Hunter | last post by:
>>> from datetime import date >>> dt = date(1005,1,1) >>> print dt.strftime('%Y') Traceback (most recent call last): File "<stdin>", line 1, in ? ValueError: year=1005 is before 1900; the datetime strftime() methods require year >= 1900 Does anyone know of a datetime string formatter that can handles strftime format strings over the full range that datetime objects support?
4
2912
by: Andy Leszczynski | last post by:
Python 2.2/Unix >>time.strftime("%T") '22:12:15' >>time.strftime("%X") '22:12:17' Python 2.3/Windows >>time.strftime("%X")
8
13620
by: Adam Monsen | last post by:
Anyone know of something that works like time.strptime(), but for other languages? Specifically, Dutch (ex: "31 augustus 2005, 17:26") and German? Thinking out loud... since "31 augustus 2005, 17:26" is only different by month name, I suppose I could just substitute the month name using a translation table for English to Dutch month names. -- Adam Monsen
5
2287
by: Swansea University Psychology | last post by:
Hi all, I have a utility that uses the C library function strftime() to return the time zone name, but it returns "GMT Standard Time" on one computer, and "BST" (which it should be at the moment) on the other computer. Both PCs are Windows XP Pro Service Pack 2. Both have their time zone set to GMT +0 (London). And in the Date & Time control panel applet, both show "GMT Standard Time" as the Current time zone. Both have the correct...
20
12602
by: Jean Johnson | last post by:
Hello - I have a start and end time that is written using the following: time.strftime("%b %d %Y %H:%M:%S") How do I calculate the elapsed time? JJ
5
1338
by: HMS Surprise | last post by:
I wish to generate a datetime string that has the following format. '05/02/2007 12:46'. The leading zeros are required. I found '14.2 time' in the library reference and have pulled in localtime. Are there any formatting functions available or do I need to make my own? Perhaps there is something similar to C's printf formatting. Thanks,
2
3365
by: Steve | last post by:
Hi All, I've been trying to come up with a good way to run a certain process at a timed interval (say every 5 mins) using the SLEEP command and a semaphore flag. The basic thread loop was always sitting in the sleep command and not able to be interrupted. When the time came to set the semaphore flag to false (stopping the thread), my program would have to wait up to the entire sleep time to break out of the loop. I have finally found...
0
8832
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9333
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8256
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6800
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3319
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.