[ python-Bugs-1643943 ] strptime %U broken
SourceForge.net
noreply at sourceforge.net
Thu Jan 25 22:33:13 CET 2007
Bugs item #1643943, was opened at 2007-01-24 15:00
Message generated for change (Comment added) made by bcannon
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1643943&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.4
>Status: Closed
>Resolution: Fixed
Priority: 5
Private: No
Submitted By: Brian Nahas (bnahas)
Assigned to: Brett Cannon (bcannon)
Summary: strptime %U broken
Initial Comment:
Python 2.4.1 (#1, May 16 2005, 15:19:29)
[GCC 4.0.0 20050512 (Red Hat 4.0.0-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from time import strptime
>>> strptime('2006-53-0', '%Y-%U-%w')
(2006, 12, 31, 0, 0, 0, 6, 365, -1)
>>> strptime('2007-00-0', '%Y-%U-%w')
(2006, 12, 24, 0, 0, 0, 6, -7, -1)
>>> strptime('2007-01-0', '%Y-%U-%w')
(2007, 1, 7, 0, 0, 0, 6, 7, -1)
>>> strptime('2007-02-0', '%Y-%U-%w')
(2007, 1, 7, 0, 0, 0, 6, 7, -1)
>>> strptime('2007-03-0', '%Y-%U-%w')
(2007, 1, 14, 0, 0, 0, 6, 14, -1)
>>>
Note that in the above test, Sunday of week 1 and week 2 for 2007 reported the date as 2007-01-07 and Sunday of week 0 was reported as 2006-12-24, not 2006-12-31. I'm not sure exactly what is correct, but the inconsistencies are bothersome.
Same results on:
Python 2.4.4c1 (#70, Oct 11 2006, 10:59:14) [MSC v.1310 32 bit (Intel)] on win32
----------------------------------------------------------------------
>Comment By: Brett Cannon (bcannon)
Date: 2007-01-25 13:33
Message:
Logged In: YES
user_id=357491
Originator: NO
Rev. 53564 (trunk) has the fix and 2.5 will as soon as a commit problem I
am having is fixed. I basically rewrote the algorithm to have a generic
calculation for the Julian day and just shifted the length of week 0 and
the day of the week based on whether %U or %W was specified. Cut out all
the other edge cases which were messy and confusing.
----------------------------------------------------------------------
Comment By: Brian Nahas (bnahas)
Date: 2007-01-25 11:39
Message:
Logged In: YES
user_id=562121
Originator: YES
No worries.
Here's what I'm doing as a work-around. I needed to convert the results
of a mysql YEARWEEK field to the sunday at the start of that week:
import datetime
def mysqlWeekToSundayDate(yearweek):
year = int(yearweek[0:4])
week = int(yearweek[4:6])
day = datetime.date(year, 1, 1)
dayDelta = datetime.timedelta(1)
weekDelta = datetime.timedelta(7)
while day.strftime("%w") != "0":
day = day + dayDelta
day = day + ((week - 1) * weekDelta)
return day
I'm relatively new to Python so it is probably not the most efficient
method but it does the job.
----------------------------------------------------------------------
Comment By: Brett Cannon (bcannon)
Date: 2007-01-25 10:50
Message:
Logged In: YES
user_id=357491
Originator: NO
I will try to fix this when I can. Just to warn you, Brian, I really
doubt I will put the effort into backporting this to 2.4.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1643943&group_id=5470
More information about the Python-bugs-list
mailing list