Opened 14 years ago

Closed 14 years ago

Last modified 13 years ago

#14752 closed (fixed)

WeekArchiveView gives incorrect results when using weeks beginning with Monday

Reported by: Mark Sundstrom Owned by: nobody
Component: Generic views Version: dev
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

WeekArchiveView defaults to weeks defined as beginning on Sunday (the strptime '%U' format) and this works correctly. Using weeks defined as beginning on Monday ('%W'), gives incorrect results. This is because BaseWeekArchiveView.get_dated_items calls the helper function, _date_from_string, with the wrong format.

For example, for the 10th week in 2009, beginning on Sunday, it correctly constructs the following:

time.strptime('2009__0__10', '%Y__%w__%U')

However, for the 10th week in 2009, beginning on Monday, it incorrectly constructs:

time.strptime('2009__0__10', '%Y__%w__%W')

This can be fixed by using:

time.strptime('2009__1__10', '%Y__%w__%W')

The '1' refers to the day of the week being Monday (Sunday = 0).

I've attached a patch, tests.diff, which demonstrates the problem, and another patch, dates.diff, with the correction.

Attachments (3)

tests.diff (4.7 KB ) - added by Mark Sundstrom 14 years ago.
dates.diff (731 bytes ) - added by Mark Sundstrom 14 years ago.
combined.diff (5.4 KB ) - added by Mark Sundstrom 14 years ago.

Download all attachments as: .zip

Change History (7)

by Mark Sundstrom, 14 years ago

Attachment: tests.diff added

by Mark Sundstrom, 14 years ago

Attachment: dates.diff added

comment:1 by Łukasz Rekucki, 14 years ago

Patch needs improvement: set
Triage Stage: UnreviewedAccepted

The patch looks ok, but both tests and the fix should be in a single diff - it's easier to test that way.

by Mark Sundstrom, 14 years ago

Attachment: combined.diff added

in reply to:  1 comment:2 by Mark Sundstrom, 14 years ago

Replying to lrekucki:

The patch looks ok, but both tests and the fix should be in a single diff - it's easier to test that way.

Okay, see combined.diff

I had separated them because I thought it would be easier to demonstrate the problem, i.e.: apply the test patch, see the bug, apply the fix, see the bug go away.

comment:3 by Russell Keith-Magee, 14 years ago

Resolution: fixed
Status: newclosed

(In [14684]) Fixed #14752 -- Corrected date parsing in WeekArchiveView when using %W as a week format. Thanks to msundstr for the report and patch.

comment:4 by Jacob, 13 years ago

milestone: 1.3

Milestone 1.3 deleted

Note: See TracTickets for help on using tickets.
Back to Top