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

strptime %d handling of single digit day of month #79084

Closed
mikegleen mannequin opened this issue Oct 5, 2018 · 11 comments
Closed

strptime %d handling of single digit day of month #79084

mikegleen mannequin opened this issue Oct 5, 2018 · 11 comments
Labels
3.8 (EOL) end of life docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error

Comments

@mikegleen
Copy link
Mannequin

mikegleen mannequin commented Oct 5, 2018

BPO 34903
Nosy @brettcannon, @matrixise, @pganssle, @miss-islington, @tirkarthi, @mikegleen
PRs
  • bpo-34903: For datetime.datetime.strptime(), the leading zero for some two-digit formats is optional #9747
  • bpo-34903: For datetime.datetime.strptime(), the leading zero for some two-digit formats is optional. #14149
  • [3.7] bpo-34903: Document that some strptime formats only require 1 digit (GH-14149) #14205
  • [3.8] bpo-34903: Document that some strptime formats only require 1 digit (GH-14149) #14206
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2019-06-18.18:56:50.324>
    created_at = <Date 2018-10-05.07:31:26.590>
    labels = ['type-bug', '3.8', 'docs']
    title = 'strptime %d handling of single digit day of month'
    updated_at = <Date 2021-05-14.19:50:35.336>
    user = 'https://github.com/mikegleen'

    bugs.python.org fields:

    activity = <Date 2021-05-14.19:50:35.336>
    actor = 'guziy.sasha'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2019-06-18.18:56:50.324>
    closer = 'p-ganssle'
    components = ['Documentation']
    creation = <Date 2018-10-05.07:31:26.590>
    creator = 'Mike Gleen'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 34903
    keywords = ['patch']
    message_count = 11.0
    messages = ['327109', '327110', '327156', '327200', '327227', '327237', '346000', '346001', '346002', '346004', '393688']
    nosy_count = 8.0
    nosy_names = ['brett.cannon', 'docs@python', 'matrixise', 'p-ganssle', 'miss-islington', 'xtreak', 'Mike Gleen', 'guziy.sasha']
    pr_nums = ['9747', '14149', '14205', '14206']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue34903'
    versions = ['Python 3.8']

    @mikegleen
    Copy link
    Mannequin Author

    mikegleen mannequin commented Oct 5, 2018

    strptime correctly parses single digit day-of-month values (at least in the case of "%d %b %Y") which is the behavior I want. However, the documentation seems to say that the field must be two digits with a leading zero if necessary. So I hope that this is the intended behavior rather than just an accidental artifact. If so, then my suggestion is that the documentation be updated to reflect this.

    @mikegleen mikegleen mannequin assigned docspython Oct 5, 2018
    @mikegleen mikegleen mannequin added docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error labels Oct 5, 2018
    @matrixise
    Copy link
    Member

    Hi Mike,

    Thank you for your issue, but could you add the link to the documentation, just because we have time.strptime and datetime.datetime.strptime.

    Thank you,

    @mikegleen
    Copy link
    Mannequin Author

    mikegleen mannequin commented Oct 5, 2018

    Sorry for the omission. This refers to datetime.datetime.strptime. The documentation I referenced is: https://docs.python.org/3/library/datetime.html; I did not test 2.7.

    @brettcannon
    Copy link
    Member

    So the documentation reads that way because it was originally written for strftime and has been repurposed to represent both. If the code does the right thing then adding a note that strptime supports single digits accurately would probably be a welcome pull request!

    @tirkarthi
    Copy link
    Member

    In addition to %d there are also other items that support single digit though zero padding is mentioned with strptime as below in the context of strftime :

    >>> import datetime
    >>> datetime.datetime.strptime("1/1/2018 1:1:1", "%d/%m/%Y %I:%M:%S")
    datetime.datetime(2018, 1, 1, 1, 1, 1)
    
    
    >>> datetime.datetime.strftime(datetime.datetime(year=2018, month=1, day=1, hour=1, second=1, minute=1), "%d/%m/%Y %I:%M:%S")
    '01/01/2018 01:01:01'

    I couldn't find exact set of words that can be used to denote that zero padding is optional in strptime and it's returned as zero padded in strftime but if we are changing %d then I propose changing other items too with similar wording.

    Thanks

    @mikegleen
    Copy link
    Mannequin Author

    mikegleen mannequin commented Oct 6, 2018

    Thanks for the quick response. I would be happy to write a pull request for
    the doc change. I've never done this before so it'll take a little while to
    get my head around the process, but the "Helping with Documentation"
    chapter seems good.

    Mike

    On Sat, Oct 6, 2018 at 7:09 AM Karthikeyan Singaravelan <
    report@bugs.python.org> wrote:

    Karthikeyan Singaravelan <tir.karthi@gmail.com> added the comment:

    In addition to %d there are also other items that support single digit
    though zero padding is mentioned with strptime as below in the context of
    strftime :

    >>> import datetime
    >>> datetime.datetime.strptime("1/1/2018 1:1:1", "%d/%m/%Y %I:%M:%S")
    datetime.datetime(2018, 1, 1, 1, 1, 1)

    >>> datetime.datetime.strftime(datetime.datetime(year=2018, month=1,
    day=1, hour=1, second=1, minute=1), "%d/%m/%Y %I:%M:%S")
    '01/01/2018 01:01:01'

    I couldn't find exact set of words that can be used to denote that zero
    padding is optional in strptime and it's returned as zero padded in
    strftime but if we are changing %d then I propose changing other items too
    with similar wording.

    Thanks

    ----------
    nosy: +xtreak


    Python tracker <report@bugs.python.org>
    <https://bugs.python.org/issue34903\>


    @pganssle
    Copy link
    Member

    New changeset 6b9c204 by Paul Ganssle (Mike Gleen) in branch 'master':
    bpo-34903: Document that some strptime formats only require 1 digit (GH-14149)
    6b9c204

    @miss-islington
    Copy link
    Contributor

    New changeset 452b417 by Miss Islington (bot) in branch '3.7':
    bpo-34903: Document that some strptime formats only require 1 digit (GH-14149)
    452b417

    @pganssle
    Copy link
    Member

    Thanks for the PR, Mike! This is now merged and backported to Python 3.7, so I believe we can close this issue.

    @miss-islington
    Copy link
    Contributor

    New changeset 35aa0b0 by Miss Islington (bot) in branch '3.8':
    bpo-34903: Document that some strptime formats only require 1 digit (GH-14149)
    35aa0b0

    @guziysasha
    Copy link
    Mannequin

    guziysasha mannequin commented May 14, 2021

    This is a bit unfortunate for the formats without separators, that could give wrong results silently:

    In [26]: datetime.strptime("2020010112", "%Y%m%d%H")
    Out[26]: datetime.datetime(2020, 1, 1, 12, 0)
    
    In [27]: datetime.strptime("2020010112", "%Y%m%d%H%M")
    Out[27]: datetime.datetime(2020, 1, 1, 1, 2)
    

    @guziysasha guziysasha mannequin added the 3.8 (EOL) end of life label May 14, 2021
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 (EOL) end of life docs Documentation in the Doc dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants