Skip to content
Snippets Groups Projects
Commit 203c8143 authored by Pavel Kácha's avatar Pavel Kácha
Browse files

* Added format_time (to avoid time conversions where not necessary, for...

 * Added format_time (to avoid time conversions where not necessary, for example when parsed from logs)
 * Added utc arg for format_timestamp, to signal, whether input epoch needs adjustment to local time (defaults to True, so yes)
parent a220e53b
No related branches found
No related tags found
No related merge requests found
......@@ -578,13 +578,23 @@ class Client(object):
def format_timestamp(epoch=None, utcoffset=None):
t = epoch if epoch else time.time()
tstr = "%04d-%02d-%02dT%02d:%02d:%02d" % time.localtime(t)[:6]
us = int(t % 1 * 1000000 + 0.5)
usstr = "." + str(us).rstrip("0") if us else ""
offset = utcoffset if utcoffset is not None else -(time.altzone if time.daylight else time.timezone)
offsstr = ("%+03d:%02d" % divmod((offset+30)//60, 60)) if offset else "Z"
def format_timestamp(epoch=None, utc=True, utcoffset=None):
if utcoffset is None:
utcoffset = -(time.altzone if time.daylight else time.timezone)
if epoch is None:
epoch = time.time()
if utc:
epoch += utcoffset
us = int(epoch % 1 * 1000000 + 0.5)
return format_time(*time.gmtime(epoch)[:6], microsec=us, utcoffset=utcoffset)
def format_time(year, month, day, hour, minute, second, microsec=0, utcoffset=0):
if utcoffset is None:
utcoffset = -(time.altzone if time.daylight else time.timezone)
tstr = "%04d-%02d-%02dT%02d:%02d:%02d" % (year, month, day, hour, minute, second)
usstr = "." + str(microsec).rstrip("0") if microsec else ""
offsstr = ("%+03d:%02d" % divmod((utcoffset+30)//60, 60)) if utcoffset else "Z"
return tstr + usstr + offsstr
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment