[Datetime-SIG] Fixed offset timezones

Alexander Belopolsky alexander.belopolsky at gmail.com
Fri Dec 11 11:17:59 EST 2015


On Thu, Dec 10, 2015 at 8:40 PM, Chris Angelico <rosuav at gmail.com> wrote:

> I can't think of any real-world use-cases for an actual fixed-offset
> timezone. Usually these are either fake (like when you parse an RFC822
> time), or incorrect (when you're trying to represent "local time" in
> any way - although it might happen to mostly work in places without
> DST).
>

You certainly know one important  "real-world use-case for an actual
fixed-offset
timezone": UTC.  In fact, when datetime.timezone was introduced in Python,
support for UTC was the main motivation.  Arbitrary fixed offset timezones
were added primarily because once we've already paid a price of adding a
timezone class to the datetime module, support for arbitrary fixed offset
timezones came essentially for free.

Non-UTC fixed offset timezones are quite useful when your timestamps come
with UTC offset information.  Once you parse such timestamps into aware
datetime instances (using strptime or your own parser), you can do almost
everything you want with the result: convert to UTC, reformat/serialize for
further transmission, compute time differences, etc.  The only operation
that is slightly odd is the addition of a timedelta which may give you a
result that uses winter time offset in the summer.  Note that the result is
not wrong - just not what some users may expect.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/datetime-sig/attachments/20151211/42caa1ae/attachment-0001.html>


More information about the Datetime-SIG mailing list