Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #76574

Re: How to look up historical time zones by date and location

References (4 earlier) <53F1FBCC.6060406@gmail.com> <mailman.13107.1408384942.18130.python-list@python.org> <lstqar$pg5$2@reader1.panix.com> <53F2A197.3090401@gmail.com> <53F2A8E2.9000804@gmail.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2014-08-19 10:25 -0600
Subject Re: How to look up historical time zones by date and location
Newsgroups comp.lang.python
Message-ID <mailman.13153.1408465604.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Mon, Aug 18, 2014 at 7:31 PM, luofeiyu <elearn2014@gmail.com> wrote:
> My dear  friends here, all i want is get   ` LMT+8:06:00`  from the output
> of tz1  `<DstTzInfo 'Asia/Shanghai' LMT+8:06:00 STD>`
>
> Shall we get back to the main point?
>
> If you are interested in it ,please say yes or no ,and how to do that ?
>
>
> import pytz,datetime
> tz1 = pytz.timezone('Asia/Shanghai')
> tz1
> <DstTzInfo 'Asia/Shanghai' LMT+8:06:00 STD>
>>>> str(tz1)
> 'Asia/Shanghai'

This is not a supported use case, so there's no good way to do it that
I can see. What gets printed when you evaluate tz1 is the result of
calling repr(), not str().

>>> repr(tz1)
"<DstTzInfo 'Asia/Shanghai' LMT+8:06:00 STD>"

If you just want the "LMT+8:06:00" as a string, you could call
repr(tz1) and then parse the result with a regex. But like I said,
this is not something that is supported by pytz. Somebody else noted
that the repr is simply showing the first historical entry for the
timezone in the database. Since the first entry is somewhat arbitrary,
not all time zones will show LMT like this, and there is no guarantee
that it won't change in some future update of pytz. In fact, there is
an open bug to fix this behavior:
https://bugs.launchpad.net/pytz/+bug/1319939

We might be able to be more helpful if you would be more clear about
what problem it is that you are trying to solve. Are you trying, for a
given point on the Earth, to determine what nautical time zone it
falls into, or some other "natural" time zone, or its LMT offset, or
something else? For any of those cases, I think the Olson database of
*legal* time zones is not going to be very useful. It would probably
be better to obtain the longitude and do the calculation yourself.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: How to look up historical time zones by date and location Ian Kelly <ian.g.kelly@gmail.com> - 2014-08-18 11:53 -0600
  Re: How to look up historical time zones by date and location pecore@pascolo.net - 2014-08-18 21:47 +0200
  Re: How to look up historical time zones by date and location Grant Edwards <invalid@invalid.invalid> - 2014-08-18 21:14 +0000
    Re: How to look up historical time zones by date and location luofeiyu <elearn2014@gmail.com> - 2014-08-19 09:31 +0800
    Re: How to look up historical time zones by date and location luofeiyu <elearn2014@gmail.com> - 2014-08-19 09:00 +0800
    Re: How to look up historical time zones by date and location Ian Kelly <ian.g.kelly@gmail.com> - 2014-08-19 10:25 -0600
      Re: How to look up historical time zones by date and location Denis McMahon <denismfmcmahon@gmail.com> - 2014-08-19 17:44 +0000

csiph-web