Skip to content

Commit

Permalink
use Z isoformat in UTC timestamps
Browse files Browse the repository at this point in the history
instead of +00:00
  • Loading branch information
minrk committed Nov 13, 2016
1 parent 3f21dc2 commit 5d80a46
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 23 deletions.
22 changes: 9 additions & 13 deletions notebook/services/contents/tz.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,11 @@
Just UTC-awareness right now
"""

#-----------------------------------------------------------------------------
# Copyright (C) 2013 The IPython Development Team
#
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#-----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.

from datetime import tzinfo, timedelta, datetime

#-----------------------------------------------------------------------------
# Code
#-----------------------------------------------------------------------------
# constant for zero offset
ZERO = timedelta(0)

Expand All @@ -44,3 +33,10 @@ def utc_method(*args, **kwargs):

utcfromtimestamp = utc_aware(datetime.utcfromtimestamp)
utcnow = utc_aware(datetime.utcnow)

def isoformat(dt):
"""Return iso-formatted timestamp
Like .isoformat(), but uses Z for UTC instead of +00:00
"""
return dt.isoformat().replace('+00:00', 'Z')
4 changes: 2 additions & 2 deletions notebook/services/kernels/kernelmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from traitlets import Dict, List, Unicode, TraitError, default, validate

from notebook.utils import to_os_path
from notebook.services.contents.tz import utcnow
from notebook.services.contents.tz import utcnow, isoformat
from ipython_genutils.py3compat import getcwd


Expand Down Expand Up @@ -177,7 +177,7 @@ def kernel_model(self, kernel_id):
model = {
"id":kernel_id,
"name": kernel.kernel_name,
"last_activity": kernel.last_activity,
"last_activity": isoformat(kernel.last_activity),
"execution_state": kernel.execution_state,
"connections": self._kernel_connections[kernel_id],
}
Expand Down
16 changes: 8 additions & 8 deletions notebook/services/sessions/tests/test_sessionmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_get_session(self):
'kernel': {
'id': 'A',
'name': 'bar',
'last_activity': dummy_date,
'last_activity': dummy_date_s,
'execution_state': 'idle',
}}
self.assertEqual(model, expected)
Expand Down Expand Up @@ -116,7 +116,7 @@ def test_list_sessions(self):
'kernel': {
'id': 'A',
'name':'python',
'last_activity': dummy_date,
'last_activity': dummy_date_s,
'execution_state': 'idle',
}
}, {
Expand All @@ -127,7 +127,7 @@ def test_list_sessions(self):
'kernel': {
'id': 'B',
'name':'python',
'last_activity': dummy_date,
'last_activity': dummy_date_s,
'execution_state': 'idle',
}
}, {
Expand All @@ -138,7 +138,7 @@ def test_list_sessions(self):
'kernel': {
'id': 'C',
'name':'python',
'last_activity': dummy_date,
'last_activity': dummy_date_s,
'execution_state': 'idle',
}
}
Expand All @@ -164,7 +164,7 @@ def test_list_sessions_dead_kernel(self):
'kernel': {
'id': 'B',
'name':'python',
'last_activity': dummy_date,
'last_activity': dummy_date_s,
'execution_state': 'idle',
}
}
Expand All @@ -185,7 +185,7 @@ def test_update_session(self):
'kernel': {
'id': 'A',
'name':'julia',
'last_activity': dummy_date,
'last_activity': dummy_date_s,
'execution_state': 'idle',
}
}
Expand Down Expand Up @@ -216,7 +216,7 @@ def test_delete_session(self):
'kernel': {
'id': 'A',
'name':'python',
'last_activity': dummy_date,
'last_activity': dummy_date_s,
'execution_state': 'idle',
}
}, {
Expand All @@ -227,7 +227,7 @@ def test_delete_session(self):
'kernel': {
'id': 'C',
'name':'python',
'last_activity': dummy_date,
'last_activity': dummy_date_s,
'execution_state': 'idle',
}
}
Expand Down
5 changes: 5 additions & 0 deletions notebook/services/sessions/tests/test_sessions_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ def test_modify_kernel_name(self):
r = requests.get(url_path_join(self.base_url(), 'api/kernels'))
r.raise_for_status()
kernel_list = r.json()
after['kernel'].pop('last_activity')
[ k.pop('last_activity') for k in kernel_list ]
self.assertEqual(kernel_list, [after['kernel']])

def test_modify_kernel_id(self):
Expand All @@ -248,4 +250,7 @@ def test_modify_kernel_id(self):
r = requests.get(url_path_join(self.base_url(), 'api/kernels'))
r.raise_for_status()
kernel_list = r.json()

kernel.pop('last_activity')
[ k.pop('last_activity') for k in kernel_list ]
self.assertEqual(kernel_list, [kernel])

0 comments on commit 5d80a46

Please sign in to comment.