From 662581bff00a8cc145e4c07ea25be92cfeedc013 Mon Sep 17 00:00:00 2001 From: storm64 Date: Thu, 21 Apr 2022 22:05:12 +0200 Subject: [PATCH 1/2] [sched] Update lib.js Correct `decodeTime(t)` to return a more likely expected time: - before: `require("sched").decodeTime(60*60*1000-1)` returns: `{ hrs: 0, mins: 60 }` - after: `require("sched").decodeTime(60*60*1000-1)` returns: `{ hrs: 1, mins: 0 }` --- apps/sched/lib.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/sched/lib.js b/apps/sched/lib.js index 58ba5daf0..6211f4837 100644 --- a/apps/sched/lib.js +++ b/apps/sched/lib.js @@ -110,9 +110,9 @@ exports.setSettings = function(settings) { // time in ms -> { hrs, mins } exports.decodeTime = function(t) { - t = 0 | t; // sanitise - let hrs = 0 | (t / 3600000); - return { hrs: hrs, mins: Math.round((t - hrs * 3600000) / 60000) }; + t = Math.ceil(t / 60000); // sanitise to full minutes + let hrs = 0 | (t / 60); + return { hrs: hrs, mins: t - hrs * 60; } // time in { hrs, mins } -> ms From 052c1694d262381e09889a7a4b87fa20d7c7c7ac Mon Sep 17 00:00:00 2001 From: storm64 Date: Thu, 21 Apr 2022 23:01:39 +0200 Subject: [PATCH 2/2] [Sched] Correct `decodeTime(t)` rounding Correct `decodeTime(t)` to return a more likely expected time: - before: `require("sched").decodeTime(60*60*1000-1)` returns: `{ hrs: 0, mins: 60 }` - after: `require("sched").decodeTime(60*60*1000-1)` returns: `{ hrs: 1, mins: 0 }` --- apps/sched/ChangeLog | 1 + apps/sched/lib.js | 2 +- apps/sched/metadata.json | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/sched/ChangeLog b/apps/sched/ChangeLog index 7372f9c4a..d944e7eed 100644 --- a/apps/sched/ChangeLog +++ b/apps/sched/ChangeLog @@ -4,3 +4,4 @@ 0.04: Fix `getTimeToAlarm` to check for next dow if alarm.t lower currentTime. 0.05: Export new functions (`newDefaultAlarm/Timer`), add Settings page 0.06: Refactor some methods to library +0.07: Correct `decodeTime(t)` to return a more likely expected time diff --git a/apps/sched/lib.js b/apps/sched/lib.js index 6211f4837..0eeea68e3 100644 --- a/apps/sched/lib.js +++ b/apps/sched/lib.js @@ -112,7 +112,7 @@ exports.setSettings = function(settings) { exports.decodeTime = function(t) { t = Math.ceil(t / 60000); // sanitise to full minutes let hrs = 0 | (t / 60); - return { hrs: hrs, mins: t - hrs * 60; + return { hrs: hrs, mins: t - hrs * 60 }; } // time in { hrs, mins } -> ms diff --git a/apps/sched/metadata.json b/apps/sched/metadata.json index 5f61d7d04..c41e5b5b3 100644 --- a/apps/sched/metadata.json +++ b/apps/sched/metadata.json @@ -1,7 +1,7 @@ { "id": "sched", "name": "Scheduler", - "version": "0.06", + "version": "0.07", "description": "Scheduling library for alarms and timers", "icon": "app.png", "type": "scheduler",