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.
* 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>
* 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>