This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author p-ganssle
Recipients Paul Keating, belopolsky, p-ganssle, xtreak
Date 2018-12-19.17:06:58
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1545239218.26.0.788709270274.issue35535@psf.upfronthosting.co.za>
In-reply-to
Content
I don't really know what Python was doing in version 2.3, and I don't have immediate access to a Python 2.3 interpreter, but at least for %U and %W, datetime is calling the platform's `strftime` under the hood, so presumably if this is a bug it's a bug in glibc and the other providers of `strftime`.

Digging a bit more, %U and %W appear to be the the same for all Sundays if (and only if) the year starts on a Monday:

    import calendar
    from datetime import datetime
    from dateutil import rrule


    rr = rrule.rrule(freq=rrule.WEEKLY,
                     byweekday=rrule.SU,
                     dtstart=datetime(1900, 1, 1),
                     until=datetime(2100, 1, 1))

    for dt in rr:
        is_same = dt.strftime("%U") == dt.strftime("%W")
        year_starts_monday = calendar.weekday(dt.year, 1, 1) == 0
        assert is_same == year_starts_monday


This seems to be the right behavior, because %U and %W count all days before their respective "first day of the week" as "week 0", and week 1 starts with the relevant day of the week. If the year starts with Monday, week 1 is  1 January - 7 January according to %W (year starts on Monday), and week 1 is 7 January - 13 January according to %U (year starts on Sunday), thus all Sundays will be in the same "week number" in both systems.

> %U is supposed to work with the week numbering system common (as I understand it) in North America, where (according to Wikipedia) week 1 begins on a Sunday, and contains both 1 January and the first Saturday of the year. While I am not familiar with that system, Excel 2016 is, and it reports 

The documentation for %U says:

> Week number of the year (Sunday as the first day of the week) as a zero padded decimal number. All days in a new year preceding the first Sunday are considered to be in week 0.

This means that week 1 would only contain the first Saturday of the month and January 1st on years that start on Sunday. The Python documentation is consistent with the man page for strftime(3): http://man7.org/linux/man-pages/man3/strftime.3.html
History
Date User Action Args
2018-12-19 17:06:58p-gansslesetrecipients: + p-ganssle, belopolsky, xtreak, Paul Keating
2018-12-19 17:06:58p-gansslesetmessageid: <1545239218.26.0.788709270274.issue35535@psf.upfronthosting.co.za>
2018-12-19 17:06:58p-gansslelinkissue35535 messages
2018-12-19 17:06:58p-gansslecreate