Skip to content

Commit 6c968b8

Browse files
committed
Fix SLDateTime reading
I think this only fails on the last day of the month or during a certain window of time. date.setMonth() has an optional "day" argument that also fixed this problem, but I was nervous enough about the initial problem to go with the nuclear option of setting all date attributes at once so that the month/day/etc. resolution works properly.
1 parent 0834bf4 commit 6c968b8

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

messages/SLMessage.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -162,16 +162,16 @@ exports.SLMessage = class SLMessage extends SmartBuffer {
162162
}
163163

164164
readSLDateTime() {
165-
let date = new Date();
166-
date.setFullYear(this.readInt16LE());
167-
date.setMonth(this.readInt16LE() - 1);
168-
this.readInt16LE();
169-
date.setDate(this.readInt16LE());
170-
date.setHours(this.readInt16LE());
171-
date.setMinutes(this.readInt16LE());
172-
date.setSeconds(this.readInt16LE());
173-
date.setMilliseconds(this.readInt16LE());
174-
165+
let year = this.readInt16LE();
166+
let month = this.readInt16LE() - 1;
167+
this.readInt16LE(); // day of week
168+
let day = this.readInt16LE();
169+
let hour = this.readInt16LE();
170+
let minute = this.readInt16LE();
171+
let second = this.readInt16LE();
172+
let millisecond = this.readInt16LE();
173+
174+
let date = new Date(year, month, day, hour, minute, second, millisecond);
175175
return date;
176176
}
177177

0 commit comments

Comments
 (0)