mirror of
https://github.com/cool-RR/PySnooper.git
synced 2026-01-23 02:14:04 +00:00
Add timedelta_isoformat
This commit is contained in:
parent
f822104feb
commit
caf1e1a63a
2 changed files with 12 additions and 6 deletions
|
|
@ -80,3 +80,9 @@ else:
|
|||
return result
|
||||
|
||||
|
||||
def timedelta_isoformat(timedelta, timespec='microseconds'):
|
||||
assert isinstance(timedelta, datetime_module.timedelta)
|
||||
if timespec != 'microseconds':
|
||||
raise NotImplementedError
|
||||
time = (datetime_module.datetime.min + timedelta).time()
|
||||
return time_isoformat(time, timespec)
|
||||
|
|
|
|||
|
|
@ -310,9 +310,8 @@ class Tracer:
|
|||
self.target_frames.discard(calling_frame)
|
||||
self.frame_to_local_reprs.pop(calling_frame, None)
|
||||
|
||||
now = (datetime_module.datetime.min + (
|
||||
datetime_module.datetime.now() - self.start_time)).time()
|
||||
now_string = pycompat.time_isoformat(now, timespec='microseconds')
|
||||
duration = datetime_module.datetime.now() - self.start_time
|
||||
now_string = pycompat.timedelta_isoformat(duration, timespec='microseconds')
|
||||
self.write('Total elapsed time: {now_string}'.format(**locals()))
|
||||
|
||||
def _is_internal_frame(self, frame):
|
||||
|
|
@ -360,11 +359,12 @@ class Tracer:
|
|||
### Finished checking whether we should trace this line. ##############
|
||||
|
||||
if self.relative_time:
|
||||
now = (datetime_module.datetime.min +
|
||||
(datetime_module.datetime.now() - self.start_time)).time()
|
||||
duration = datetime_module.datetime.now() - self.start_time
|
||||
now_string = pycompat.timedelta_isoformat(
|
||||
duration, timespec='microseconds') if not self.normalize else ' ' * 15
|
||||
else:
|
||||
now = datetime_module.datetime.now().time()
|
||||
now_string = pycompat.time_isoformat(now, timespec='microseconds') if not self.normalize else ' ' * 15
|
||||
now_string = pycompat.time_isoformat(now, timespec='microseconds') if not self.normalize else ' ' * 15
|
||||
line_no = frame.f_lineno
|
||||
source_path, source = get_path_and_source_from_frame(frame)
|
||||
source_path = source_path if not self.normalize else os.path.basename(source_path)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue