urish/angular-moment

Combining 'am-time-ago' and amCalendar to use in one Tag

Closed this issue · 5 comments

I think, it'd be great to use 'am-time-ago' and amCalendar in one tag.
It should display x seconds/minutes ago but when it reaches 2 hours ago, it should activate amCalendar filter.

urish commented

Hi, have you checked out the fullDateThreshold attribute?

See #75 for an example

Yeah I saw that, but that doesn't return calendar filtered date.

urish commented

What about the proposed change in #198 ?

ok, great! #198 really helped and now, I can use both 'am-time-ago' and 'amCalendar' in single tag (indirectly).
Although, I didn't use the callback method described in #198 because, in that case, I had to write the complete logic - but that's already written in angular-moment.js. and I prefer to reuse the code by extending it with new tags.

let me write it here in case anyone else wants to do the similar thing.

// angular-moment.js
function updateTime(momentInstance) {
    ...
    ...
    if (showFullDate) {
        element.text(momentInstance.format(fullDateFormat));
    } else {
        var now = getNow();
        if(attr.amTimeAgoToCalendar && now.diff(momentInstance, 'hour') > parseInt(attr.amTimeAgoToCalendar)) {
            element.text(momentInstance.calendar());
        }
        else {
            element.text(momentInstance.from(getNow(), withoutSuffix));
        }
    }
    ...
    ...
}

// in template file
<span am-time-ago="obj.time" am-time-ago-to-calendar="2"></span>
urish commented

Great to read that it helped!

The feedback about #198 not being helpful here is important. Everybody has a different requirements, and I am looking for an approach that will be useful for most users, without having to maintain too many different possible code-flows. Do you have any suggestion of how #198 could be extended to support your use-case as well? Perhaps adding some extra parameters for the callback?

I'd appreciate if you could leave a comment there (#198) with you thoughts...

Thanks!