pytz peut normaliser les dates

* 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.
This commit is contained in:
Pierre-Elliott Bécue 2015-03-27 14:40:59 +01:00
parent 55dadbd693
commit d6f4e7aefd

View file

@ -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")