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

Add datetime.fromisocalendar #80185

Closed
pganssle opened this issue Feb 15, 2019 · 7 comments
Closed

Add datetime.fromisocalendar #80185

pganssle opened this issue Feb 15, 2019 · 7 comments
Labels
3.8 stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@pganssle
Copy link
Member

pganssle commented Feb 15, 2019

BPO 36004
Nosy @malemburg, @abalkin, @vstinner, @matrixise, @pganssle, @eamanu
PRs
  • bpo-36004: Add date.fromisocalendar #11888
  • 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-04-29.13:31:05.146>
    created_at = <Date 2019-02-15.14:28:36.327>
    labels = ['3.8', 'type-feature', 'library']
    title = 'Add datetime.fromisocalendar'
    updated_at = <Date 2019-04-29.13:31:05.145>
    user = 'https://github.com/pganssle'

    bugs.python.org fields:

    activity = <Date 2019-04-29.13:31:05.145>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-04-29.13:31:05.146>
    closer = 'vstinner'
    components = ['Library (Lib)']
    creation = <Date 2019-02-15.14:28:36.327>
    creator = 'p-ganssle'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 36004
    keywords = ['patch']
    message_count = 7.0
    messages = ['335616', '335617', '335641', '335661', '335783', '341079', '341080']
    nosy_count = 6.0
    nosy_names = ['lemburg', 'belopolsky', 'vstinner', 'matrixise', 'p-ganssle', 'eamanu']
    pr_nums = ['11888']
    priority = 'low'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue36004'
    versions = ['Python 3.8']

    @pganssle
    Copy link
    Member Author

    pganssle commented Feb 15, 2019

    Datetime has many methods that "serializes" an instance to some other format - toordinal, timestamp, isoformat, etc. Most methods that "serialize" a datetime have a corresponding method that "deserializes" that method, or another way to reverse the operation:

    • strftime / strptime
    • timestamp / fromtimestamp
    • isoformat / fromisoformat
    • toordinal / fromordinal
    • timetuple / datetime(*thetuple[0:6])

    However, as I found out when implementing dateutil.parser.isoparse, there is no simple way to invert isocalendar().

    I have an implementation as part of dateutil.parser.isoparse:

    https://github.com/dateutil/dateutil/blob/master/dateutil/parser/isoparser.py#L297

    If there are no objections, I'd like to add an implementation in CPython itself. Thinking the name should be fromisocalendar.

    @pganssle pganssle added 3.8 stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Feb 15, 2019
    @matrixise
    Copy link
    Member

    matrixise commented Feb 15, 2019

    +1

    1 similar comment
    @eamanu
    Copy link
    Mannequin

    eamanu mannequin commented Feb 15, 2019

    +1

    @pganssle
    Copy link
    Member Author

    pganssle commented Feb 16, 2019

    I have a first-pass PR, a few questions to address:

    1. Should it take three arguments or a single 3-tuple? (I've gone with 3 arguments)
    2. Since all three arguments are required, should we make them positional-only?
    3. Should we allow time components in the datetime flavor of this? If so, I think we would also want datetime.isocalendar() to return a longer tuple, which would be backwards incompatible.
    4. Should we add a tz argument in the datetime flavor?

    I think for questions 3 and 4 the answer is no, modelling after .toordinal/.fromordinal.

    @pganssle
    Copy link
    Member Author

    pganssle commented Feb 17, 2019

    The attached PR is more or less fully ready, I think the correct answers to 1, 3 and 4 are that we should go with 3 separate arguments and we should not allow either time components or tz components, at least in this version.

    In the future, I don't think it will be backwards incompatible to add in these features if they are desired (though I imagine they won't be terribly in demand, and it's pretty easy to work around).

    The only real remaining question is number 2. Right now I am allowing keyword arguments, but the only real value I see in doing that is that PEP-570 (positional-only parameters) is not done yet and it's kind of annoying to implement "positional only parameters" in the pure Python version. If anyone feels strongly about this, let me know, otherwise I'll switch the implementation over to positional-only parameters.

    @vstinner
    Copy link
    Member

    vstinner commented Apr 29, 2019

    New changeset 88c0937 by Victor Stinner (Paul Ganssle) in branch 'master':
    bpo-36004: Add date.fromisocalendar (GH-11888)
    88c0937

    @vstinner
    Copy link
    Member

    vstinner commented Apr 29, 2019

    Thanks Paul, nice enhancement!

    @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 stdlib Python modules in the Lib dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants