From d86bd4bdd67bc7f34a2891acb7e86af6a31cdad0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Elliott=20B=C3=A9cue?= Date: Fri, 27 Mar 2015 14:57:28 +0100 Subject: [PATCH] =?UTF-8?q?Ouais,=20en=20fait,=20normaliser=20un=20temps?= =?UTF-8?q?=20dont=20l'offset=20est=20explicite=20=C3=A7a=20sert=20=C3=A0?= =?UTF-8?q?=20rien.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crans_utils.py | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/crans_utils.py b/crans_utils.py index 6317907..ac0e78d 100644 --- a/crans_utils.py +++ b/crans_utils.py @@ -352,8 +352,7 @@ def datetime_from_generalized_time_format(gtf): tz = '+0000' the_date = datetime.datetime.strptime(date, "%Y%m%d%H%M%S") if pytz is not None: - tz_dict = build_tz_dict() - the_timezone = tz_dict.get(tz, pytz.utc) + the_timezone = pytz.FixedOffset(int(tz[0:-2])*60 + int(tz[-2:])) the_date = the_timezone.localize(the_date) the_date = the_timezone.normalize(the_date) return the_date @@ -364,27 +363,7 @@ def datetime_to_generalized_time_format(datetime_obj): if datetime_obj.utcoffset() is None: if pytz is not None: datetime_obj = pytz.utc.localize(datetime_obj) - datetime_obj = pytz.utc.normalize(datetime_obj) else: to_append = "Z" mostly_gtf = datetime.datetime.strftime(datetime_obj, "%Y%m%d%H%M%S%z") return mostly_gtf.replace('+0000', "Z") + to_append - -def build_tz_dict(): - """Crappy way to define a dict containing all timezones that - pytz can handle. - - It seems there is no way to get a tz object from the offset - with pytz. - - """ - tz_dict = {} - for tz in pytz.common_timezones: - mytz = pytz.timezone(tz) - d = datetime.datetime.now(mytz).utcoffset().total_seconds() - hours = int(d)/3600 - minutes = int(float(int(d) % 3600)/60) - fmt = "%+03d%02d" % (hours, minutes) - if fmt not in tz_dict: - tz_dict[fmt] = mytz - return tz_dict