Opened 6 years ago

Closed 6 years ago

Last modified 5 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: master
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: UI/UX:

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 6 years ago.
dates.diff (731 bytes) - added by Mark Sundstrom 6 years ago.
combined.diff (5.4 KB) - added by Mark Sundstrom 6 years ago.

Download all attachments as: .zip

Change History (7)

Changed 6 years ago by Mark Sundstrom

Attachment: tests.diff added

Changed 6 years ago by Mark Sundstrom

Attachment: dates.diff added

comment:1 Changed 6 years ago by Łukasz Rekucki

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.

Changed 6 years ago by Mark Sundstrom

Attachment: combined.diff added

comment:2 in reply to:  1 Changed 6 years ago by Mark Sundstrom

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 Changed 6 years ago by Russell Keith-Magee

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 Changed 5 years ago by Jacob

milestone: 1.3

Milestone 1.3 deleted

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