Storing timezone-less dates in local time instead of UTC

Issue #225 caused such dates to be read, but not stored in local time.
This commit is contained in:
Candid Dauth 2013-01-14 18:07:18 +01:00
parent b33c266734
commit bde871707b

View File

@ -47,7 +47,7 @@ function arrayString(val) {
//for complex types, etc... //for complex types, etc...
var prepareValue = function(val) { var prepareValue = function(val) {
if(val instanceof Date) { if(val instanceof Date) {
return JSON.stringify(val); return dateToString(val);
} }
if(typeof val === 'undefined') { if(typeof val === 'undefined') {
return null; return null;
@ -58,6 +58,33 @@ var prepareValue = function(val) {
return val === null ? null : val.toString(); return val === null ? null : val.toString();
}; };
function dateToString(date) {
function pad(number, digits) {
number = ""+number;
while(number.length < digits)
number = "0"+number;
return number;
}
var offset = -date.getTimezoneOffset();
var ret = pad(date.getFullYear(), 4) + '-'
+ pad(date.getMonth() + 1, 2) + '-'
+ pad(date.getDate(), 2) + 'T'
+ pad(date.getHours(), 2) + ':'
+ pad(date.getMinutes(), 2) + ':'
+ pad(date.getSeconds(), 2) + '.'
+ pad(date.getMilliseconds(), 3);
if(offset < 0) {
ret += "-";
offset *= -1;
}
else
ret += "+";
return ret + pad(Math.floor(offset/60), 2) + ":" + pad(offset%60, 2);
}
function normalizeQueryConfig (config, values, callback) { function normalizeQueryConfig (config, values, callback) {
//can take in strings or config objects //can take in strings or config objects
config = (typeof(config) == 'string') ? { text: config } : config; config = (typeof(config) == 'string') ? { text: config } : config;