The module refers to https://bugs.python.org/issue13305. On reading
further, I understand the following:
For years < 1000 specifiers `%C`, `%F`, `%G`, and `%Y` don't work as
expected for `strftime` provided by glibc on Linux as they don't pad the
year or century with leading zeros. Support for specifying the padding
explicitly is available, however, which can be used to fix this issue,
e.g. `%04Y`.
FreeBSD, macOS, and Windows do not support explicitly specifying the
padding, but return four digit years (with leading zeros) as expected.
It seems to me that the current approach is quite complex and that we
could simply implement a check whether `%Y` produces the expected value
and, if not, make the following substitutions:
- `%C` → `%02C`
- `%F` → `%010F`
- `%G` → `%04G`
- `%Y` → `%04Y`
This changes from wrapping `date`/`datetime` objects in subclasses with
overridden `.strftime()` to a simple function call to check whether we
need to fix the format and rewrite the format if so. (This can be cached.)
We also gain the benefit of fixing other specifiers that are also
affected, rather than just `%Y`.
There has been some precedence for cleaning up `datetime_safe` in #29600.
Also, Aymeric [https://code.djangoproject.com/ticket/21256#comment:1
doesn't really like it]... :D
--
Ticket URL: <https://code.djangoproject.com/ticket/32738>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/14378 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/32738#comment:1>
* stage: Unreviewed => Accepted
Comment:
OK, I like this: the single documented function is clearer for me that the
subclass approach.
--
Ticket URL: <https://code.djangoproject.com/ticket/32738#comment:2>
Comment (by Carlton Gibson <carlton.gibson@…>):
In [changeset:"46346f8ea08020d503b25472a26b949a5ce980a6" 46346f8]:
{{{
#!CommitTicketReference repository=""
revision="46346f8ea08020d503b25472a26b949a5ce980a6"
Refs #32738 -- Added sanitize_strftime_format() to replace datetime_safe.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32738#comment:4>
Comment (by Carlton Gibson <carlton.gibson@…>):
In [changeset:"44accb066a51d15f27e38f203c73830eddea16df" 44accb0]:
{{{
#!CommitTicketReference repository=""
revision="44accb066a51d15f27e38f203c73830eddea16df"
Refs #32738, Refs #29600, Refs #29595 -- Removed unused
django.utils.datetime_safe.time().
Unused since c72dde41e603093ab0bb12fa24fa69cfda0d35f9.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32738#comment:3>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"29e4ccb1a2d5aab21fbd7effcd48d33dc73f9b1e" 29e4ccb1]:
{{{
#!CommitTicketReference repository=""
revision="29e4ccb1a2d5aab21fbd7effcd48d33dc73f9b1e"
Fixed #32738 -- Deprecated django.utils.datetime_safe module.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32738#comment:5>