From d6f4e7aefde26197f6cdb10a50c7d815ce344d55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Elliott=20B=C3=A9cue?= Date: Fri, 27 Mar 2015 14:40:59 +0100 Subject: [PATCH] pytz peut normaliser les dates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * En gros, si tz=Europe/Paris, et que le temps est localisé à utc+0100 alors que la date référencée est en avril, on pousse à utc+0200. --- crans_utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crans_utils.py b/crans_utils.py index 36a7975..6317907 100644 --- a/crans_utils.py +++ b/crans_utils.py @@ -355,6 +355,7 @@ def datetime_from_generalized_time_format(gtf): tz_dict = build_tz_dict() the_timezone = tz_dict.get(tz, pytz.utc) the_date = the_timezone.localize(the_date) + the_date = the_timezone.normalize(the_date) return the_date def datetime_to_generalized_time_format(datetime_obj): @@ -363,6 +364,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")