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 #241 from Nitro-N/am_calendar_advanced_arguments
Browse files Browse the repository at this point in the history
amCalendar. Advanced arguments referenceTime, formats added
  • Loading branch information
urish committed Apr 14, 2016
2 parents c63f359 + 708dc9b commit e91c0bf
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ For more information about Moment.JS formatting options, see the
Format dates using moment.js calendar() method. Example:

```html
<span>{{message.time | amCalendar}}</span>
<span>{{message.time | amCalendar:referenceTime:formats}}</span>
```

This snippet will format the given time as e.g. "Today 2:30 AM" or "Last Monday 2:30 AM" etc..
Expand Down
4 changes: 2 additions & 2 deletions angular-moment.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,13 +519,13 @@
* @module angularMoment
*/
.filter('amCalendar', ['moment', 'amMoment', 'angularMomentConfig', function (moment, amMoment, angularMomentConfig) {
function amCalendarFilter(value) {
function amCalendarFilter(value, referenceTime, formats) {
if (isUndefinedOrNull(value)) {
return '';
}

var date = amMoment.preprocessDate(value);
return date.isValid() ? date.calendar() : '';
return date.isValid() ? date.calendar(referenceTime, formats) : '';
}

// Since AngularJS 1.3, filters have to explicitly define being stateful
Expand Down
4 changes: 4 additions & 0 deletions tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,10 @@ describe('module angularMoment', function () {
it('should return an empty string for invalid input', function () {
expect(amCalendar('blah blah')).toBe('');
});

it('should take advanced arguments referenceTime and formats', function () {
expect(amCalendar(new Date(2012, 0, 22, 4, 46, 54), new Date(2012, 0, 23, 4, 46, 54), {lastDay: '[Yesterday at] H:m'})).toBe('Yesterday at 4:46');
});
});

describe('amDifference filter', function () {
Expand Down

0 comments on commit e91c0bf

Please sign in to comment.