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:
@ -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
|
||||
|
@ -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());
|
||||
|
@ -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);
|
||||
|
Reference in New Issue
Block a user