[Datetime-SIG] The BDFL's take
Lennart Regebro
regebro at gmail.com
Wed Jul 29 18:08:58 CEST 2015
On Wed, Jul 29, 2015 at 5:50 PM, Alexander Belopolsky
<alexander.belopolsky at gmail.com> wrote:
> The problems you gave, are perfectly solvable using current Python 3 standard
> library.
No, it isn't, as the Python 3 standard library does not contain
real-life timezone implementations.
> For some reason you insist on solving them using third party
> tools that are not designed for those particular tasks.
The third party tool is designed to handle real-life timezone
implementations, and implements them precisely the way the datetime
designers intented. It does exactly what Tim says it should do.
> You want to know what was the local time in New York one astronomical hour
> after 2014-11-02T01:30-0400 - set TZ=America/New_York and do this:
>
>>>> t = datetime.strptime("2014-11-02T01:30-0400", "%Y-%m-%dT%H:%M%z")
>>>> u = (t+timedelta(hours=1))
>>>> u.astimezone().strftime("%Y-%m-%dT%H:%M%z")
> '2014-11-02T01:30-0500'
>>> t = datetime.strptime("2014-11-02T01:30-0400", "%Y-%m-%dT%H:%M%z")
ValueError: 'z' is a bad directive in format '%Y-%m-%dT%H:%M%z'
Nope, didn't work. Did you mean uppercase Z?
>>> t = datetime.strptime("2014-11-02T01:30-0400", "%Y-%m-%dT%H:%M%Z")
ValueError: time data '2014-11-02T01:30-0400' does not match format
'%Y-%m-%dT%H:%M%Z'
Probably, but it still didn't work.
> What do you see lacking in this solution?
Please test your examples before you paste them, I have no idea what
you are trying to do.
More information about the Datetime-SIG
mailing list