aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'libmproxy/utils.py')
-rw-r--r--libmproxy/utils.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/libmproxy/utils.py b/libmproxy/utils.py
index 76e99c34..a50be7fc 100644
--- a/libmproxy/utils.py
+++ b/libmproxy/utils.py
@@ -10,11 +10,20 @@ def timestamp():
return time.time()
-def format_timestamp(s):
- s = time.localtime(s)
- d = datetime.datetime.fromtimestamp(time.mktime(s))
- return d.strftime("%Y-%m-%d %H:%M:%S")
-
+def format_timestamp(s, include_fractions = False):
+ if type(s) is not float:
+ s = time.localtime(s)
+ d = datetime.datetime.fromtimestamp(time.mktime(s))
+ else:
+ # s is a timestamp(float) can be converted to a datetime without lossing microsecs
+ d = datetime.datetime.fromtimestamp(s)
+ if not include_fractions:
+ format = "%Y-%m-%d %H:%M:%S"
+ else:
+ # this will show 3 miliseconds digits (but will truncate and not round the 4th significant digit
+ # so 600999 microseconds will be 600ms and not 601ms)
+ format = "%Y-%m-%d %H:%M:%S."+str(d.microsecond/1000)
+ return d.strftime(format)
def isBin(s):
"""