Skip to content

Commit d0a88ef

Browse files
bbitoKevin Delisle
authored and
Kevin Delisle
committed
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: d0ea1d9 Legacy UTC date processing fallback credit: @darknos a59dad7 Remove orphaned string functions e8fdbdc Incorporate @darknos expanded check for zero dates abd4e0a Remove DATE manipulations in from/toColumnValue
1 parent ea33f55 commit d0a88ef

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

lib/mysql.js

+8-16
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,13 @@ function generateOptions(settings) {
152152
options[p] = s[p];
153153
}
154154
}
155+
// Legacy UTC Date Processing fallback - SHOULD BE TRANSITIONAL
156+
if (s.legacyUtcDateProcessing === undefined) {
157+
s.legacyUtcDateProcessing = true;
158+
}
159+
if (s.legacyUtcDateProcessing) {
160+
options.timezone = 'Z';
161+
}
155162
}
156163
return options;
157164
}
@@ -307,19 +314,6 @@ MySQL.prototype.updateOrCreate = function(model, data, options, cb) {
307314
this._modifyOrCreate(model, data, options, fields, cb);
308315
};
309316

310-
function dateToMysql(val) {
311-
return val.getUTCFullYear() + '-' +
312-
fillZeros(val.getUTCMonth() + 1) + '-' +
313-
fillZeros(val.getUTCDate()) + ' ' +
314-
fillZeros(val.getUTCHours()) + ':' +
315-
fillZeros(val.getUTCMinutes()) + ':' +
316-
fillZeros(val.getUTCSeconds());
317-
318-
function fillZeros(v) {
319-
return v < 10 ? '0' + v : v;
320-
}
321-
}
322-
323317
MySQL.prototype.getInsertedId = function(model, info) {
324318
var insertedId = info && typeof info.insertId === 'number' ?
325319
info.insertId : undefined;
@@ -356,7 +350,7 @@ MySQL.prototype.toColumnValue = function(prop, val) {
356350
if (!val.toUTCString) {
357351
val = new Date(val);
358352
}
359-
return dateToMysql(val);
353+
return val;
360354
}
361355
if (prop.type === Boolean) {
362356
return !!val;
@@ -417,8 +411,6 @@ MySQL.prototype.fromColumnValue = function(prop, val) {
417411
// those separate.
418412
if (val == '0000-00-00 00:00:00') {
419413
val = null;
420-
} else {
421-
val = new Date(val.toString().replace(/GMT.*$/, 'GMT'));
422414
}
423415
break;
424416
case 'Boolean':

0 commit comments

Comments
 (0)