Opened 4 years ago

Closed 4 years ago

Last modified 3 years ago

#14752 closed (fixed)

WeekArchiveView gives incorrect results when using weeks beginning with Monday

Reported by: msundstr 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 msundstr 4 years ago.
dates.diff (731 bytes) - added by msundstr 4 years ago.
combined.diff (5.4 KB) - added by msundstr 4 years ago.

Download all attachments as: .zip

Change History (7)

Changed 4 years ago by msundstr

Changed 4 years ago by msundstr

comment:1 follow-up: Changed 4 years ago by lrekucki

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement set
  • Triage Stage changed from Unreviewed to Accepted

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

Changed 4 years ago by msundstr

comment:2 in reply to: ↑ 1 Changed 4 years ago by msundstr

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 4 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

(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 3 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

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