Skip to content

Commit

Permalink
use moments
Browse files Browse the repository at this point in the history
  • Loading branch information
fredkingham committed Jan 19, 2017
1 parent ce382c0 commit 0629f26
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 23 deletions.
39 changes: 24 additions & 15 deletions opal/static/js/opal/filters.js
Expand Up @@ -153,25 +153,34 @@ filters.filter('daysSince', function(daysToFilter){


filters.filter('future', function(){
return function(input, includeToday){
var today = new Date();

if(includeToday){
return input >= today;
}
return input > today;
return function(i, includeToday){
if(!i){
return false;
}
var today = new moment();
var input = moment(i);

if(includeToday && input.isSame(today, "day")){
return true;
}
return input.isAfter(today, "day");
};
});

filters.filter('past', function(){
return function(input, includeToday){
var today = new Date();
filters.filter('past', function(toMomentFilter){
return function(i, includeToday){
if(!i){
return false;
}

var today = new moment();
var input = toMomentFilter(i);

if(includeToday){
return input <= today;
}
return input < today;
};
if(includeToday && input.isSame(today, "day")){
return true;
}
return input.isBefore(today, "day");
};
});

filters.filter('age', function(toMomentFilter){
Expand Down
24 changes: 16 additions & 8 deletions opal/static/js/opaltest/filtersTest.js
Expand Up @@ -263,11 +263,15 @@ describe('filters', function() {
futureFilter = $injector.get('futureFilter');

});
today = new Date();
today = moment();
});

it('should return false if undefined', function(){
expect(futureFilter(undefined)).toBe(false);
})

it('should return true if in the future', function(){
var tomorrow = today.setDate(today.getDate()+10);
var tomorrow = today.add(1, "days");
expect(futureFilter(tomorrow)).toBe(true);
});

Expand All @@ -280,7 +284,7 @@ describe('filters', function() {
});

it('should return fals if in the past', function(){
var yesterday = today.setDate(today.getDate()-10);
var yesterday = today.subtract(1, "days");
expect(futureFilter(yesterday)).toBe(false);
});
});
Expand All @@ -293,16 +297,20 @@ describe('filters', function() {
pastFilter = $injector.get('pastFilter');

});
today = new Date();
today = moment();
});

it('should return false if undefined', function(){
expect(pastFilter(undefined)).toBe(false);
})

it('should return true if in the future and passed a moment', function(){
var tomorrow = moment(today.setDate(today.getDate()+10));
var tomorrow = today.add(1, "days");
expect(pastFilter(tomorrow)).toBe(false);
});

it('should return false if in the future', function(){
var tomorrow = today.setDate(today.getDate()+10);
var tomorrow = today.add(1, "days");
expect(pastFilter(tomorrow)).toBe(false);
});

Expand All @@ -315,12 +323,12 @@ describe('filters', function() {
});

it('should return true if in the past', function(){
var yesterday = today.setDate(today.getDate()-10);
var yesterday = today.subtract(1, "days");
expect(pastFilter(yesterday)).toBe(true);
});

it('should return true if in the past and passed a moment', function(){
var yesterday = moment(today.setDate(today.getDate()-10));
var yesterday = today.subtract(1, "days");
expect(pastFilter(yesterday)).toBe(true);
});
});
Expand Down

0 comments on commit 0629f26

Please sign in to comment.