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

amCalendar. Advanced arguments referenceTime, formats added #241

Merged
merged 1 commit into from
Apr 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,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