From ce4bfd56c20fb080ca36dee92850bf44e6b11843 Mon Sep 17 00:00:00 2001 From: JonnyWong16 Date: Sat, 27 Apr 2019 16:58:23 -0700 Subject: [PATCH] Fix scheduler table displaying intervals greater than 24 hours --- data/interfaces/default/scheduler_table.html | 15 +++++++-------- plexpy/helpers.py | 8 ++++++++ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/data/interfaces/default/scheduler_table.html b/data/interfaces/default/scheduler_table.html index 37fd861c..dc66ebb7 100644 --- a/data/interfaces/default/scheduler_table.html +++ b/data/interfaces/default/scheduler_table.html @@ -10,9 +10,9 @@ DOCUMENTATION :: END <%! - import arrow + import datetime import plexpy - from plexpy import common + from plexpy import common, helpers scheduled_jobs = [j.id for j in plexpy.SCHED.get_jobs()] %> @@ -31,16 +31,15 @@ DOCUMENTATION :: END % for job in common.SCHEDULER_LIST: % if job in scheduled_jobs: <% - sched_job = plexpy.SCHED.get_job(job) - run_interval = arrow.get(str(sched_job.trigger.interval), ['H:mm:ss', 'HH:mm:ss']) - next_run_interval = arrow.get(sched_job.next_run_time).timestamp - arrow.now().timestamp + sched_job = plexpy.SCHED.get_job(job) + now = datetime.datetime.now(sched_job.next_run_time.tzinfo) %> ${sched_job.id} Active - ${arrow.get(run_interval).format('HH:mm:ss')} - ${arrow.get(next_run_interval).format('HH:mm:ss')} - ${arrow.get(sched_job.next_run_time).format('YYYY-MM-DD HH:mm:ss')} + ${helpers.format_timedelta_Hms(sched_job.trigger.interval)} + ${helpers.format_timedelta_Hms(sched_job.next_run_time - now)} + ${sched_job.next_run_time.strftime('%Y-%m-%d %H:%M:%S')} % elif job in ('Check for server response', 'Check for active sessions', 'Check for recently added items') and plexpy.WS_CONNECTED: diff --git a/plexpy/helpers.py b/plexpy/helpers.py index fbd7d205..2c6fc740 100644 --- a/plexpy/helpers.py +++ b/plexpy/helpers.py @@ -252,6 +252,14 @@ def human_duration(s, sig='dhms'): return hd +def format_timedelta_Hms(td): + s = td.total_seconds() + hours = s // 3600 + minutes = (s % 3600) // 60 + seconds = s % 60 + return '{:02d}:{:02d}:{:02d}'.format(int(hours), int(minutes), int(seconds)) + + def get_age(date): try: