Skip to content

Commit

Permalink
Remove default arguments to support node 4
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorr committed Aug 11, 2019
1 parent d0bd15c commit 3fcc1f3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
10 changes: 6 additions & 4 deletions lib/packets/packet.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ class Packet {
return new Date(str + timezone);
}

readDateTimeString(decimals, timeSep = ' ') {
readDateTimeString(decimals, timeSep) {
const length = this.readInt8();
let y = 0;
let m = 0;
Expand All @@ -309,9 +309,11 @@ class Packet {
H = this.readInt8();
M = this.readInt8();
S = this.readInt8();
str += `${timeSep}${[leftPad(2, H), leftPad(2, M), leftPad(2, S)].join(
':'
)}`;
str += `${timeSep || ' '}${[
leftPad(2, H),
leftPad(2, M),
leftPad(2, S)
].join(':')}`;
}
if (length > 10) {
ms = this.readInt32();
Expand Down
15 changes: 12 additions & 3 deletions test/integration/connection/test-datetime.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,30 @@ const date3 = null;
const date4 = '2010-12-10 14:12:09.123456';
const date5 = '2010-12-10 14:12:09.019';

function adjustTZ(d, offset = d.getTimezoneOffset()) {
function adjustTZ(d, offset) {
if (offset === undefined) {
offset = d.getTimezoneOffset();
}
return new Date(d.getTime() - offset * 60000);
}

function toMidnight(d, offset = d.getTimezoneOffset()) {
function toMidnight(d, offset) {
const t = d.getTime();
if (offset === undefined) {
offset = d.getTimezoneOffset();
}
return new Date(t - (t % (24 * 60 * 60 * 1000)) + offset * 60000);
}

function formatUTCDate(d) {
return d.toISOString().substring(0, 10);
}

function formatUTCDateTime(d, precision = 0) {
function formatUTCDateTime(d, precision) {
const raw = d.toISOString().replace('T', ' ');
if (precision === undefined) {
precision = 0;
}
return precision <= 3
? raw.substring(0, 19 + (precision && 1) + precision)
: raw.substring(0, 23) + '0'.repeat(precision - 3);
Expand Down

0 comments on commit 3fcc1f3

Please sign in to comment.