diff --git a/warden3/warden_client/warden_client.py b/warden3/warden_client/warden_client.py index 797e0eb142d29a09b7405762627ca2c4b67cc0db..5b1262d41c079f353bc9127808048212a109dd9c 100644 --- a/warden3/warden_client/warden_client.py +++ b/warden3/warden_client/warden_client.py @@ -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