Passage aux adhésions glissantes (partie 2/2, lc_ldap)

This commit is contained in:
Pierre-Elliott Bécue 2014-08-15 20:27:47 +02:00
parent 6880051943
commit 7f1ffbeed5
7 changed files with 180 additions and 30 deletions

View file

@ -306,3 +306,29 @@ def ip4_addresses():
ip_list.append(link['addr'])
return ip_list
def extractTz(thetz):
abstz = 100*abs(thetz)
if thetz == 0:
return "Z"
else:
return "%s%04d" % ("+"*(thetz < 0) + "-"*(thetz > 0), abstz)
def toGeneralizedTimeFormat(stamp):
"""Converts a timestamp (local) in a generalized time format
for LDAP.
* stamp : float value
* output : a string without the dot second
"""
return "%s%s" % (time.strftime("%Y%m%d%H%M%S", time.localtime(stamp)), extractTz(time.altzone/3600))
def fromGeneralizedTimeFormat(gtf):
"""Converts a GTF stamp to unix timestamp
* gtf : a generalized time format resource without dotsecond
* output : a float value
"""
return time.mktime(time.strptime(gtf.split("-", 1)[0].split("+", 1)[0].split('Z', 1)[0], "%Y%m%d%H%M%S"))