Skip to content

Commit 586486d

Browse files
committed
Add 'started' timestamp to output (with local timezone)
1 parent 7fac5ac commit 586486d

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ $ pip install ipython-autotime
1111

1212
```python
1313
In [1]: %load_ext autotime
14-
time: 295 µs
14+
time: 264 µs (started: 2020-12-15 11:44:36+0100)
1515

1616
In [2]: x = 1
17-
time: 519 µs
17+
time: 416 µs (started: 2020-12-15 11:44:45+0100)
1818

1919
In [3]: x / 0
2020
---------------------------------------------------------------------------
@@ -23,7 +23,7 @@ ZeroDivisionError Traceback (most recent call last)
2323
----> 1 x/0
2424

2525
ZeroDivisionError: division by zero
26-
time: 79.7 ms
26+
time: 88.7 ms (started: 2020-12-15 11:44:53+0100)
2727
```
2828

2929
## Want to turn it off?

autotime/__init__.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from ._version import version as __version__
44

5+
from time import strftime, localtime
6+
57
try:
68
from time import monotonic
79
except ImportError:
@@ -17,14 +19,20 @@ class LineWatcher(object):
1719
-----
1820
* Register the `start` and `stop` methods with the IPython events API.
1921
"""
20-
__slots__ = ['start_time']
22+
__slots__ = ['start_time', 'timestamp']
2123

2224
def start(self):
25+
self.timestamp = localtime()
2326
self.start_time = monotonic()
2427

2528
def stop(self):
2629
delta = monotonic() - self.start_time
27-
print(u'time: {}'.format(format_delta(delta)))
30+
print(
31+
u'time: {} (started: {})'.format(
32+
format_delta(delta),
33+
strftime('%Y-%m-%d %H:%M:%S%z', self.timestamp),
34+
)
35+
)
2836

2937

3038
timer = LineWatcher()

tests/test_autotime.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def test_full_cycle():
1010
with tt.AssertPrints('time: '):
1111
ip.run_cell('%load_ext autotime')
1212

13-
with tt.AssertPrints('time: '):
13+
with tt.AssertPrints(' (started: '):
1414
ip.run_cell('x = 1')
1515

1616
with tt.AssertNotPrints('time: '):

0 commit comments

Comments
 (0)