pytz question: GMT vs. UTC

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

pytz question: GMT vs. UTC

Skip Montanaro-3
According ato the pytz doc (http://pytz.sourceforge.net/):

"?UTC? is Universal Time, also known as Greenwich Mean Time or GMT in
the United Kingdom."

If they are equal, why don't timezone objects created from those two
strings compare equal?

>>> pytz.timezone("UTC") == pytz.timezone("GMT")
False

(I'm revealing my complete ignorance of timezone manipulation by
asking this question.)

Thx,

Skip


Reply | Threaded
Open this post in threaded view
|

pytz question: GMT vs. UTC

Chris Angelico
On Thu, Jan 30, 2014 at 4:29 AM, Skip Montanaro <skip at pobox.com> wrote:

> According ato the pytz doc (http://pytz.sourceforge.net/):
>
> "?UTC? is Universal Time, also known as Greenwich Mean Time or GMT in
> the United Kingdom."
>
> If they are equal, why don't timezone objects created from those two
> strings compare equal?
>
>>>> pytz.timezone("UTC") == pytz.timezone("GMT")
> False

There are some technical differences between UTC and GMT, which almost
never come up, and which I very much doubt are significant here (does
pytz care about leap seconds?). But what I'm seeing - at least in the
version of pytz that I picked up by typing 'sudo pip install pytz' on
Debian Wheezy - is that the two are different types. UTC seems to be a
special case, while GMT is like the others. That may be why they're
not comparing equal, even though all operations might happen to
produce the same results.

ChrisA


Reply | Threaded
Open this post in threaded view
|

pytz question: GMT vs. UTC

Ben Finney-10
In reply to this post by Skip Montanaro-3
Skip Montanaro <skip at pobox.com> writes:

> According ato the pytz doc (http://pytz.sourceforge.net/):
>
> "?UTC? is Universal Time, also known as Greenwich Mean Time or GMT in
> the United Kingdom."

This is inaccurate, and I'd like to see it corrected in the
documentation. UTC is neither UT nor GMT.

GMT is not precisely defined, which makes it unsuitable for keeping
precise time in a computer system.

> If they are equal, why don't timezone objects created from those two
> strings compare equal?
>
> >>> pytz.timezone("UTC") == pytz.timezone("GMT")
> False

Python is correct, the timezones are not the same.

See <URL:https://en.wikipedia.org/wiki/Coordinated_Universal_Time> and
<URL:https://en.wikipedia.org/wiki/Greenwich_Mean_Time>. From the
former:

    Saying "GMT" often implies either UTC or UT1 when used within
    informal or casual contexts. In technical contexts, usage of "GMT"
    is avoided; the unambiguous terminology "UTC" or "UT1" is preferred.

> (I'm revealing my complete ignorance of timezone manipulation by
> asking this question.)

Treat GMT like any other locale-specific timezone, and convert to/from
it as late/early as possible (like a locale-specific encoding).

Treat UTC as the canonical timezone for keeping all timestamp values in
(like Unicode for text).

--
 \     ?Reality must take precedence over public relations, for nature |
  `\                            cannot be fooled.? ?Richard P. Feynman |
_o__)                                                                  |
Ben Finney