Skip to content

Commit b83ccf6

Browse files
committed
Add colon in timezone, add space before timezone
1 parent 586486d commit b83ccf6

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

Diff for: README.md

+3-3
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: 264 µs (started: 2020-12-15 11:44:36+0100)
14+
time: 264 µs (started: 2020-12-15 11:44:36 +01:00)
1515

1616
In [2]: x = 1
17-
time: 416 µs (started: 2020-12-15 11:44:45+0100)
17+
time: 416 µs (started: 2020-12-15 11:44:45 +01:00)
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: 88.7 ms (started: 2020-12-15 11:44:53+0100)
26+
time: 88.7 ms (started: 2020-12-15 11:44:53 +01:00)
2727
```
2828

2929
## Want to turn it off?

Diff for: autotime/__init__.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
from IPython.core.magics.execution import _format_time as format_delta
1313

1414

15+
def format_timestamp(struct_time):
16+
timestamp = strftime('%Y-%m-%d %H:%M:%S %z', struct_time)
17+
# add colon in %z (for datetime.fromisoformat, stackoverflow.com/q/44836581)
18+
return '{}:{}'.format(timestamp[:-2], timestamp[-2:])
19+
20+
1521
class LineWatcher(object):
1622
"""Class that implements a basic timer.
1723
@@ -30,7 +36,7 @@ def stop(self):
3036
print(
3137
u'time: {} (started: {})'.format(
3238
format_delta(delta),
33-
strftime('%Y-%m-%d %H:%M:%S%z', self.timestamp),
39+
format_timestamp(self.timestamp),
3440
)
3541
)
3642

0 commit comments

Comments
 (0)