Opened 7 years ago

Closed 7 years ago

Last modified 3 years ago

#7380 closed (wontfix)

Generic week view inconsistent with django.utils.dateformat

Reported by: dave.lowe@… Owned by: nobody
Component: Generic views Version: master
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

The generic week view parses the date by passing the year and week to Python's strptime function. The time module, where strptime is from, and specifically the %W directive, operates on an understanding that week numbers range from 00 to 53 and "All days in a new year preceding the first Monday are considered to be in week 0." [See http://docs.python.org/lib/module-time.html].

Django's DateFormat function in django.utils.dateformat operates differently. It uses the ISO calendar and the "first week of an ISO year is the first (Gregorian) calendar week of a year containing a Thursday." There actually is no week 0. Jan 1, 2010 (a Friday) is considered to be week 53 from the year before.

As a result, this makes dealing with week numbers in a template (and passing the correct number to a URL) extremely difficult.

Change History (4)

comment:1 Changed 7 years ago by dave.lowe@…

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Correction: the generic view uses the %U directive which considers all days in a new year preceding the first Sunday to be in week 0. This may actually be an additional issue -- Sunday-based rather than the default Monday-based dates in Python and Django's Date Format.

comment:2 Changed 7 years ago by ericholscher

  • milestone set to 1.0
  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 7 years ago by jacob

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

This is backwards-incompatible in a pretty subtle way, so I think unfortunately this is a "find a workaround" situation. The workaround in this case, BTW, is to use reverse URL resolution (i.e. the url template tag) to correctly interpolate the right values into the URL.

comment:4 Changed 3 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

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