You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In [1]: fromdateutilimportparserIn [2]: date=parser.parse("Thu Jun 02 11:56:53 B 2011", tzinfos={"B": 2*3600})
In [3]: dateOut[3]: datetime.datetime(2011, 6, 2, 11, 56, 53)
In [4]: date.isoformat()
Out[4]: '2011-06-02T11:56:53+02:00'
However, it seems that timezones A and P are recognized as aliases for AM and PM:
In [3]: parser.parse("Thu Jun 02 12:56:53 A 2011", tzinfos={"A": 3600}).isoformat() # Noon in UTC+1Out[3]: '2011-06-02T00:56:53'# Midnight in UTCIn [4]: parser.parse("Thu Jun 02 12:56:53 P 2011", tzinfos={"P": -3*3600}).isoformat()
Out[4]: '2011-06-02T12:56:53'
This means that date using 24 hour format in these timezones are broken :
In [5]: parser.parse("Thu Jun 02 13:56:53 A 2011")
---------------------------------------------------------------------------ParserErrorTraceback (mostrecentcalllast)
CellIn[5], line1---->1parser.parse("Thu Jun 02 13:56:53 A 2011")
File~/.virtualenvs/tmp-9cee89e9c581522/lib/python3.10/site-packages/dateutil/parser/_parser.py:1368, inparse(timestr, parserinfo, **kwargs)
1366returnparser(parserinfo).parse(timestr, **kwargs)
1367else:
->1368returnDEFAULTPARSER.parse(timestr, **kwargs)
File~/.virtualenvs/tmp-9cee89e9c581522/lib/python3.10/site-packages/dateutil/parser/_parser.py:643, inparser.parse(self, timestr, default, ignoretz, tzinfos, **kwargs)
640res, skipped_tokens=self._parse(timestr, **kwargs)
642ifresisNone:
-->643raiseParserError("Unknown string format: %s", timestr)
645iflen(res) ==0:
646raiseParserError("String does not contain a date: %s", timestr)
ParserError: Unknownstringformat: ThuJun0213:56:53A2011
What is the result
Dates expressed in A and P timezones are not parsed correctly and can even raise exceptions
What is expected
Dates expressed in A and P timezones are parsed correctly and, if tzinfo is supplied, are offseted correctly
The text was updated successfully, but these errors were encountered:
What is happening
For context, some timezones are named with a single letter (A,B,C,D,..,Z) (cf. https://www.timeanddate.com/time/zones/a or https://www.timeanddate.com/time/zones/p)
The parser generally recognizes them correctly as timezones:
However, it seems that timezones A and P are recognized as aliases for AM and PM:
This means that date using 24 hour format in these timezones are broken :
What is the result
Dates expressed in A and P timezones are not parsed correctly and can even raise exceptions
What is expected
Dates expressed in A and P timezones are parsed correctly and, if tzinfo is supplied, are offseted correctly
The text was updated successfully, but these errors were encountered: