diff --git a/lib/plugins/useTimestamps.js b/lib/plugins/useTimestamps.js index d7bbcef..afd7676 100644 --- a/lib/plugins/useTimestamps.js +++ b/lib/plugins/useTimestamps.js @@ -1,38 +1,18 @@ var mongoose = require('mongoose') , ObjectID = mongoose.ObjectID - , BinaryParser = mongoose.mongo.BinaryParser; + //, BinaryParser = require('bson').BinaryParser; exports.useTimestamps = function (schema, options) { - if (schema.path('_id')) { - schema.add({ - updatedAt: Date - }); - schema.virtual('createdAt') - .get( function () { - if (this._createdAt) return this._createdAt; - var unixtime = BinaryParser.decodeInt(this._id.id.slice(0, 4), 32, true, true); - return this._createdAt = new Date(unixtime * 1000); - }); - schema.pre('save', function (next) { - if (this.isNew) { - this.updatedAt = this.createdAt; - } else { - this.updatedAt = new Date; - } - next(); - }); - } else { - schema.add({ - createdAt: Date - , updatedAt: Date - }); - schema.pre('save', function (next) { - if (!this.createdAt) { - this.createdAt = this.updatedAt = new Date; - } else { - this.updatedAt = new Date; - } - next(); - }); - } + schema.add({ + createdAt: Date + , updatedAt: Date + }); + schema.pre('save', function (next) { + if (!this.createdAt) { + this.createdAt = this.updatedAt = new Date; + } else { + this.updatedAt = new Date; + } + next(); + }); }; diff --git a/package.json b/package.json index 4e47092..4857a5e 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "mongoose-types" , "description": "More types for mongoose" -, "version": "1.0.3" +, "version": "1.0.3-2" , "author": "Brian Noguchi" -, "dependencies": { "mongoose": ">= 1.0.16"} +, "dependencies": { "mongoose": ">= 1.0.16" } , "keywords": [ "mongoose", "mongo", "mongodb", "types" ] , "scripts": { "test": "make test" } , "engines": { "node": ">= 0.1.101" }