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).
This commit is contained in:
2022-04-15 16:17:18 -05:00
parent de8bba63a0
commit e0136a01cd
3 changed files with 6 additions and 6 deletions

View File

@ -581,7 +581,7 @@ Contains information about the system's current time and date. Passed as an argu
* `year` - short representing current system year * `year` - short representing current system year
* `month` - short representing current system month (where 1 is January, 2 is February, etc.) * `month` - short representing current system month (where 1 is January, 2 is February, etc.)
* `day` - short representing current system day of the month * `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.) * `hour` - short representing current system hour (24-hour time where 0 is midnight, 13 is 1PM, etc.)
* `minute` - short representing current system minute * `minute` - short representing current system minute
* `second` - short representing current system second * `second` - short representing current system second

View File

@ -153,9 +153,9 @@ exports.SLMessage = class SLMessage extends SmartBuffer {
writeSLDateTime(date) { writeSLDateTime(date) {
this.writeInt16LE(date.getFullYear()); this.writeInt16LE(date.getFullYear());
this.writeInt16LE(date.getMonth() + 1); this.writeInt16LE(date.getMonth() + 1);
var dayOfWeek = date.getDay() - 1; var dayOfWeek = date.getDay() + 1;
if (dayOfWeek < 0) { if (dayOfWeek == 7) {
dayOfWeek = 6; dayOfWeek = 0;
} }
this.writeInt16LE(dayOfWeek); this.writeInt16LE(dayOfWeek);
this.writeInt16LE(date.getDate()); this.writeInt16LE(date.getDate());

View File

@ -181,8 +181,8 @@ describe('SLMessage utilities', function() {
assert.equal(decodedMsg.readUInt16LE(), 2021); assert.equal(decodedMsg.readUInt16LE(), 2021);
// javascript Date() month is 0-based, ScreenLogic month matches the calendar // javascript Date() month is 0-based, ScreenLogic month matches the calendar
assert.equal(decodedMsg.readUInt16LE(), 9); assert.equal(decodedMsg.readUInt16LE(), 9);
// ScreenLogic day-of-week starts with Monday as 0 // ScreenLogic day-of-week starts with Sunday as 1
assert.equal(decodedMsg.readUInt16LE(), 0); assert.equal(decodedMsg.readUInt16LE(), 2);
assert.equal(decodedMsg.readUInt16LE(), 6); assert.equal(decodedMsg.readUInt16LE(), 6);
assert.equal(decodedMsg.readUInt16LE(), 22); assert.equal(decodedMsg.readUInt16LE(), 22);
assert.equal(decodedMsg.readUInt16LE(), 8); assert.equal(decodedMsg.readUInt16LE(), 8);