Use the new updateLocale() .
Moment.js is updated again, so the preferred method is :
moment.updateLocale('en', { relativeTime : { future: 'in %s', past: '%s ago', s: 'a few seconds', m: 'a minute', mm: '%d minutes', h: 'an hour', hh: '%d hours', d: 'a day', dd: function(number) { if (number < 7) { return number + ' days'; // Moment uses "d" when it just 1 day. } else { var weeks = Math.round(number / 7); return weeks + ' ' + (weeks > 1 ? 'weeks' : 'week'); } }, M: 'a month', MM: '%d months', y: 'a year', yy: '%d years' } });
Thanks to @timrwood and @gahen for the answers.
I am working on updating Moment so that you can only redefine a single relativeTime object, such as dd , instead of providing all the objects.
The GitHub problem is here , so give it a thumbs up if you want to do something like this:
moment.updateLocale('en', { relativeTime : { dd: function(number) { if (number < 7) { return number + ' days'; // Moment uses "d" when it just 1 day. } else { var weeks = Math.round(number / 7); return weeks + ' ' + (weeks > 1 ? 'weeks' : 'week'); } } } });
Joshua pinter
source share