Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-30802: strptime() directives %W and %U -- Make weekday optional and assume the first day of the week #11594

Closed
wants to merge 4 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Jan 17, 2019

Motivation

  1. A year and a week number is enough to get a meaningful result
  2. When getting a date of the beginning of the week, the minimal amount of data required is a year and a week number. Specifying a weekday in that case is a violation of DRY principle and is error-prone.

Example

# When does the week start?

# BAD:    did I change %U to %W but forgot about %a?
#         or is this supposed to be the END of the week?
>>> datetime.strptime ('2019 3 Sun', '%Y %W %a')
datetime.datetime(2019, 1, 27, 0, 0)

# error-prone
>>> datetime.strptime ('2019 3 Mon', '%Y %W %a')
datetime.datetime(2019, 1, 21, 0, 0)

# error-prone
>>> datetime.strptime ('2019 3 Sun', '%Y %U %a')
datetime.datetime(2019, 1, 20, 0, 0)

# OK
>>> datetime.strptime ('2019 3',     '%Y %W')
datetime.datetime(2019, 1, 21, 0, 0)

# OK
>>> datetime.strptime ('2019 3',     '%Y %U')
datetime.datetime(2019, 1, 20, 0, 0)

https://bugs.python.org/issue30802

Directives %U and %W can now be used without specifying the day of
the week, in which case the first day of the week is assumed:

 - Sunday for %U
 - Monday for %W

This only has effect on the aforementioned directives. Specifying %U
or %W doesn't specify the day of the week implicitly.
@csabella
Copy link
Contributor

@pganssle, would you be able to review this? Thanks!

@pganssle
Copy link
Member

@csabella Yes I will review, thank you for the ping!

@ghost ghost requested review from abalkin and pganssle as code owners November 17, 2019 11:23
@csabella csabella requested review from pganssle and abalkin and removed request for abalkin and pganssle February 3, 2020 12:18
@ghost ghost changed the title bpo-30802: strptime() directives %W and %U no longer require a weekday by assuming the first day of the week if omitted bpo-30802: strptime() directives %W and %U -- Make weekday optional and assume the first day of the week Mar 30, 2020
@ghost
Copy link
Author

ghost commented Apr 21, 2020

@pganssle @abalkin
Review, please

@csabella csabella requested review from abalkin and pganssle and removed request for pganssle and abalkin May 23, 2020 15:48
@ghost ghost closed this Oct 4, 2020
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants