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

Commit dafcf1da by Sascha Depold

dates do not have precision of milliseconds anymore

1 parent f2eca756
Showing with 14 additions and 8 deletions
...@@ -132,7 +132,7 @@ module.exports = (function() { ...@@ -132,7 +132,7 @@ module.exports = (function() {
} }
if (this.__options.timestamps && this.hasOwnProperty(updatedAtAttr)) { if (this.__options.timestamps && this.hasOwnProperty(updatedAtAttr)) {
this[updatedAtAttr] = values[updatedAtAttr] = new Date() this[updatedAtAttr] = values[updatedAtAttr] = Utils.now()
} }
if (this.isNewRecord) { if (this.isNewRecord) {
...@@ -284,13 +284,13 @@ module.exports = (function() { ...@@ -284,13 +284,13 @@ module.exports = (function() {
DAO.prototype.equals = function(other) { DAO.prototype.equals = function(other) {
var result = true var result = true
, self = this
Utils._.each(this.values, function(value, key) { Utils._.each(this.values, function(value, key) {
if(Utils._.isDate(value) && Utils._.isDate(other[key])) if(Utils._.isDate(value) && Utils._.isDate(other[key])) {
result = result && (value.getTime() == other[key].getTime()) result = result && (value.getTime() == other[key].getTime())
else } else {
result = result && (value == other[key]) result = result && (value == other[key])
}
}) })
return result return result
...@@ -332,8 +332,8 @@ module.exports = (function() { ...@@ -332,8 +332,8 @@ module.exports = (function() {
var defaults = this.hasPrimaryKeys ? {} : { id: null } var defaults = this.hasPrimaryKeys ? {} : { id: null }
if (this.__options.timestamps && isNewRecord) { if (this.__options.timestamps && isNewRecord) {
defaults[this.__options.underscored ? 'created_at' : 'createdAt'] = new Date() defaults[this.__options.underscored ? 'created_at' : 'createdAt'] = Utils.now()
defaults[this.__options.underscored ? 'updated_at' : 'updatedAt'] = new Date() defaults[this.__options.underscored ? 'updated_at' : 'updatedAt'] = Utils.now()
if (this.__options.paranoid) { if (this.__options.paranoid) {
defaults[this.__options.underscored ? 'deleted_at' : 'deletedAt'] = null defaults[this.__options.underscored ? 'deleted_at' : 'deletedAt'] = null
......
...@@ -99,7 +99,7 @@ var Utils = module.exports = { ...@@ -99,7 +99,7 @@ var Utils = module.exports = {
}, },
toDefaultValue: function(value) { toDefaultValue: function(value) {
return (value == DataTypes.NOW) ? new Date() : value return (value === DataTypes.NOW) ? Utils.now() : value
}, },
setAttributes: function(hash, identifier, instance, prefix) { setAttributes: function(hash, identifier, instance, prefix) {
...@@ -173,6 +173,12 @@ var Utils = module.exports = { ...@@ -173,6 +173,12 @@ var Utils = module.exports = {
} }
return subClass; return subClass;
},
now: function() {
var now = new Date()
now.setMilliseconds(0)
return now
} }
} }
......
...@@ -416,7 +416,7 @@ describe(Helpers.getTestDialectTeaser("DAO"), function() { ...@@ -416,7 +416,7 @@ describe(Helpers.getTestDialectTeaser("DAO"), function() {
var query = { where: { username: 'fnord' }} var query = { where: { username: 'fnord' }}
this.User.find(query).success(function(user2) { this.User.find(query).success(function(user2) {
expect(user1.equals(user2)).toEqual(true) expect(user1.equals(user2)).toBeTrue()
done() done()
}.bind(this)) }.bind(this))
}.bind(this)) }.bind(this))
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!