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


Groups > comp.lang.python > #60941

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

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.021
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; '-10': 0.09; 'cest': 0.09; 'function,': 0.09; 'git': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; '--------': 0.10; 'ast': 0.16; 'cdt': 0.16; 'cet': 0.16; 'eat': 0.16; 'edt': 0.16; 'msd': 0.16; 'pdt': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject: \n ': 0.16; 'utc': 0.16; 'subject:python': 0.16; 'import': 0.22; 'header:User-Agent:1': 0.23; 'parse': 0.24; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'feature': 0.29; 'est': 0.30; 'subject:list': 0.30; 'twitter:': 0.31; 'hay': 0.31; 'blog:': 0.33; 'subject:time': 0.33; 'skip:d 20': 0.34; 'but': 0.35; 'there': 0.35; 'pst': 0.36; 'east': 0.36; 'auto': 0.38; 'hat': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'skip:t 30': 0.61; 'from:charset:utf-8': 0.61; 'act': 0.63; 'klein': 0.68; 'url:info': 0.73; 'discover': 0.82; '6.5': 0.84; '9.5': 0.84; 'bot': 0.84; 'hnc': 0.84; 'ict': 0.84; 'mart': 0.84; 'samt': 0.84; 'sgt': 0.84; 'wat': 0.84; 'cast': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Stéphane Klein <contact@stephane-klein.info>
Subject Re: I look for a list to convert time zone abbreviation to full time zone in python
Date Tue, 03 Dec 2013 16:46:17 +0100
References <l7ibsg$m9g$1@ger.gmane.org> <CADmi=6O_Te5L917Z8ihi315Jm_GOQ_N0sxotdAYWJ_dz_8WbzQ@mail.gmail.com> <529DF853.5080900@stephane-klein.info>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding 8bit
X-Gmane-NNTP-Posting-Host 37.162.51.71
User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:24.0) Gecko/20100101 Thunderbird/24.1.1
In-Reply-To <529DF853.5080900@stephane-klein.info>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3515.1386085591.18130.python-list@python.org> (permalink)
Lines 70
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1386085591 news.xs4all.nl 2876 [2001:888:2000:d::a6]:57499
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:60941

Show key headers only | View raw


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 ?

-- 
Stéphane Klein <contact@stephane-klein.info>
blog: http://stephane-klein.info
Twitter: http://twitter.com/klein_stephane
cv: http://cv.stephane-klein.info

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


Thread

Re: I look for a list to convert time zone abbreviation to full time zone in python Stéphane Klein <contact@stephane-klein.info> - 2013-12-03 16:46 +0100

csiph-web