No Support for Timezone In xMySQL
ShantanuVidwans opened this issue · 0 comments
In NodeJS, when a connection is initialized for mysql, the default timezone is 'UTC'
If the data stored in the database is not in UTC timezone then when xMySQL fetches the data then the same DateTime is not received.
xMySQL returns the UTC time by converting the local time stored in DB to UTC timezone.
Eg: My time zone is IST (->UTC +5:30)
data in db = "2022-02-01" <- The data is stored in IST TimeZone
data i get from xMySQL = "2022-01-31T18:30:00.000Z" <- See the offset of -5:30 due to timezone not set properly
Solution:
I cloned the repo and found a solution for this. The following command line argument can be added, so timezone can also be supported by xMySQL.
cmd.helper.js->
[near line 74]
program.timezone = program.timezone || "UTC"; //default to UTC if no timezone provided
[near line 19]
.option("-t, --timezone ", "set the timezone")
adding this will cause the code to add the timzone parameter in the "sqlConfig".
Internally it would end up like this:
var sqlConfig= {
host : 'localhost',
user : 'xxx',
password : '',
database : 'xxx',
timezone: 'IST' //<-the timzone added after the above code change
};
Comment on this Issue if you choose to use these changes. Will improve my quality of life