[Django] #25352: django.views.generic.dates.WeekArchiveView use of _date_from_string results on off-by-one weeks handling

4 views
Skip to first unread message

Django

unread,
Sep 4, 2015, 10:26:15 AM9/4/15
to django-...@googlegroups.com
#25352: django.views.generic.dates.WeekArchiveView use of _date_from_string results
on off-by-one weeks handling
-------------------------------+--------------------
Reporter: OdyX | Owner: nobody
Type: Bug | Status: new
Component: Generic views | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
While trying to use WeekArchiveView to display objects in given weeks (and
navigate within weeks), I've found that the data would be displayed off by
one week, which makes it very confusing to use.

I think the problem start there:
https://github.com/django/django/blob/master/django/views/generic/dates.py#L551
:

{{{
date = _date_from_string(year, self.get_year_format(),
week_start, '%w',
week, week_format)

since = self._make_date_lookup_arg(date)
until = self._make_date_lookup_arg(self._get_next_week(date))
}}}

`date` is then used as `since`, which should be the start of the
'''current''' week, while `_date_from_string` outputs the day starting the
next week (format in use being '%w').

{{{
>>> from django.utils import timezone
>>> now = timezone.datetime.now()
>>> now.strftime('%W')
'35'
>>> now.isocalendar()[1]
36
>>> from django.views.generic.dates import _date_from_string
>>> _date_from_string('2015', '%Y', '1', '%w', '35', '%W')
datetime.date(2015, 8, 31)
}}}

Actually, I'm not sure where the bug lays, but seeing `.isocalendar()[1]`
differ from `.strftime('%W')` is certainly weird. So far, it seems to me
to be the cause for my `previous_week` and `next_week`-based buttons to
have off-by-one errors. Is there any reason for `.strftime('%W')`
https://github.com/django/django/blob/master/django/utils/dateformat.py#L300
not to use `.isocalendar()` ?

What am I overlooking, or doing wrong?

--
Ticket URL: <https://code.djangoproject.com/ticket/25352>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Sep 4, 2015, 2:02:36 PM9/4/15
to django-...@googlegroups.com
#25352: django.views.generic.dates.WeekArchiveView use of _date_from_string results
on off-by-one weeks handling
-------------------------------+--------------------------------------

Reporter: OdyX | Owner: nobody
Type: Bug | Status: new
Component: Generic views | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by timgraham):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

Could you check Django's test suite to see if this is covered there?
Sometimes by trying to make the change you think needs to be made, you'll
uncover a failing test that shows the reason why things the way they are.
Also, if you could provide a failing test case for your report, that's
very helpful in understanding it.

--
Ticket URL: <https://code.djangoproject.com/ticket/25352#comment:1>

Django

unread,
Sep 8, 2015, 10:49:31 AM9/8/15
to django-...@googlegroups.com
#25352: django.views.generic.dates.WeekArchiveView use of _date_from_string results
on off-by-one weeks handling
-------------------------------+--------------------------------------
Reporter: OdyX | Owner: nobody
Type: Bug | Status: closed

Component: Generic views | Version: 1.8
Severity: Normal | Resolution: needsinfo
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by timgraham):

* status: new => closed
* resolution: => needsinfo


Comment:

Is the issue that weeks are 0-indexed? As noted
[https://docs.python.org/3/library/datetime.html in the Python docs], "All
days in a new year preceding the first Sunday are considered to be in week
0."

Please reopen if you can provide more details like a sample project or a
test case for Django's test suite. The current report is a bit abstract
and it's difficult for me to understand what problem you're reporting.
Thanks!

--
Ticket URL: <https://code.djangoproject.com/ticket/25352#comment:2>

Reply all
Reply to author
Forward
0 new messages