Ouais, en fait, normaliser un temps dont l'offset est explicite ça sert à rien.
This commit is contained in:
parent
d6f4e7aefd
commit
d86bd4bdd6
1 changed files with 1 additions and 22 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue