Remove String manipulations of Date objects
This commit contains all previous work after rebase went badly RE: Pull Request requested by @kjdelisle regarding #149 following my proposed solution "A" at #149 (comment). As mentioned in the post linked above, this change allows the underlying mysqljs/mysql module to handle Date object serialization and removes the forced conversion of Dates to UTC Strings. An opt-out fallback to forced coercion to UTC is included, which was modeled after #265 from @darknos . Old, squashed commits: d0ea1d926eae04d0355109c87eef4eeec173f887 Legacy UTC date processing fallback credit: @darknos a59dad7d7bd945895fb410a963cf5932b6a20f9e Remove orphaned string functions e8fdbdcfd4092f3d9e018f688d14def3e3ca9856 Incorporate @darknos expanded check for zero dates abd4e0a7e9122f857974678a6b6ad87a19988f6f Remove DATE manipulations in from/toColumnValue
This commit is contained in:
parent
ea33f557ab
commit
d0a88ef045
24
lib/mysql.js
24
lib/mysql.js
|
@ -152,6 +152,13 @@ function generateOptions(settings) {
|
|||
options[p] = s[p];
|
||||
}
|
||||
}
|
||||
// Legacy UTC Date Processing fallback - SHOULD BE TRANSITIONAL
|
||||
if (s.legacyUtcDateProcessing === undefined) {
|
||||
s.legacyUtcDateProcessing = true;
|
||||
}
|
||||
if (s.legacyUtcDateProcessing) {
|
||||
options.timezone = 'Z';
|
||||
}
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
@ -307,19 +314,6 @@ MySQL.prototype.updateOrCreate = function(model, data, options, cb) {
|
|||
this._modifyOrCreate(model, data, options, fields, cb);
|
||||
};
|
||||
|
||||
function dateToMysql(val) {
|
||||
return val.getUTCFullYear() + '-' +
|
||||
fillZeros(val.getUTCMonth() + 1) + '-' +
|
||||
fillZeros(val.getUTCDate()) + ' ' +
|
||||
fillZeros(val.getUTCHours()) + ':' +
|
||||
fillZeros(val.getUTCMinutes()) + ':' +
|
||||
fillZeros(val.getUTCSeconds());
|
||||
|
||||
function fillZeros(v) {
|
||||
return v < 10 ? '0' + v : v;
|
||||
}
|
||||
}
|
||||
|
||||
MySQL.prototype.getInsertedId = function(model, info) {
|
||||
var insertedId = info && typeof info.insertId === 'number' ?
|
||||
info.insertId : undefined;
|
||||
|
@ -356,7 +350,7 @@ MySQL.prototype.toColumnValue = function(prop, val) {
|
|||
if (!val.toUTCString) {
|
||||
val = new Date(val);
|
||||
}
|
||||
return dateToMysql(val);
|
||||
return val;
|
||||
}
|
||||
if (prop.type === Boolean) {
|
||||
return !!val;
|
||||
|
@ -417,8 +411,6 @@ MySQL.prototype.fromColumnValue = function(prop, val) {
|
|||
// those separate.
|
||||
if (val == '0000-00-00 00:00:00') {
|
||||
val = null;
|
||||
} else {
|
||||
val = new Date(val.toString().replace(/GMT.*$/, 'GMT'));
|
||||
}
|
||||
break;
|
||||
case 'Boolean':
|
||||
|
|
Loading…
Reference in New Issue