GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — datetime-RFC2822 roundtripping · Issue #37748 · python/cpython

datetime-RFC2822 roundtripping #37748

New issue
Copy link
New issue
Copy link
Closed
Closed
datetime-RFC2822 roundtripping#37748
Copy link
Assignees
abalkin
Labels
easystdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-emailtype-featureA feature request or enhancementA feature request or enhancement

Description

@doerwalter
doerwalter
opened on Jan 9, 2003
Issue body actions
BPO 665194
Nosy @tim-one, @warsaw, @akuchling, @doerwalter, @abalkin, @devdanzin, @merwok, @bitdancer
Dependencies
  • bpo-5094: datetime lacks concrete tzinfo implementation for UTC
  • Files
  • datetime-mimeformat.diff
  • formatdate_datetime_support.patch
  • util_datetime.patch
  • issue665194.diff
  • localtime.patch
  • localtime.patch
  • 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 = 'https://github.com/abalkin'
    closed_at = <Date 2012-08-23.04:10:12.456>
    created_at = <Date 2003-01-09.18:24:53.000>
    labels = ['easy', 'type-feature', 'library', 'expert-email']
    title = 'datetime-RFC2822 roundtripping'
    updated_at = <Date 2012-08-23.04:10:12.455>
    user = 'https://github.com/doerwalter'

    bugs.python.org fields:

    activity = <Date 2012-08-23.04:10:12.455>
    actor = 'belopolsky'
    assignee = 'belopolsky'
    closed = True
    closed_date = <Date 2012-08-23.04:10:12.456>
    closer = 'belopolsky'
    components = ['Library (Lib)', 'email']
    creation = <Date 2003-01-09.18:24:53.000>
    creator = 'doerwalter'
    dependencies = ['5094']
    files = ['8214', '21886', '22649', '26094', '26954', '26955']
    hgrepos = []
    issue_num = 665194
    keywords = ['patch', 'easy']
    message_count = 36.0
    messages = ['53725', '53726', '53727', '53728', '53729', '53730', '53731', '53732', '53733', '81810', '107436', '135154', '135211', '135222', '135226', '135228', '140317', '140747', '140748', '161644', '163486', '163516', '163620', '168834', '168835', '168837', '168838', '168840', '168841', '168912', '168913', '168914', '168916', '168919', '168920', '168922']
    nosy_count = 10.0
    nosy_names = ['tim.peters', 'barry', 'akuchling', 'doerwalter', 'belopolsky', 'ajaksu2', 'eric.araujo', 'r.david.murray', 'Alexander.Belopolsky', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue665194'
    versions = ['Python 3.3']

    Activity

    Next
    1. doerwalter commented on Jan 9, 2003

      @doerwalter
      doerwalter
      on Jan 9, 2003
      ContributorAuthor
      More actions

      It would be good to have a simply way to convert
      between datetime objects and RFC2822 style strings.
      From string to datetime is easy with
      datetime.datetime(*email.Utils.parsedate(m)[:7]) (but
      this drops the timezone), but the other direction seems
      impossible. email.Utils.formatdate takes a timestamp
      argument, but AFAICT there's no way to get a timestamp
      out of a datetime object.

      Of course the best solution (ignoring backwards
      compatibility) would be for parsedate und formatdate to
      return/accept datetime objects or for datetime to have
      the appropriate methods.

    2. doerwalter
      added
      type-featureA feature request or enhancementA feature request or enhancement
      on Jan 9, 2003
    3. tim-one commented on Jan 11, 2003

      @tim-one
      tim-one
      on Jan 11, 2003
      Member
      More actions

      Logged In: YES
      user_id=31435

      You can get a timestamp like so:

      >>> time.mktime(datetime.date(2002, 1, 1).timetuple())
      1009861200.0
      >>>

      The dates for which this works depends on the platform
      mktime implementation, though.

      BTW, this sounds a lot more like a new feature request
      than a bug!

    4. doerwalter commented on Jan 11, 2003

      @doerwalter
      doerwalter
      on Jan 11, 2003
      ContributorAuthor
      More actions

      Logged In: YES
      user_id=89016

      OK, I'll mark this a feature request.

      datetime has fromordinal() and toordinal(), it has
      fromtimestamp(), so I'd say a totimestamp() method would be
      a logical addition.

    5. tim-one commented on Jan 11, 2003

      @tim-one
      tim-one
      on Jan 11, 2003
      Member
      More actions

      Logged In: YES
      user_id=31435

      Define what totimestamp() should do. The range of
      timestamps supported by the *platform* C library (and so
      indirectly by Python's time module) isn't defined by any
      standard, and isn't easily discoverable either. It may or
      may not work before 1970, may or may not after 2038.
      datetime covers days far outside that range. Note that
      even a double doesn't have enough bits of precision to
      cover the full range of datetime values, either.

      In contrast, ordinals are wholly under Python's control, so
      we can promise surprise-free conversion in both directions.
      All we can promise about timestamps is that if the platform
      supports a timestamp for a time in datetime's range,
      datetime can make sense of it.

    6. doerwalter commented on Jan 13, 2003

      @doerwalter
      doerwalter
      on Jan 13, 2003
      ContributorAuthor
      More actions

      Logged In: YES
      user_id=89016

      totimestamp() should be the inverse of fromtimestamp(), i.e.
      foo.totimestamp() should be the same as
      time.mktime(foo.timetuple()).
      datetime.datetime.totimestamp() should raise OverflowError
      iff time.mktime() raises OverflowError.

      But as this may lose precision, I'd say it would be better,
      if datetime supported RFC1123 conversion directly, i.e. two
      methods frommime() and tomime(), that parse and format
      strings like "Sun, 06 Nov 1994 08:49:37 GMT" (what
      rfc822.parsedate() and rfc822.formatdate() do)

    7. brettcannon commented on May 23, 2003

      @brettcannon
      brettcannon
      on May 23, 2003
      Member
      More actions

      Logged In: YES
      user_id=357491

      time.strptime doesn't solve your problem?

    8. doerwalter commented on May 26, 2003

      @doerwalter
      doerwalter
      on May 26, 2003
      ContributorAuthor
      More actions

      Logged In: YES
      user_id=89016

      time.strptime() is locale aware, but RFC1123 & RFC822
      require english day and month names, so time.strptime()
      can't be used as-is. (And of course time.strptime() only
      works for formatting, not for parsing)

    9. akuchling commented on Dec 21, 2006

      @akuchling
      akuchling
      on Dec 21, 2006
      Contributor
      More actions

      Moving to feature requests.

    10. doerwalter commented on Mar 7, 2007

      @doerwalter
      doerwalter
      on Mar 7, 2007
      ContributorAuthor
      More actions

      Here is a patch that implements to formatting part. It adds a method mimeformat() to the datetime class. The datetime object must have a tzinfo for this to work.
      File Added: datetime-mimeformat.diff

    11. devdanzin commented on Feb 12, 2009

      @devdanzin
      devdanzinmannequin
      on Feb 12, 2009
      Mannequin
      More actions

      Patch includes tests, should be updated.

    12. devdanzin
      added
      stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
      on Feb 12, 2009
    13. devdanzin
      added
      easy
      on Apr 22, 2009
    14. 31 remaining items

    15. abalkin commented on Aug 22, 2012

      @abalkin
      abalkin
      on Aug 22, 2012
      Member
      More actions

      So since the other tests were passing before, presumably there
      is some test that could be added to exercise the bug you were
      fixing. Do you remember what that was?

      Yes, the issue was the one that was mentioned in an XXX comment: in many places UTC offset was different at different historical times but standard C library and Python's time module provides a single constant for it. There are plenty of examples that can be found in Olson's database (Europe/Kiev comes to mind), but it is not easy to devise a test that will work cross-platform. Maybe we should just restrict the test to Linux/BSD family of OSes?

    16. bitdancer commented on Aug 23, 2012

      @bitdancer
      bitdancer
      on Aug 23, 2012
      Member
      More actions

      I think restricting the test is fine. If we find a platform-specific bug on another platform we can add a test specific to that platform when we fix the bug.

      Can you provide the test? I'm going to commit what I've got at this point to make sure I don't miss the RC.

    17. AlexanderBelopolsky commented on Aug 23, 2012

      @AlexanderBelopolsky
      AlexanderBelopolskymannequin
      on Aug 23, 2012
      Mannequin
      More actions

      Please commit. I'll add the test.

      On Wed, Aug 22, 2012 at 9:11 PM, R. David Murray <[email protected]> wrote:

      R. David Murray added the comment:

      I think restricting the test is fine. If we find a platform-specific bug on another platform we can add a test specific to that platform when we fix the bug.

      Can you provide the test? I'm going to commit what I've got at this point to make sure I don't miss the RC.

      ----------


      Python tracker <[email protected]>
      <http://bugs.python.org/issue665194\>


    18. python-dev commented on Aug 23, 2012

      @python-dev
      python-devmannequin
      on Aug 23, 2012
      Mannequin
      More actions

      New changeset 71b9cca81598 by R David Murray in branch 'default':
      bpo-665194: Update email.utils.localtime to use astimezone, and fix bug.
      http://hg.python.org/cpython/rev/71b9cca81598

    19. bitdancer commented on Aug 23, 2012

      @bitdancer
      bitdancer
      on Aug 23, 2012
      Member
      More actions

      Leaving open until the test is committed.

    20. bitdancer
      unassigned
      bitdancer
      on Aug 23, 2012
    21. abalkin
      assigned
      abalkin
      on Aug 23, 2012
    22. python-dev commented on Aug 23, 2012

      @python-dev
      python-devmannequin
      on Aug 23, 2012
      Mannequin
      More actions

      New changeset a2d83fba8fd8 by R David Murray in branch 'default':
      bpo-665194: fix variable name in exception code path.
      http://hg.python.org/cpython/rev/a2d83fba8fd8

    23. python-dev commented on Aug 23, 2012

      @python-dev
      python-devmannequin
      on Aug 23, 2012
      Mannequin
      More actions

      New changeset 604222c1f8a0 by Alexander Belopolsky in branch 'default':
      Added test for a bug fixed in issue bpo-665194.
      http://hg.python.org/cpython/rev/604222c1f8a0

    24. python-dev commented on Aug 23, 2012

      @python-dev
      python-devmannequin
      on Aug 23, 2012
      Mannequin
      More actions

      New changeset 4c134e6ba0df by Alexander Belopolsky in branch 'default':
      Issue bpo-665194: Added a small optimization
      http://hg.python.org/cpython/rev/4c134e6ba0df

    25. abalkin
      closed this as completedon Aug 23, 2012
    26. abalkin
      closed this as completedon Aug 23, 2012
    27. ezio-melotti
      transferred this issue fromon Apr 9, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    • @abalkin
      abalkin

    Labels

    easystdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-emailtype-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.