Skip to content

strptime(.., '%c') fails to parse output of strftime('%c', ..) in some locales #53203

Closed

Description

@abalkin
BPO 8957
Nosy @abalkin, @vstinner, @ezio-melotti
Dependencies
  • bpo-8915: Use locale.nl_langinfo in _strptime
  • Files
  • strptime-locale-bug.c: Working C code
  • strptime-locale-bug.py: Failing python code
  • cfmt.py
  • issue8957.py3k.1.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 = None
    closed_at = None
    created_at = <Date 2010-06-09.20:24:38.889>
    labels = ['extension-modules', 'type-bug', '3.7']
    title = "strptime(.., '%c') fails to parse output of strftime('%c', ..) in some locales"
    updated_at = <Date 2016-09-26.21:29:29.654>
    user = 'https://github.com/abalkin'

    bugs.python.org fields:

    activity = <Date 2016-09-26.21:29:29.654>
    actor = 'belopolsky'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Extension Modules']
    creation = <Date 2010-06-09.20:24:38.889>
    creator = 'belopolsky'
    dependencies = ['8915']
    files = ['17601', '17602', '20358', '20412']
    hgrepos = []
    issue_num = 8957
    keywords = ['patch']
    message_count = 18.0
    messages = ['107413', '125966', '125968', '126043', '126045', '126055', '126057', '126059', '126084', '126235', '126313', '126316', '126339', '126340', '126345', '126347', '126358', '221924']
    nosy_count = 4.0
    nosy_names = ['belopolsky', 'vstinner', 'ezio.melotti', 'rpetrov']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = 'needs patch'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue8957'
    versions = ['Python 3.7']

    Linked PRs

    Activity

    1. abalkin commented on Jun 9, 2010

      @abalkin
      MemberAuthor

      The following code:

      import locale, time
      locale.setlocale(locale.LC_ALL, "fr_FR.UTF-8")
      t = time.localtime()
      s = time.strftime('%c', t)
      time.strptime('%c', s)

      Raises

      ValueError: time data '%c' does not match format 'Mer 9 jui 16:14:46 2010'

      in any locale where month follows day in '%c' format. Note that attached C code works as expected on my OSX laptop.

      I wonder it it would make sense to call platform strptime where available? I wonder if platform support for strptime has improved since 2002 when _strptime.py was introduced.

    2. self-assigned this
      on Jun 9, 2010
    3. abalkin commented on Jan 11, 2011

      @abalkin
      MemberAuthor

      Adding bpo-8915 as a dependency because deducing D_T_FMT locale setting from strftime output seems impossible:

      >>> locale.nl_langinfo(locale.D_T_FMT)
      '%a %b %e %H:%M:%S %Y'
    4. abalkin commented on Jan 11, 2011

      @abalkin
      MemberAuthor

      Victor,

      You may be interested because your native language is implicated. :-)

    5. rpetrov commented on Jan 11, 2011

      rpetrovmannequin
      Mannequin

      time.strptime(s, '%c' ) ?

    6. abalkin commented on Jan 11, 2011

      @abalkin
      MemberAuthor

      time.strptime(s, '%c' ) ?

      Oh my. It certainly took a long time to recognize a silly mistake!

      Thanks.

    7. abalkin commented on Jan 12, 2011

      @abalkin
      MemberAuthor

      My tests were wrong but the problem does exist. I am attaching a script that tests strptime(.., '%c') for all locales installed on my system (an unmodified US Mac OS X 10.6.6).

      The only failing locale that I recognize is Hebrew (he_IL). Eli, what do you think about this?

       
      $ ./python.exe cfmt.py 
      am_ET [ማክሰ ጃንዩ 11 18:56:18 2011] %A %B %d %H:%M:%S %Y != %a %b %e %H:%M:%S %Y
      et_EE [T, 11. jaan  2011. 18:56:18] %a, %d. %B %Y. %H:%M:%S != %a, %d. %b %Y. %T
      he_IL [EST 18:56:18 2011 ינו 11 ג'] %Z %H:%M:%S %Y %B %d %a != %Z %H:%M:%S %Y %b %d %a
    8. changed the title [-]strptime('%c', ..) fails to parse output of strftime('%c', ..) in non-English locale[/-] [+]strptime(.., '%c') fails to parse output of strftime('%c', ..) in some locales[/+] on Jan 12, 2011
    9. rpetrov commented on Jan 12, 2011

      rpetrovmannequin
      Mannequin
      • %T is equal for %H:%M:%S
      • locales with %A and %B are broken on this platform as %c is "Appropriate date and time representation (%c) with abbreviations"
    10. 68 remaining items

    11. added a commit that references this issue on Jun 26, 2025
    12. serhiy-storchaka commented on Jun 26, 2025

      @serhiy-storchaka
      Member

      #135971 is perhaps the last PR for this issue. It adds support of non-decimal alt digits on locale lzh_TW, fixes bug in detecting the position of week day name on locales byn_ER and wal_ET, fixes support of single-digit hour on locales ar_SA and bg_BG.

      The code is prepared for using nl_langinfo(). The rest of changes belongs to #53161.

    13. removed
      pendingThe issue will be closed if no feedback is provided
      on Jun 26, 2025
    14. added a commit that references this issue on Jun 27, 2025
    15. added 2 commits that reference this issue on Jun 27, 2025
    16. added 2 commits that reference this issue on Jun 27, 2025
    17. added a commit that references this issue on Jul 11, 2025
    18. added a commit that references this issue on Jul 12, 2025
    19. added a commit that references this issue on Aug 4, 2025
    20. added a commit that references this issue on Aug 19, 2025
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Labels

    extension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions