Skip to content

Fixes #636. Prevents losing days when using date columns in certain timezones. #646

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/protocol/packets/RowDataPacket.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ RowDataPacket.prototype._typeCast = function(field, parser, timeZone, supportBig
return dateString;
}

/* If the stored value was a DATE string, then passing this string to
the Date() constructor will make JavaScript assume that the time is
00:00:00. If, in addition, we have a positive time zone offset, we will
lose one day in the final result. In order to prevent that, we add
24 hours to the parsed date.
See <https://github.com/felixge/node-mysql/issues/636>. */
if (timeZone == 'local' && field.type === Types.DATE && dt.getTimezoneOffset() > 0) {
dt.setSeconds(dt.getSeconds() + 60*60*24);
}

return dt;
case Types.TINY:
case Types.SHORT:
Expand Down