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

How can I show date difference like “Today, Yesterday, Tomorrow, etc..”? #218

Open
Mr-Anonymous opened this issue Feb 6, 2016 · 3 comments

Comments

@Mr-Anonymous
Copy link

In my app, I have to show a to-do list where the lists are saved in date format like “2016-02-06” (YYYY-MM-DD) in sql. When I show those data in the angular front-end, I want the days to be listed as:

Today
Tomorrow,
2 Days from now,
etc..

I tried the following:

  1. am-time-ago directive: This is not what I want since it shows in hours ago for today, etc..

  2. amDifference filter: This sorta works but still today is listed as 0 and days like 'yesterday' cannot be listed. Also I would prefer to show tomorrow instead of 1 day from now.

Is there a way to achieve this with angular-moment?

@wembernard
Copy link

👍

I found http://momentjs.com/docs/#/displaying/tonow/ but wondering how to use it with angular-moment

@michaeljota
Copy link

You can access the moment library directly and use that functions. I think.

@keemyb
Copy link

keemyb commented Apr 21, 2016

Hopefully this is of some use. I haven't used angular-moment to test it out though.

yourModule.filter('amD2', function() {
    var mappings = {
        "0 days": "Today",
        "1 day from now": "Tomorrow",
        "1 day ago": "Yesterday",
    };
    return function(amDifferenceOutput) {
        var mappedValue = mappings[amDifferenceOutput];

        return mappedValue || amDifferenceOutput;
    }
});

Usage:

<span ng-bind="myTime | amDifference | amD2"></span>

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants