diff --git a/lib/protocol/packets/RowDataPacket.js b/lib/protocol/packets/RowDataPacket.js index 09f3fb2b9..08efd91f0 100644 --- a/lib/protocol/packets/RowDataPacket.js +++ b/lib/protocol/packets/RowDataPacket.js @@ -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 . */ + 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: