formatDate() in data-api-client depends on system timezone
See original GitHub issueI had a problem with inserting values with the timestamp
mysql data type. Javascript Date object 2020-05-28T03:56:48.466Z
was being transformed to "2020-05-28 05:56:48"
. (I am in UTC+2 timezone. Server uses UTC, however I encountered this issue during local development.)
Then I tried running the script with
$ TZ='UTC' node somescript.js
and 2020-05-28T03:56:48.466Z
was correctly transformed to "2020-05-28 03:56:48"
.
I think the problem might be that aws-sdk does not communicate my system timezone to Aurora Data API and expects UTC.
Related source code: https://github.com/ArsenyYankovsky/data-api-client/blob/support-date/index.js#L189
const formatDate = (date) => {
const padNumber = (number) => number <= 9 ? '0' + number : number
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
const hour = date.getHours()
const minutes = date.getMinutes()
const seconds = date.getSeconds()
return year + '-' + padNumber(month) + '-' + padNumber(day) + ' ' + padNumber(hour) + ':' + padNumber(minutes) + ':' + padNumber(seconds)
}
Expected: timestamp string sent to Data API should be in UTC and not be related to system timezone.
Suggested fix: use UTC variants of Date methods like Date.prototype.getUTCHours()
Thanks for this amazing library!
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (4 by maintainers)
Top GitHub Comments
I’ll definitely check it out and let you know. I don’t immediately see any issues with it, but I’ll run some tests and if everything go well publish a new version.
Thank you so much @ArsenyYankovsky 👍. I will give it a try.