Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

I look for a list to convert time zone abbreviation to full time zone in python

1,000 views
Skip to first unread message

Stéphane Klein

unread,
Dec 2, 2013, 11:18:29 AM12/2/13
to pytho...@python.org
Hi,

I would like to convert time zone abbreviation to full time zone in Python.

I've found this information :

*
http://stackoverflow.com/questions/1703546/parsing-date-time-string-with-timezone-abbreviated-name-in-python

I'm currently writing dict with this informations :
http://www.timeanddate.com/library/abbreviations/timezones/

Questions :

* are there the same list somewhere (I didn't found in pytz) ?
* is it possible to append this list in pytz or in standard python date module ?

Best regards,
Stephane
--
St�phane Klein <con...@stephane-klein.info>
blog: http://stephane-klein.info
Twitter: http://twitter.com/klein_stephane
cv: http://cv.stephane-klein.info

Joel Goldstick

unread,
Dec 2, 2013, 12:31:22 PM12/2/13
to Stéphane Klein, pytho...@python.org
On Mon, Dec 2, 2013 at 11:18 AM, Stéphane Klein <con...@stephane-klein.info> wrote:
Hi,

I would like to convert time zone abbreviation to full time zone in Python.

I've found this information :

*
http://stackoverflow.com/questions/1703546/parsing-date-time-string-with-timezone-abbreviated-name-in-python

I'm currently writing dict with this informations :
http://www.timeanddate.com/library/abbreviations/timezones/

Questions :

* are there the same list somewhere (I didn't found in pytz) ?
* is it possible to append this list in pytz or in standard python date module ?

Is this what you are looking for: http://timezonedb.com/download

Best regards,
Stephane
--
Stéphane Klein <con...@stephane-klein.info>

Stuart Bishop

unread,
Dec 3, 2013, 5:07:34 AM12/3/13
to Stéphane Klein, pytho...@python.org
On Mon, Dec 2, 2013 at 11:18 PM, Stéphane Klein
<con...@stephane-klein.info> wrote:

> * are there the same list somewhere (I didn't found in pytz) ?

Not that I know of.

> * is it possible to append this list in pytz or in standard python date module ?

It could go into pytz (but generated from the IANA database, not from
the list you quote). Whether it should go into pytz is debatable.

If you need to map an abbreviation back to a single timezone you are
solving the wrong problem, because you can only map an abbreviation
back to a list of possible timezones (And that list might change when
the database is corrected). Also, to correctly represent this you need
to specify the point in time. EST in 'Tue Dec 3 20:44:00 EST 2013'
maps to about 3 timezones. EST in 'Tue Dec 3 20:44:00 EST 2011' maps
to about 6.

--
Stuart Bishop <stu...@stuartbishop.net>
http://www.stuartbishop.net/

Stéphane Klein

unread,
Dec 3, 2013, 10:27:15 AM12/3/13
to pytho...@python.org
Le 03/12/13 11:07, Stuart Bishop a écrit :
> It could go into pytz (but generated from the IANA database, not from
> the list you quote). Whether it should go into pytz is debatable.
>

Ok.

> If you need to map an abbreviation back to a single timezone you are
> solving the wrong problem, because you can only map an abbreviation
> back to a list of possible timezones (And that list might change when
> the database is corrected). Also, to correctly represent this you need
> to specify the point in time. EST in 'Tue Dec 3 20:44:00 EST 2013'
> maps to about 3 timezones. EST in 'Tue Dec 3 20:44:00 EST 2011' maps
> to about 6.
>

Ok I understand this now.

My original need is by example, convert

Apr 16 12:09:00 SGT 2010

to UTC format.

I would like to use datetime.datetime.strptime function, but it don't success to
parse %Z param.

pytz haven't parse function.

python-dateutil have a auto discover parse function, but I don't want to use
this auto discover feature.

Question, pytz can't implement a parsing feature ?

Best regards,
Stéphane

Stéphane Klein

unread,
Dec 3, 2013, 10:46:17 AM12/3/13
to pytho...@python.org
Le 03/12/13 16:27, Stéphane Klein a écrit :
> python-dateutil have a auto discover parse function, but I don't want to use
> this auto discover feature

For now, I use this :

--------
import dateutil.parser
import pytz

tz_str = '''-12 Y
-11 X NUT SST
-10 W CKT HAST HST TAHT TKT
-9 V AKST GAMT GIT HADT HNY
-8 U AKDT CIST HAY HNP PST PT
-7 T HAP HNR MST PDT
-6 S CST EAST GALT HAR HNC MDT
-5 R CDT COT EASST ECT EST ET HAC HNE PET
-4 Q AST BOT CLT COST EDT FKT GYT HAE HNA PYT
-3 P ADT ART BRT CLST FKST GFT HAA PMST PYST SRT UYT WGT
-2 O BRST FNT PMDT UYST WGST
-1 N AZOT CVT EGT
0 Z EGST GMT UTC WET WT
1 A CET DFT WAT WEDT WEST
2 B CAT CEDT CEST EET SAST WAST
3 C EAT EEDT EEST IDT MSK
4 D AMT AZT GET GST KUYT MSD MUT RET SAMT SCT
5 E AMST AQTT AZST HMT MAWT MVT PKT TFT TJT TMT UZT YEKT
6 F ALMT BIOT BTT IOT KGT NOVT OMST YEKST
7 G CXT DAVT HOVT ICT KRAT NOVST OMSST THA WIB
8 H ACT AWST BDT BNT CAST HKT IRKT KRAST MYT PHT SGT ULAT WITA WST
9 I AWDT IRKST JST KST PWT TLT WDT WIT YAKT
10 K AEST ChST PGT VLAT YAKST YAPT
11 L AEDT LHDT MAGT NCT PONT SBT VLAST VUT
12 M ANAST ANAT FJT GILT MAGST MHT NZST PETST PETT TVT WFT
13 FJST NZDT
11.5 NFT
10.5 ACDT LHST
9.5 ACST
6.5 CCT MMT
5.75 NPT
5.5 SLT
4.5 AFT IRDT
3.5 IRST
-2.5 HAT NDT
-3.5 HNT NST NT
-4.5 HLV VET
-9.5 MART MIT'''

tzd = {}
for tz_descr in map(str.split, tz_str.split('\n')):
tz_offset = int(float(tz_descr[0]) * 3600)
for tz_code in tz_descr[1:]:
tzd[tz_code] = tz_offset

print(tzd)

date1 = 'Apr 16 12:09:00 SGT 2010'
date = dateutil.parser.parse(date1, tzinfos=tzd).astimezone(pytz.utc)
print(date)
--------

Are there a better solution ?
0 new messages