Add DateTime writing support to SLMessages

There may be some value in providing a read version of this as well, but
it is comprised of so many properties that I'm leaving that out for now.
If it becomes a need in the future, it will be straightforward to add.
This commit is contained in:
2021-09-06 22:45:41 -05:00
parent 37d40b3386
commit f271554d89
2 changed files with 32 additions and 0 deletions

View File

@ -150,6 +150,21 @@ exports.SLMessage = class SLMessage extends SmartBuffer {
return 0;
}
writeSLDateTime(date) {
this.writeInt16LE(date.getFullYear());
this.writeInt16LE(date.getMonth() + 1);
var dayOfWeek = date.getDay() - 1;
if (dayOfWeek < 0) {
dayOfWeek = 6;
}
this.writeInt16LE(dayOfWeek);
this.writeInt16LE(date.getDate());
this.writeInt16LE(date.getHours());
this.writeInt16LE(date.getMinutes());
this.writeInt16LE(date.getSeconds());
this.writeInt16LE(date.getMilliseconds());
}
static slackForAlignment(val) {
return (4 - val % 4) % 4;
}