Momentjs: change the default humanize () behavior

The moment.js documentation provides the following example:

moment.duration(1, "minutes").humanize(); // a minute
moment.duration(2, "minutes").humanize(); // 2 minutes
moment.duration(24, "hours").humanize();  // a day

      

I need to have for this call

moment.duration(1, "minutes").humanize();

      

the output is "1 minute" and I want to have for this line

moment.duration(24, "hours").humanize();

      

exit "24 hours".

I can't just replace the word "a" with 1, because it will be used for different languages.

Is it possible? Maybe some simple config / workaround / undocumented feature?

+3


source to share


2 answers


From moment.js documentation you can set it up like this:

moment.locale('en', {
    relativeTime : {
        future: "in %s",
        past:   "%s ago",
        s:  "seconds",
        m:  "a minute",  //change that to "%d minute"
        mm: "%d minutes",
        h:  "an hour",   //here too
        hh: "%d hours",
        d:  "a day",     //and here
        dd: "%d days",
        M:  "a month",   //and so on...
        MM: "%d months",
        y:  "a year",
        yy: "%d years"
    }
});

      



I know this solution is not perfect but cannot find a better one.

+4


source


To get a "24 hours" output moment.duration(24, "hours").humanize();

with a moment you can use a relative time threshold like moment.relativeTimeThreshold ('h', 25)



0


source







All Articles