[Datetime-SIG] Allow numerical arguments for timezones

Guido van Rossum guido at python.org
Thu Dec 10 20:26:31 EST 2015


My guess is that the OP is parsing dates that have a numerical TZ offset
(like most date formats found in internet protocols like http or email
headers). But there's really no substitute for just calling

    datetime(....., tzinfo=timezone(timedelta(hours=......)))

On Thu, Dec 10, 2015 at 5:20 PM, Alexander Belopolsky <
alexander.belopolsky at gmail.com> wrote:

>
> On Thu, Dec 10, 2015 at 8:09 PM, Guido van Rossum <guido at python.org>
> wrote:
>
>> The reason that timezone() takes a timedelta is to avoid mistakes in the
>> units.
>
>
> That was more or less the original reasoning.   Note that an early
> prototype required the offset to be specified in minutes. [1]
>
> I don't expect people to have to construct timezone objects "by hand".
> You would normally get tzinfo populated with a local timezone by calling
> .astimezone() on a UTC instance:
>
> >>> from datetime import *
> >>> dt = datetime.now(timezone.utc)
> >>> print(dt.astimezone())
> 2015-12-10 20:19:34.446688-05:00
>
> [1]: http://bugs.python.org/issue5094#msg106911
>



-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/datetime-sig/attachments/20151210/46cbc019/attachment-0001.html>


More information about the Datetime-SIG mailing list