From f4ba2b1bbd16770fb51c63145bb574cc92940fba Mon Sep 17 00:00:00 2001 From: orgos Date: Mon, 20 Apr 2015 18:30:24 -0400 Subject: [PATCH] Added milliseconds to the date conversion. --- lib/utils.js | 5 +++-- test/core/utils.js | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index 35efdd7..2cee612 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -220,7 +220,7 @@ exports.encode = function encode (value) { return '"' + exports.escape(value) + '"'; } else if (value instanceof Date) { - return 'date("' + getOrientDbUTCDate(value) + '", "yyyy-MM-dd HH:mm:ss", "UTC")'; + return 'date("' + getOrientDbUTCDate(value) + '", "yyyy-MM-dd HH:mm:ss.SSS", "UTC")'; } else if (value instanceof RID) { return value.toString(); @@ -314,8 +314,9 @@ function getOrientDbUTCDate(date){ var HH = pad(date.getUTCHours(), 2); var mm = pad(date.getUTCMinutes(), 2); var ss = pad(date.getUTCSeconds(), 2); + var SSS = pad(date.getUTCMilliseconds(), 3); - return yyyy + '-' + MM + '-' + dd + ' ' + HH + ':' + mm + ':' + ss; + return yyyy + '-' + MM + '-' + dd + ' ' + HH + ':' + mm + ':' + ss + '.' + SSS; } function pad (number, size){ diff --git a/test/core/utils.js b/test/core/utils.js index d274100..16ce5c9 100644 --- a/test/core/utils.js +++ b/test/core/utils.js @@ -16,8 +16,8 @@ describe('utils.prepare', function () { text.should.equal('SELECT * FROM OUser WHERE foo = "\\/// TE /// ST \\\\\\\\\\\\"'); }); it("should prepare SQL statements with date parameters", function () { - var date = new Date(Date.UTC(2015, 0, 5, 22, 7, 5)); - utils.prepare("select from index:foo where date = :date", {date: date}).should.equal("select from index:foo where date = date(\"2015-01-05 22:07:05\", \"yyyy-MM-dd HH:mm:ss\", \"UTC\")"); + var date = new Date(Date.UTC(2015, 0, 5, 22, 7, 5, 435)); + utils.prepare("select from index:foo where date = :date", {date: date}).should.equal("select from index:foo where date = date(\"2015-01-05 22:07:05.435\", \"yyyy-MM-dd HH:mm:ss.SSS\", \"UTC\")"); }); });