dresende/node-sql-query

about time zone

Closed this issue · 11 comments

why about local time think to +00:00 timezone and not is server local timezone in no-mysql sql?

module.exports.dateToString = function (date, timeZone, opts) {
var dt = new Date(date);
if (timeZone != 'local') {
var tz = convertTimezone(timeZone);
dt.setTime(dt.getTime() + (dt.getTimezoneOffset() * 60000));
if (tz !== false) {
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());
var milli = zeroPad(dt.getMilliseconds(), 3);
if (opts.dialect == 'mysql') {
return year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second + '.' + milli;
} else {
return year + '-' + month + '-' + day + 'T' + hour + ':' + minute + ':' + second + '.' + milli + 'Z';
}
}

I'm sorry, I didn't understand your question.

i mean just if i am use sqlite. and if i use timeZone = local(default is local )
the function dt.getHours() will get my localserver time .but in line 41 add Z sign to see it is a GMT time

for example .in my local time now is Fri Nov 10 2017 23:52:29 GMT+0800
dt.getHours() will return 23
and it return value is 2017-10-09T23:52:29Z

i dont think its a right time because when i use new Date('2017-10-09T23:52:29Z') will return Tue Oct 10 2017 07:52:29 GMT+0800
in my mind. line 41 should change to

return year + '-' + month + '-' + day + 'T' + hour + ':' + minute + ':' + second + '.' + milli; 

is any special reason to add Z in the end of string?

I'm not actually sure to be honest. You can see there's a condition there. I tested to fully work (it should) in mysql (that's the condition there) and the else is there mainly for postgres since I know it supports timezones. You also have to put the code in perspective, 3 years ago.

Does sqlite support timezones? Probably not. Perhaps it should behave the same as mysql and don't add timezone. Do you have any other suggestion?

I never use postgresql so i have no idea about it...
but i dont think use the 'Z' sign to record time is a good idea if you want to use local datetime to record .
I like your project node-orm2, it run well in mysql but its some bug in sqlite(i use sqlite because i would like to publish my project to some noob who maybe not want to install mysql or other professional sql)
In sqlite, it just save as a string like a txt file. and the bug is generated with different between CST and GMT
save with CST and read with GMT you know .
ofcause i can declare timeZone field by my local timezone.but i not think it a good solution.
not send a PR because i just use mysql and sqlite or other nosql like mongo:)

The idea of using Z is to indicate the database we're saving in UTC. That's why it shifts the date according to the timezone you specify. Perhaps it should handle local timezone in a special way and it's not doing it.

Check if this solves your problem. If it does, I'll update orm dependency.

just try and copy the commit(b7dc7f0) in Helpers,
in sqlite save date with 2017-11-14 22:42:55.787. but orm still return a Date object with 2017-11-14T22:42:55.787Z
maybe process a date type in orm when read data from sql and return a Date object?

Are you defining timezone as local in orm?

i am not set config of timezone.
orm will set to local if i dont set timezone in config, didnt it?
/lib/Drivers/DML/sqlite.js

I believe it does. Perhaps you should open a ticket on orm and discuss with them. I no longer maintain it, just small things.

well. i just open a issue in this project because i find the orm source code and seek into this project