> The `'%W'` format uses the ISO week format and its week begins on a
Monday. The `'%W'` format is the same in both the `strftime()` and the
`date`.
However, as established in #7380, this is not true (another example is the
week starting on 2015-11-16, which is week 47 according to `date`, but 46
according to `strftime()`). This section of the docs should be rephrased
into a warning that `'%W'` and `'W'` are not compatible with each other.
--
Ticket URL: <https://code.djangoproject.com/ticket/26217>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_docs: => 0
* needs_better_patch: => 0
* type: Uncategorized => Bug
* needs_tests: => 0
* stage: Unreviewed => Accepted
Comment:
Would be great if you could submit a patch since you apparently understand
the issue.
--
Ticket URL: <https://code.djangoproject.com/ticket/26217#comment:1>
* owner: nobody => koniiiik
* status: new => assigned
Comment:
I'll try to submit a PR later this week, unless somebody beats me to it.
--
Ticket URL: <https://code.djangoproject.com/ticket/26217#comment:2>
Comment (by koniiiik):
As promised, https://github.com/django/django/pull/6171.
--
Ticket URL: <https://code.djangoproject.com/ticket/26217#comment:3>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/26217#comment:4>
* needs_better_patch: 0 => 1
Comment:
Left some comments for improvement, please uncheck "Patch needs
improvement" when updating.
--
Ticket URL: <https://code.djangoproject.com/ticket/26217#comment:5>
Comment (by koniiiik):
Thanks for the feedback; I'm trying to incorporate it into the patch.
One interesting thing I found is that the GNU libc supports an additional
format string, `'%V'`, which uses the same ISO 8601 numbering as the `'W'`
format character of the `date` template filter.
(http://linux.die.net/man/3/strftime) However, it is not documented in the
Python docs for `strftime`, since the Python docs are limited to the C89
standard. On the other hand, `'%V'` was introduced in C99, which hopefully
means that any reasonably recent system supports this format string.
Anyway, I think it might be worth adding support for `'%V'` in
`WeekArchiveView`. That way we get a combination of out-of-the-box date
formatters and parsers that work in templates and Python code alike. A
potential pitfall is that requires a different year in certain corner
cases with first and last weeks in a given year, which is `'%G'` for
`strftime` and `'o'` for `date`. This means a bit of special-casing would
be required in `WeekArchiveView`, and clear docs pointing out the
difference, but I still think it's worth it.
Is it okay to implement this in the current PR, or should I open a new
one?
--
Ticket URL: <https://code.djangoproject.com/ticket/26217#comment:6>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/26217#comment:7>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"468c6a3b6348fc3701ac569eeb119ddd146cf7c6" 468c6a3b]:
{{{
#!CommitTicketReference repository=""
revision="468c6a3b6348fc3701ac569eeb119ddd146cf7c6"
[1.9.x] Fixed #26217 -- Added a warning about format strings to
WeekArchiveView docs.
Backport of fe8ea3ba3ba709b3d6c39da046f0883a296e6441 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26217#comment:8>
Comment (by Tim Graham <timograham@…>):
In [changeset:"fe8ea3ba3ba709b3d6c39da046f0883a296e6441" fe8ea3ba]:
{{{
#!CommitTicketReference repository=""
revision="fe8ea3ba3ba709b3d6c39da046f0883a296e6441"
Fixed #26217 -- Added a warning about format strings to WeekArchiveView
docs.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26217#comment:9>
Comment (by koniiiik):
For the sake of completeness, in case someone stumbles upon this ticket,
using `'%V'` as the format string to parse the week number is a dead end,
because while `strftime` is a function specified in the C standard,
`strptime` is not, which means CPython needs to include its own
implementation of `strptime`, and that only implements the set of
`strftime` format strings mandated by C89.
--
Ticket URL: <https://code.djangoproject.com/ticket/26217#comment:10>
Comment (by Tim Graham <timograham@…>):
In [changeset:"2109975e901440da70e29d0f330a600bc2d37e9a" 2109975]:
{{{
#!CommitTicketReference repository=""
revision="2109975e901440da70e29d0f330a600bc2d37e9a"
Refs #26217 -- Fixed typo in docs/ref/class-based-views/generic-date-
based.txt.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26217#comment:11>
Comment (by Tim Graham <timograham@…>):
In [changeset:"d38da1cc401f61ff06aeda31e2b1b1f3be242efd" d38da1cc]:
{{{
#!CommitTicketReference repository=""
revision="d38da1cc401f61ff06aeda31e2b1b1f3be242efd"
[1.9.x] Refs #26217 -- Fixed typo in docs/ref/class-based-views/generic-
date-based.txt.
Backport of 2109975e901440da70e29d0f330a600bc2d37e9a from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26217#comment:12>