Skip to content

Commit

Permalink
Added support for milliseconds
Browse files Browse the repository at this point in the history
  • Loading branch information
Mattijah committed Jun 1, 2014
1 parent 7bacacf commit a7be73c
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions lib/sql_string.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,16 @@ SqlString.dateToString = function(date, timeZone) {
dt.setTime(dt.getTime() + (tz * 60000));
}
}

var year = dt.getFullYear();
var month = zeroPad(dt.getMonth() + 1);
var day = zeroPad(dt.getDate());
var hour = zeroPad(dt.getHours());
var minute = zeroPad(dt.getMinutes());
var second = zeroPad(dt.getSeconds());

return year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
var month = zeroPad(dt.getMonth() + 1, 2);
var day = zeroPad(dt.getDate(), 2);
var hour = zeroPad(dt.getHours(), 2);
var minute = zeroPad(dt.getMinutes(), 2);
var second = zeroPad(dt.getSeconds(), 2);
var millisecond = zeroPad(dt.getMilliseconds(), 3);

return year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second + '.' + millisecond;
};

SqlString.bufferToString = function(buffer) {
Expand Down Expand Up @@ -124,8 +125,13 @@ SqlString.objectToValues = function(object, timeZone) {
return values.join(', ');
};

function zeroPad(number) {
return (number < 10) ? '0' + number : number;
function zeroPad(number, length) {
number = number.toString();
while (number.length < length) {
number = '0' + number;
}

return number;
}

function convertTimezone(tz) {
Expand Down

0 comments on commit a7be73c

Please sign in to comment.