4 ms·
A line in one of my Python daemons has been crashing it repeatedly all day: isotime = datetime.strptime(time.get('title'), '%a %d %b %I:%M:%S %p').replace(ye
by user982 7y ago
A line in one of my Python daemons has been crashing it repeatedly all day:
isotime = datetime.strptime(time.get('title'), '%a %d %b %I:%M:%S %p').replace(year=YEAR, tzinfo=TZ).isoformat()
ValueError: day is out of range for month
It's not mission-critical, so I'm just going to wait it out until tomorrow.
EDIT: Hacked it out.
isotime = datetime.strptime(f"{time.get('title')} {YEAR} {tzoffset:+03d}00", '%a %d %b %I:%M:%S %p %Y %z').isoformat()
- 1wd 7y agohttps://bugs.python.org/issue26460 https://bugs.python.org/issue26460
- phoobahr 7y agoThat strap time parsing doesn't fail under python 2.7.17 or 3.8.1
- user982 7y agoPython 2.7.17 (default, Dec 31 2019, 23:59:25) Type "help", "copyright", "credits" or "license" for more information. >>> from datetime import datetime >>> datetime.strptime('Sat 29 Feb 12:00:00 PM', '%a %d %b %I:%M:%S %p') Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: day is out of range for month
- park_94110 7y agoThis is because 1900 is the default year in datetime. 1900 was not a leap year.
- user982 7y agoI know, I'm just providing a counterexample to phoobahr.
- detaro 7y agoInteresting. Given the documentation of strptime, I would have expected that to not be possible at all (since constructing a datetime without a year isn't possible directly)