diff options
author | Marcelo Glezer <marcelo.glezer@gmail.com> | 2015-03-02 23:22:44 -0300 |
---|---|---|
committer | Marcelo Glezer <marcelo.glezer@gmail.com> | 2015-03-02 23:22:44 -0300 |
commit | 58dba3f49083288e19f6e9edb7cc60e88dd446e3 (patch) | |
tree | 2cbcafe106575bf8f3b93494c97fa87bab050b38 /libmproxy/utils.py | |
parent | 91e5a4a4b5bf1beb083afb0731294cfeaca62944 (diff) | |
download | mitmproxy-58dba3f49083288e19f6e9edb7cc60e88dd446e3.tar.gz mitmproxy-58dba3f49083288e19f6e9edb7cc60e88dd446e3.tar.bz2 mitmproxy-58dba3f49083288e19f6e9edb7cc60e88dd446e3.zip |
fixed formatting and added a 'test' (sort of)
Diffstat (limited to 'libmproxy/utils.py')
-rw-r--r-- | libmproxy/utils.py | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/libmproxy/utils.py b/libmproxy/utils.py index a50be7fc..e608c8a3 100644 --- a/libmproxy/utils.py +++ b/libmproxy/utils.py @@ -11,20 +11,14 @@ def timestamp(): 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) - + s = time.localtime(s) + d = datetime.datetime.fromtimestamp(time.mktime(s)) + return d.strftime("%Y-%m-%d %H:%M:%S") + +def format_timestamp_with_milli(s): + d = datetime.datetime.fromtimestamp(s) + return d.strftime("%Y-%m-%d %H:%M:%S.")+str(d.microsecond/1000).zfill(3) + def isBin(s): """ Does this string have any non-ASCII characters? |