On Thu, Aug 27, 2015 at 2:32 PM, Tim Peters tim.peters@gmail.com wrote:
[Tim]
[...] Stewart, I still don't grasp what your problem is. The only concrete example I've seen is dealing with this string:
2004-10-31 01:15 EST-05:00
..
[Tim]
That's fine - I'm trying to get across the idea, not suggest a specific implementation, and 4 steps are one less than 5 ;-)
Dealing with simple time strings like this should really be one step:
ts = '2004-10-31 01:15 EST-05:00' dt = datetime.strptime(ts.replace('EST', '').replace(':', ''),
'%Y-%m-%d %H%M %z')
print(dt)
2004-10-31 01:15:00-05:00
It is unfortunate that we need to massage the input like this before passing it to datetime.strptime(). Ideally, datetime.strptime() should have a way to at least parse -05:00 as a fixed offset timezone.
However, this problem has nothing to do with PEP 495. Once you have the UTC offset - there is no ambiguity. The other 01:15 would be "2004-10-31 01:15 -04:00." The EST part is redundant and is dropped explicitly in my solution and not used in the solutions by Tim and Guido.