Skip to content

Commit 321f6df

Browse files
committed
milliseconds for setting date values
1 parent b098d49 commit 321f6df

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

lib/packets/execute.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ function Execute(id, parameters, charsetNumber) {
1111
this.encoding = CharsetToEncoding[charsetNumber];
1212
}
1313

14+
var pad = '000000000000';
15+
function leftPad(num, value) {
16+
var s = value.toString();
17+
// if we don't need to pad
18+
if (s.length >= num) {
19+
return s;
20+
}
21+
return (pad + s).slice(-num);
22+
}
23+
1424
Execute.prototype.toPacket = function() {
1525
// TODO: don't try to calculate packet length in advance, allocate some big buffer in advance (header + 256 bytes?)
1626
// and copy + reallocate if not enough
@@ -36,7 +46,9 @@ Execute.prototype.toPacket = function() {
3646
this.parameters[i] =
3747
[d.getFullYear(), d.getMonth() + 1, d.getDate()].join('-') +
3848
' ' +
39-
[d.getHours(), d.getMinutes(), d.getSeconds()].join(':');
49+
[d.getHours(), d.getMinutes(), d.getSeconds()].join(':') +
50+
'.' + leftPad(3, d.getMilliseconds())
51+
;
4052
}
4153
if (Buffer.isBuffer(this.parameters[i])) {
4254
length += Packet.lengthCodedNumberLength(this.parameters[i].length);

0 commit comments

Comments
 (0)