Skip to content

Commit

Permalink
Merge pull request #50 from SpiNNakerManchester/bug-49/timezone
Browse files Browse the repository at this point in the history
Corrections to timestamp rendering
  • Loading branch information
Christian-B committed Oct 21, 2020
2 parents c364e10 + 4a2b7c6 commit 74cebab
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 18 deletions.
2 changes: 0 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,4 @@
six>=1.8.0
appdirs
enum-compat
pytz
tzlocal
future
2 changes: 0 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@
install_requires=["six>=1.8.0",
"appdirs",
"enum-compat",
"pytz",
"tzlocal",
"future"],
# Scripts
entry_points={
Expand Down
8 changes: 8 additions & 0 deletions spalloc/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from datetime import datetime
import time


Expand All @@ -38,3 +39,10 @@ def make_timeout(delay_seconds):
if delay_seconds is None:
return None
return time.time() + delay_seconds


def render_timestamp(timestamp):
""" Convert a timestamp (Unix seconds) into a local human-readable\
timestamp string.
"""
return datetime.fromtimestamp(timestamp).strftime("%d/%m/%Y %H:%M:%S")
9 changes: 2 additions & 7 deletions spalloc/scripts/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,12 @@
"""
import argparse
from collections import OrderedDict
import datetime
import sys
from pytz import utc
from tzlocal import get_localzone
from six import iteritems
from spalloc import __version__, JobState
from spalloc.term import (
Terminal, render_definitions, render_boards, DEFAULT_BOARD_EDGES)
from spalloc._utils import render_timestamp
from .support import Terminate, Script


Expand Down Expand Up @@ -131,10 +129,7 @@ def show_job_info(t, client, timeout, job_id):
info["Owner"] = job["owner"]
info["State"] = _state_name(job)
if job["start_time"] is not None:
utc_timestamp = datetime.datetime.fromtimestamp(
job["start_time"], utc)
local_timestamp = utc_timestamp.astimezone(get_localzone())
info["Start time"] = local_timestamp.strftime('%d/%m/%Y %H:%M:%S')
info["Start time"] = render_timestamp(job["start_time"])
info["Keepalive"] = job["keepalive"]
if "keepalivehost" in job and job["keepalivehost"] is not None:
info["Owner host"] = job["keepalivehost"]
Expand Down
9 changes: 2 additions & 7 deletions spalloc/scripts/ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@
``--machine`` arguments.
"""
import argparse
import datetime
import sys
from pytz import utc
from tzlocal import get_localzone
from spalloc import __version__, JobState
from spalloc.term import Terminal, render_table
from spalloc._utils import render_timestamp
from .support import Script


Expand Down Expand Up @@ -90,10 +88,7 @@ def render_job_list(t, jobs, args):
num_boards = "" if job["boards"] is None else len(job["boards"])

# Format start time
utc_timestamp = datetime.datetime.fromtimestamp(
job["start_time"], utc)
local_timestamp = utc_timestamp.astimezone(get_localzone())
timestamp = local_timestamp.strftime('%d/%m/%Y %H:%M:%S')
timestamp = render_timestamp(job["start_time"])

if job["allocated_machine_name"] is not None:
machine_name = job["allocated_machine_name"]
Expand Down

0 comments on commit 74cebab

Please sign in to comment.