Optimisation de GTF <-> datetime en virant sgn.
This commit is contained in:
parent
fb542de099
commit
9d89a0df5e
1 changed files with 3 additions and 6 deletions
|
@ -349,8 +349,7 @@ def datetime_from_generalized_time_format(gtf):
|
|||
date, tz = gtf[0:14], gtf[14:]
|
||||
else:
|
||||
date = gtf.replace("Z", '')
|
||||
tz = '0000'
|
||||
tz = tz.replace('+', '')
|
||||
tz = '+0000'
|
||||
the_date = datetime.datetime.strptime(date, "%Y%m%d%H%M%S")
|
||||
if pytz is not None:
|
||||
tz_dict = build_tz_dict()
|
||||
|
@ -360,10 +359,10 @@ def datetime_from_generalized_time_format(gtf):
|
|||
|
||||
def datetime_to_generalized_time_format(datetime_obj):
|
||||
"""Transforms a datetime to a GTF"""
|
||||
to_append = ""
|
||||
if datetime_obj.utcoffset() is None:
|
||||
if pytz is not None:
|
||||
datetime_obj = pytz.utc.localize(datetime_obj)
|
||||
to_append = ""
|
||||
else:
|
||||
to_append = "Z"
|
||||
mostly_gtf = datetime.datetime.strftime(datetime_obj, "%Y%m%d%H%M%S%z")
|
||||
|
@ -383,9 +382,7 @@ def build_tz_dict():
|
|||
d = datetime.datetime.now(mytz).utcoffset().total_seconds()
|
||||
hours = int(d)/3600
|
||||
minutes = int(float(int(d) % 3600)/60)
|
||||
fmt = "%s%02d%02d" % (sgn(hours), abs(hours), minutes)
|
||||
fmt = "%+03d%02d" % (hours, minutes)
|
||||
if fmt not in tz_dict:
|
||||
tz_dict[fmt] = mytz
|
||||
return tz_dict
|
||||
|
||||
sgn = lambda x: '-' if x < 0 else ''
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue