From e0136a01cde7e2bd0f9efff8ffddd4786c871119 Mon Sep 17 00:00:00 2001 From: Parnic Date: Fri, 15 Apr 2022 16:17:18 -0500 Subject: [PATCH] Fix SLDateTime day-of-week calculation Turns out we were offsetting the wrong direction. This offsets the correct way (verified against a Wireshark capture of the official app). --- README.md | 2 +- messages/SLMessage.js | 6 +++--- test/slmessage.spec.js | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 2c8831d..10be86c 100755 --- a/README.md +++ b/README.md @@ -581,7 +581,7 @@ Contains information about the system's current time and date. Passed as an argu * `year` - short representing current system year * `month` - short representing current system month (where 1 is January, 2 is February, etc.) * `day` - short representing current system day of the month -* `dayOfWeek` - short representing current system day of the week (where 0 is Sunday and 6 is Sunday) +* `dayOfWeek` - short representing current system day of the week (where 1 is Sunday and 7 is Saturday) * `hour` - short representing current system hour (24-hour time where 0 is midnight, 13 is 1PM, etc.) * `minute` - short representing current system minute * `second` - short representing current system second diff --git a/messages/SLMessage.js b/messages/SLMessage.js index 89dab34..5b23a0b 100644 --- a/messages/SLMessage.js +++ b/messages/SLMessage.js @@ -153,9 +153,9 @@ exports.SLMessage = class SLMessage extends SmartBuffer { writeSLDateTime(date) { this.writeInt16LE(date.getFullYear()); this.writeInt16LE(date.getMonth() + 1); - var dayOfWeek = date.getDay() - 1; - if (dayOfWeek < 0) { - dayOfWeek = 6; + var dayOfWeek = date.getDay() + 1; + if (dayOfWeek == 7) { + dayOfWeek = 0; } this.writeInt16LE(dayOfWeek); this.writeInt16LE(date.getDate()); diff --git a/test/slmessage.spec.js b/test/slmessage.spec.js index ee67215..981fdb9 100644 --- a/test/slmessage.spec.js +++ b/test/slmessage.spec.js @@ -181,8 +181,8 @@ describe('SLMessage utilities', function() { assert.equal(decodedMsg.readUInt16LE(), 2021); // javascript Date() month is 0-based, ScreenLogic month matches the calendar assert.equal(decodedMsg.readUInt16LE(), 9); - // ScreenLogic day-of-week starts with Monday as 0 - assert.equal(decodedMsg.readUInt16LE(), 0); + // ScreenLogic day-of-week starts with Sunday as 1 + assert.equal(decodedMsg.readUInt16LE(), 2); assert.equal(decodedMsg.readUInt16LE(), 6); assert.equal(decodedMsg.readUInt16LE(), 22); assert.equal(decodedMsg.readUInt16LE(), 8);