From c.buhtz at posteo.jp Fri Jul 15 12:51:33 2022 From: c.buhtz at posteo.jp (c.buhtz at posteo.jp) Date: Fri, 15 Jul 2022 16:51:33 +0000 Subject: [Dateutil] German daynames? Message-ID: <4Lky7F0KNbz6tn9@submission01.posteo.de> Hello, I am not sure if there is a problem with dateutil or in my understanding. So I am asking here first before opening an Issue. In short: The parse can not handle German weekday names (e.g. German "So" which is English "Sun"). Here an example: Lets create a timestamp (the day name of that date is "Sunday", in short "Sun", in German "Sonntag", in short German "So"). import datetime, dateutil.parser, locale val_dt = datetime.datetime(2022, 7, 17, 1, 2) val_str_locale_default = val_dt.strftime('%Y-%m-%d %a %H:%M') print(val_str_locale_default) # '2022-07-17 Sun 01:02' locale.setlocale(locale.LC_TIME, '') val_str_locale_german = val_dt.strftime('%Y-%m-%d %a %H:%M') print(val_str_locale_german) # '2022-07-17 So 01:02' OK, this is as expected. But now it comes to the parsing via dateutil. Parsing the first timestamp string with English dayname "Sun" is no problem. dateutil.parser.parse(val_str_locale_default) # datetime.datetime(2022, 7, 17, 1, 2) But parsing the German timestamp string with "So" ... dateutil.parser.parse(val_str_locale_german) ...throws: Traceback (most recent call last): File "", line 1, in File "/usr/lib/python3/dist-packages/dateutil/parser/_parser.py", line 1374, in parse return DEFAULTPARSER.parse(timestr, **kwargs) File "/usr/lib/python3/dist-packages/dateutil/parser/_parser.py", line 649, in parse raise ParserError("Unknown string format: %s", timestr) dateutil.parser._parser.ParserError: Unknown string format: 2022-07-17 So 01:02 Is there a "good" reason why this happens? 1. I would assume that after setlocale(LC_TIME, '') also dateutil should use the current locale (German, de_DE) when handling/parsing timestamps. But it seems to me that it doesn't. 2. Why does the day name relevant at all for dateutil? "Sun" or "So" is not represented in datetime.datetime so why parse that string. Just ignore day names. In that case it wouldn't matter in which language they are. I assume there are good (design) reasons for the current situation and I only have some understanding problems here. :) Kind Christian