Skip to content

Add datetime.fromisocalendar #80185

Description

@pganssle
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']

    Activity

    1. pganssle commented on Feb 15, 2019

      @pganssle
      MemberAuthor

      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.

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-featureA feature request or enhancement
      on Feb 15, 2019
    3. matrixise commented on Feb 15, 2019

      @matrixise
      Member

      +1

    4. eamanu commented on Feb 15, 2019

      eamanumannequin
      Mannequin

      +1

    5. pganssle commented on Feb 16, 2019

      @pganssle
      MemberAuthor

      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.

    6. pganssle commented on Feb 17, 2019

      @pganssle
      MemberAuthor

      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.

    7. vstinner commented on Apr 29, 2019

      @vstinner
      Member

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

    8. vstinner commented on Apr 29, 2019

      @vstinner
      Member

      Thanks Paul, nice enhancement!

    9. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.8 (EOL)end of lifestdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions