Moment.js changes the range fromNow

Can I change the time range in moment.js for fromNow, so the range of hours is from 60 seconds to 59 minutes and, like wise for others (90 sec. - 45 minutes).

ref: Moment.Js

is something similar to how you can change lang:

moment.lang('en', { relativeTime : { future: "Due in %s", past: "%s ago", s: "seconds", m: "a minute", mm: "%d minutes", h: "an hour", hh: "%d hours", d: "a day", dd: "%d days", M: "a month", MM: "%d months", y: "a year", yy: "%d years" } }); 
+4
source share
1 answer

duration.humanize has thresholds that determine when a unit is considered a minute, an hour, and so on. For example, by default, more than 45 seconds is considered a minute, more than 22 hours is considered a day, and so on.

To change these moment.relativeTimeThreshold(unit, limit) , use moment.relativeTimeThreshold(unit, limit) , where the limit is one of s , m , h , d , m .

  • s seconds is the least number of seconds considered to be a minute
  • m minutes is the least number of minutes considered to be hours
  • h hours is the least number of hours considered to be a day
  • d days the smallest number of days to be considered a month
  • m months is the smallest number of months considered a year

  // Retrieve existing thresholds moment.relativeTimeThreshold('s'); // 45 moment.relativeTimeThreshold('m'); // 45 moment.relativeTimeThreshold('h'); // 22 moment.relativeTimeThreshold('d'); // 26 moment.relativeTimeThreshold('M'); // 11 // Set new thresholds moment.relativeTimeThreshold('s', 40); moment.relativeTimeThreshold('m', 40); moment.relativeTimeThreshold('h', 20); moment.relativeTimeThreshold('d', 25); moment.relativeTimeThreshold('M', 10); 

NOTE The resulting thresholds were added in 2.8.1 .

+1
source

Source: https://habr.com/ru/post/1489750/


All Articles