Skip to content

Commit bde8717

Browse files
committed
Storing timezone-less dates in local time instead of UTC
Issue brianc#225 caused such dates to be read, but not stored in local time.
1 parent b33c266 commit bde8717

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

lib/utils.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function arrayString(val) {
4747
//for complex types, etc...
4848
var prepareValue = function(val) {
4949
if(val instanceof Date) {
50-
return JSON.stringify(val);
50+
return dateToString(val);
5151
}
5252
if(typeof val === 'undefined') {
5353
return null;
@@ -58,6 +58,33 @@ var prepareValue = function(val) {
5858
return val === null ? null : val.toString();
5959
};
6060

61+
function dateToString(date) {
62+
function pad(number, digits) {
63+
number = ""+number;
64+
while(number.length < digits)
65+
number = "0"+number;
66+
return number;
67+
}
68+
69+
var offset = -date.getTimezoneOffset();
70+
var ret = pad(date.getFullYear(), 4) + '-'
71+
+ pad(date.getMonth() + 1, 2) + '-'
72+
+ pad(date.getDate(), 2) + 'T'
73+
+ pad(date.getHours(), 2) + ':'
74+
+ pad(date.getMinutes(), 2) + ':'
75+
+ pad(date.getSeconds(), 2) + '.'
76+
+ pad(date.getMilliseconds(), 3);
77+
78+
if(offset < 0) {
79+
ret += "-";
80+
offset *= -1;
81+
}
82+
else
83+
ret += "+";
84+
85+
return ret + pad(Math.floor(offset/60), 2) + ":" + pad(offset%60, 2);
86+
}
87+
6188
function normalizeQueryConfig (config, values, callback) {
6289
//can take in strings or config objects
6390
config = (typeof(config) == 'string') ? { text: config } : config;

0 commit comments

Comments
 (0)