diff --git a/pysnooper/pycompat.py b/pysnooper/pycompat.py index ce7566e..5b9a481 100644 --- a/pysnooper/pycompat.py +++ b/pysnooper/pycompat.py @@ -6,6 +6,7 @@ import abc import os import inspect import sys +import datetime as datetime_module PY3 = (sys.version_info[0] == 3) PY2 = not PY3 @@ -64,3 +65,18 @@ try: from collections import abc as collections_abc except ImportError: # Python 2.7 import collections as collections_abc + +if sys.version_info[:2] >= (3, 6): + time_isoformat = datetime_module.time.isoformat +else: + def time_isoformat(time, timespec='microseconds'): + assert isinstance(time, datetime_module.time) + if timespec != 'microseconds': + raise NotImplementedError + result = '{:02d}:{:02d}:{:02d}.{:06d}'.format( + time.hour, time.minute, time.second, time.microsecond + ) + assert len(result) == 15 + return result + + diff --git a/pysnooper/tracer.py b/pysnooper/tracer.py index b1b1a16..c62da1b 100644 --- a/pysnooper/tracer.py +++ b/pysnooper/tracer.py @@ -346,7 +346,8 @@ class Tracer: # # ### Finished checking whether we should trace this line. ############## - now_string = datetime_module.datetime.now().time().isoformat() + now = datetime_module.datetime.now().time() + now_string = pycompat.time_isoformat(now, timespec='microseconds') line_no = frame.f_lineno source_path, source = get_path_and_source_from_frame(frame) if self.last_source_path != source_path: