This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: datetime.strptime have no directive to convert date values with Era and Time Zone name
Type: enhancement Stage: resolved
Components: Extension Modules Versions: Python 3.6
Status: closed Resolution: rejected
Dependencies: Superseder: %Z in strptime doesn't match EST and others
View: 22377
Assigned To: Nosy List: Raghunath Lingutla, belopolsky, p-ganssle, xtreak
Priority: normal Keywords:

Created on 2018-06-22 12:57 by Raghunath Lingutla, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg320231 - (view) Author: Raghunath Lingutla (Raghunath Lingutla) Date: 2018-06-22 12:57
Python3.6 module datetime.strptime didn't have directive to convert date values having Era designator (AD or BC) and time zone (Ex: EST, PST, -07:00)

Below are few example for date values which are not supported

2018-04-14 12:08:56 EST

2018-05-23 11:03:43 PST

2017-12-24 AD 12:08:56

2018-05-23 11:03:43 +05:30
msg326339 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2018-09-25 11:06
Thanks for the report Raghunath. Regarding timezone detection there is a limitation with %Z supporting only UTC, GMT and `time.tzname` which is not documented and it's an open issue tracked at issue22377 . Regarding a directive to determine Era I think it falls under a feature request and compile error is used for errors during compiling python interpreter itself. So I am changing this from compile error to enhancement.

# Support for GMT, UTC and error on PDT

$ ./python.exe
Python 3.8.0a0 (heads/master:f6c8007a29, Sep 25 2018, 12:30:43)
[Clang 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> datetime.datetime.strptime("2018-06-14 10:10:11 GMT", "%Y-%m-%d %H:%M:%S %Z")
datetime.datetime(2018, 6, 14, 10, 10, 11)
>>> datetime.datetime.strptime("2018-06-14 10:10:11 UTC", "%Y-%m-%d %H:%M:%S %Z")
datetime.datetime(2018, 6, 14, 10, 10, 11)
>>> datetime.datetime.strptime("2018-06-14 10:10:11 PDT", "%Y-%m-%d %H:%M:%S %Z")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/", line 568, in _strptime_datetime
    tt, fraction, gmtoff_fraction = _strptime(data_string, format)
  File "/Users/karthikeyansingaravelan/stuff/python/cpython/Lib/", line 349, in _strptime
    raise ValueError("time data %r does not match format %r" %
ValueError: time data '2018-06-14 10:10:11 PDT' does not match format '%Y-%m-%d %H:%M:%S %Z'

Hope this helps!

msg328843 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2018-10-29 17:24
Since the Python datetime only supports dates within 0001-01-01 through 9999-12-31 range, it is not clear how we can meaningfully support the AD/BC era designation.

Looking at man strftime page on my Mac, I see that they use every upper an lower case letter as a valid format specifier, but they still not have a letter code for AD/BC.  In the "BUGS" section they humorousely complain that "There is no conversion specification for the phase of the moon" which makes me think that the moon phase designations are higher on some people agenda than the era designations.
Date User Action Args
2022-04-11 14:59:02adminsetgithub: 78121
2018-10-29 17:24:53belopolskysetsuperseder: %Z in strptime doesn't match EST and others
2018-10-29 17:24:32belopolskysetstatus: open -> closed
resolution: rejected
stage: resolved
2018-10-29 17:24:03belopolskysetmessages: + msg328843
2018-09-25 11:06:30xtreaksettype: compile error -> enhancement
messages: + msg326339
2018-09-25 10:21:42xtreaksetnosy: + xtreak
2018-07-05 15:13:24p-gansslesetnosy: + p-ganssle
2018-06-22 20:51:09ned.deilysetnosy: - lemburg
2018-06-22 20:49:48ned.deilysetnosy: + lemburg, belopolsky
2018-06-22 12:57:29Raghunath Lingutlacreate