5 ms·
Note that Python still lacks any way to parse these dates in the standard library. You have to use a third party library to parse them. You might think `datetim
by NelsonMinar 5y ago
Note that Python still lacks any way to parse these dates in the standard library. You have to use a third party library to parse them. You might think `datetime.fromisoformat` parsed ISO dates but you'd be wrong; it doesn't support the trailing Z or any other form of timezone information. The docs are clear about this, and the developer discussion I've read basically boils down to "it's too hard to parse ISO dates so we didn't do it here." This discussion has been going on for years.
https://stackoverflow.com/questions/127803/how-do-i-parse-an-iso-8601-formatted-date https://stackoverflow.com/questions/127803/how-do-i-parse-an...
- macintux 5y agoPlus the naive date times that seem to pop up by default. Frustrating.
- Dunedan 5y agoCan you elaborate on this? Parsing ISO 8601 formatted dates doesn't result in naive Python datetimes: >>> datetime.fromisoformat("2021-10-24T20:17:41+02:00") datetime.datetime(2021, 10, 24, 20, 17, 41, tzinfo=datetime.timezone(datetime.timedelta(seconds=7200)))
- NelsonMinar 5y agoYour example demonstrates I'm wrong with isoformat not supporting any timezone info. Sorry about that. Given it can handle +02:00 I wonder why they don't just add support for z and Z and instantly cover 95% of the world's JSON data?
- macintux 5y agoSorry, was on mobile and didn't elaborate. Was referring to datetime.datetime.now(); why can't it incorporate the local timezone?
- Dunedan 5y agoWell, it can, it's just not the default: >>> from datetime import datetime, timezone >>> datetime.now(tz=timezone.utc).astimezone() datetime.datetime(2021, 10, 25, 19, 58, 34, 51668, tzinfo=datetime.timezone(datetime.timedelta(seconds=7200), 'CEST')) Or if you want to use a specific timezone: >>> from datetime import datetime >>> from zoneinfo import ZoneInfo >>> datetime.now(tz=ZoneInfo("Europe/Berlin")) datetime.datetime(2021, 10, 25, 19, 58, 34, 51668, tzinfo=zoneinfo.ZoneInfo(key='Europe/Berlin'))
- macintux 5y agoYes, but who’s more likely to get the code right to determine the system’s timezone: the programmer or the library? datetime.datetime.now() is by definition local to the system. What motivation is there to not include a timezone with the return value?
- benatkin 5y agoYep. from dateutil.parser import isoparse
- mountainriver 5y agoI’m amazed this is still a problem, it makes it hard to treat python seriously
- franga2000 5y agoPython has one of the most exhaustive stdlibs out there. Surely the a handful of useful but trivial missing functions don't make it any less serious than, for example, NodeJS, which barely even has a stdlib.
- KptMarchewa 5y agoPython also has one of the most outdated and dead libs in stdlib out there. https://www.python.org/dev/peps/pep-0594/ https://www.python.org/dev/peps/pep-0594/
- franga2000 5y agoThe stdlib contains outdated modules, it's not outdated itself. Windows 11 still contains some DLLs dating back as far as at least NT 4.0 and nobody would call it an outdated OS. The stdlib is constantly being improved and I for one am glad that older and rarely used features are being kept around instead of booting them out with the next minor release.
- KptMarchewa 5y ago>The stdlib is constantly being improved At a glacial pace. Generally stuff is being added and left to die. >rarely used features are being kept around instead of booting them out with the next minor release Or, maybe, being actively maintained? Python desperately lacked corporate interest and paid maintainership, and I'm glad that this starts to change. Entirely volunteer model sounds cool, until you see that people are only interested in adding "cool" stuff and syntactic sugar like walrus operator.
- mountainriver 5y agoI would rather they did less well