Can compare dates

pull/2/head
Louis Chatriot 12 years ago
parent fdc01721e0
commit 07ff9e2183
  1. 4
      lib/model.js
  2. 18
      test/model.test.js

@ -164,6 +164,10 @@ function compareThings (a, b) {
// Booleans
if (typeof a === 'boolean') { return typeof b === 'boolean' ? compareNSB(a, b) : -1; }
if (typeof b === 'boolean') { return typeof a === 'boolean' ? compareNSB(a, b) : 1; }
// Dates
if (util.isDate(a)) { return util.isDate(b) ? compareNSB(a.getTime(), b.getTime()) : -1; }
if (util.isDate(b)) { return util.isDate(a) ? compareNSB(a.getTime(), b.getTime()) : 1; }
}

@ -396,6 +396,24 @@ describe('Model', function () {
});
});
it('Then dates', function () {
var otherStuff = [{}, { hello: 'world' }, [], ['quite', 5]]
, dates = [new Date(-123), new Date(), new Date(5555), new Date(0)]
, now = new Date();
model.compareThings(now, now).should.equal(0);
model.compareThings(new Date(54341), now).should.equal(-1);
model.compareThings(now, new Date(54341)).should.equal(1);
model.compareThings(new Date(0), new Date(-54341)).should.equal(1);
model.compareThings(new Date(123), new Date(4341)).should.equal(-1);
otherStuff.forEach(function (stuff) {
dates.forEach(function (date) {
model.compareThings(date, stuff).should.equal(-1);
model.compareThings(stuff, date).should.equal(1);
});
});
});
}); // ==== End of 'Comparing things' ==== //

Loading…
Cancel
Save