Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
Merge pull request #171 from nicholasruggeri/master
Browse files Browse the repository at this point in the history
A filter to add or subtract a value from a given date using the methods Add and Subtract
  • Loading branch information
urish committed Sep 3, 2015
2 parents 7a9e156 + 06e5d73 commit 39b5bf6
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/.idea
/bower_components
/node_modules
/coverage
/coverage
npm-debug.log
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ For more information about Moment.JS difference function, see the

### amDurationFormat filter

Formats a duration (such as 5 days) in a human readable format. See [Moment.JS documentation](http://momentjs.com/docs/#/durations/creating/) for a list of supported duration formats, and [`humanize() documentation`](http://momentjs.com/docs/#/durations/humanize/) for explanation about the formatting algorithm.
Formats a duration (such as 5 days) in a human readable format. See [Moment.JS documentation](http://momentjs.com/docs/#/durations/creating/) for a list of supported duration formats, and [`humanize() documentation`](http://momentjs.com/docs/#/durations/humanize/) for explanation about the formatting algorithm.

Example:

Expand All @@ -131,6 +131,32 @@ Example:

Will display the age of the message (e.g. 10 minutes, 1 hour, 2 days, etc).

### amSubtract filter

Subtract values (hours, minutes, seconds ...) from a specified date.

See [Moment.JS documentation](http://momentjs.com/docs/#/durations/creating/) for a list of supported duration formats.

Example:

```html
<span>Start time: {{day.start | amSubtract : '1' : 'hours' | amDateFormat : 'hh'}} : {{day.start | amSubtract : '30' : 'minutes' | amDateFormat : 'mm'}}</span>

```

### amAdd filter

Add values (hours, minutes, seconds ...) to a specified date.

See [Moment.JS documentation](http://momentjs.com/docs/#/durations/creating/) for a list of supported duration formats.

Example:

```html
<span>Start time: {{day.start | amAdd : '1' : 'hours' | amDateFormat : 'hh'}} : {{day.start | amAdd : '30' : 'minutes' | amDateFormat : 'mm'}}</span>

```

### Time zone support

The `amDateFormat` and `amCalendar` filters can be configured to display dates aligned
Expand Down
42 changes: 42 additions & 0 deletions angular-moment.js
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,48 @@
amTimeAgoFilter.$stateful = angularMomentConfig.statefulFilters;

return amTimeAgoFilter;
}])

/**
* @ngdoc filter
* @name angularMoment.filter:amSubtract
* @module angularMoment
* @function
*/
.filter('amSubtract', ['moment', 'angularMomentConfig', function (moment, angularMomentConfig) {
function amSubtractFilter(value, amount, type) {

if (typeof value === 'undefined' || value === null) {
return '';
}

return moment(value).subtract(parseInt(amount, 10), type);
}

amSubtractFilter.$stateful = angularMomentConfig.statefulFilters;

return amSubtractFilter;
}])

/**
* @ngdoc filter
* @name angularMoment.filter:amAdd
* @module angularMoment
* @function
*/
.filter('amAdd', ['moment', 'angularMomentConfig', function (moment, angularMomentConfig) {
function amAddFilter(value, amount, type) {

if (typeof value === 'undefined' || value === null) {
return '';
}

return moment(value).add(parseInt(amount, 10), type);
}

amAddFilter.$stateful = angularMomentConfig.statefulFilters;

return amAddFilter;
}]);
}

Expand Down
2 changes: 1 addition & 1 deletion angular-moment.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 39b5bf6

Please sign in to comment.