Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix Date.timeDiff spec or when the difference was a negative number

  • Loading branch information...
commit 6b0274ef0073a2316340c414cd52771e40cc58ba 1 parent d9ad479
@arian arian authored anutron committed
Showing with 15 additions and 6 deletions.
  1. +1 −1  Source/Types/Date.Extras.js
  2. +14 −5 Specs/1.3/Types/Date.Extras.js
View
2  Source/Types/Date.Extras.js
@@ -29,7 +29,7 @@ Date.implement({
timeDiff: function(to, separator){
if (to == null) to = new Date;
- var delta = ((to - this) / 1000).floor();
+ var delta = ((to - this) / 1000).floor().abs();
var vals = [],
durations = [60, 60, 24, 365, 0],
View
19 Specs/1.3/Types/Date.Extras.js
@@ -40,12 +40,21 @@ describe('Date.getTimePhrase', function(){
describe('Date.timeDiff', function(){
it('should return a readable time difference format', function(){
- var date = new Date();
+ var date = new Date('06/20/2011'),
+ orig = date.clone();
+
+ expect(date.timeDiff(orig)).toEqual('0s');
+ expect(date.decrement('second', 10).timeDiff(orig)).toEqual('10s');
+ expect(date.decrement('month', 1).timeDiff(orig)).toEqual('31d:0h:0m:10s');
+ expect(date.decrement('year', 2).timeDiff(orig)).toEqual('2y:31d:0h:0m:10s');
+ expect(date.timeDiff()).not.toBeNull();
+ });
+
+ it('should return a positive difference', function(){
+ var date = new Date('06/20/2011'),
+ orig = date.clone();
- expect(date.timeDiff()).toEqual('0s');
- expect(date.decrement('second', 10).timeDiff()).toEqual('10s');
- expect(date.decrement('month', 1).timeDiff()).toEqual('31d:0h:0m:10s');
- expect(date.decrement('year', 2).timeDiff()).toEqual('2y:31d:0h:0m:10s');
+ expect(date.increment('month', 1).timeDiff(orig)).toEqual('30d:0h:0m:0s');
});
});
Please sign in to comment.
Something went wrong with that request. Please try again.