[issue30802] datetime.datetime.strptime('200722', '%Y%U')

Sergey Bon. report at bugs.python.org
Sun Dec 23 21:30:10 EST 2018


Sergey Bon. <sbon at pm.me> added the comment:

Documentation says:

%U - Week number of the year (Sunday as the first day of the week)
%W - Week number of the year (Monday as the first day of the week)

It wouldn't be intuitive if %U assumed Sunday when weekday provided and Monday otherwise. There are two separate directives specifically to distinguish these two cases, so which day of the week is the first one should be determined on the used directive:

>>> datetime.strptime ('2018 Mon 52', '%Y %a %W')
datetime.datetime(2018, 12, 24, 0, 0)

>>> datetime.strptime ('2018 52',     '%Y %W')
datetime.datetime(2018, 12, 24, 0, 0)

>>> datetime.strptime ('2018 Sun 52', '%Y %a %U')
datetime.datetime(2018, 12, 30, 0, 0)

>>> datetime.strptime ('2018 52',     '%Y %U')
datetime.datetime(2018, 12, 30, 0, 0)

----------
nosy: +sergey-bon

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue30802>
_______________________________________


More information about the Python-bugs-list mailing list