不要怂,就是干,撸起袖子干!

Commit 53795052 by Mick Hansen

Merge pull request #4116 from gutobortolozzo/issue-4007-1

Sequelize doesn't compare dates correctly
2 parents 3a4ff4a6 8eafb4e9
...@@ -339,8 +339,13 @@ Instance.prototype.set = function(key, value, options) { // testhint options:non ...@@ -339,8 +339,13 @@ Instance.prototype.set = function(key, value, options) { // testhint options:non
} }
// Convert date fields to real date objects // Convert date fields to real date objects
if (this.Model._hasDateAttributes && this.Model._isDateAttribute(key) && value !== null && value !== undefined && !(value instanceof Date) && !value._isSequelizeMethod) { if (this.Model._hasDateAttributes && this.Model._isDateAttribute(key) && !!value && !value._isSequelizeMethod) {
value = new Date(value); if (!(value instanceof Date)) {
value = new Date(value);
}
if (originalValue && value.getTime() === originalValue.getTime()) {
return;
}
} }
} }
......
...@@ -62,6 +62,22 @@ describe(Support.getTestDialectTeaser('Instance'), function() { ...@@ -62,6 +62,22 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
expect(user.changed('birthdate')).to.equal(true); expect(user.changed('birthdate')).to.equal(true);
}); });
it('should return false for two instances with same value', function () {
var milliseconds = 1436921941088;
var firstDate = new Date(milliseconds);
var secondDate = new Date(milliseconds);
var user = this.User.build({
birthdate: firstDate
}, {
isNewRecord: false,
raw: true
});
user.set('birthdate', secondDate);
expect(user.changed('birthdate')).to.equal(false);
});
it('should return true for changed JSON with same object', function () { it('should return true for changed JSON with same object', function () {
var user = this.User.build({ var user = this.User.build({
meta: { meta: {
...@@ -79,4 +95,4 @@ describe(Support.getTestDialectTeaser('Instance'), function() { ...@@ -79,4 +95,4 @@ describe(Support.getTestDialectTeaser('Instance'), function() {
expect(user.changed('meta')).to.equal(true); expect(user.changed('meta')).to.equal(true);
}); });
}); });
}); });
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!