#5267·moment

moment("2019-08-30 23:59:59").from(moment("2019-10-25 12:00:00")) is '54.50001157407407 days ago' (should be 55.500... days ago)

Author: badpCreated Oct 24, 2019Updated Sep 2, 2026
Labelsrelative time threshold issues

Describe the bug Bug, or at least surprising behaviour, when humanizing time deltas in the past with high relativeTimeThresholds

To Reproduce Running moment 2.24:

moment.relativeTimeThreshold("h", 73);
moment.relativeTimeThreshold("d", 91);
moment.relativeTimeThreshold("M", 25);
moment.relativeTimeRounding(x => x); // I use moment.relativeTimeRounding(x => x.toFixed(1)); in my application
moment.unix(Date.now() / 1000 - 86400*54).fromNow(true) // 54 days
moment.unix(Date.now() / 1000 - 86400*55).fromNow(true) // 54.00000001157407 days
moment.unix(Date.now() / 1000 - 86400*56).fromNow(true) // 55 days

moment().subtract(54, 'days').fromNow(true) // 54 days
moment().subtract(55, 'days').fromNow(true) // 54 days
moment().subtract(56, 'days').fromNow(true) // 55 days

Expected behavior I perhaps incorrectly expect moment.unix(Date.now() / 1000 - 86400*55).fromNow(true) to return "55 days" (should I use a different moment constructor?)

I definitely expect moment().subtract(55, 'days').fromNow(true) to return "55 days"

Desktop (please complete the following information):

  • OS: Ubuntu, OSX
  • Browser: Chrome
  • Version: 79.0.3938.0 (Official Build) dev (64-bit)

Moment-specific environment

  • The time zone setting of the machine the code is running on: CEST, Europe/Amsterdam
  • The time and date at which the code was run: "2019-10-24T17:24:19+02:00"
  • Other libraries in use (TypeScript, Immutable.js, etc): can be reproduced on the browser console for momentjs.com

Please run the following code in your environment and include the output:

console.log((new Date()).toString())
console.log((new Date()).toLocaleString())
console.log((new Date()).getTimezoneOffset())
console.log(navigator.userAgent)
console.log(moment.version)

Thu Oct 24 2019 17:25:41 GMT+0200 (Central European Summer Time)
10/24/2019, 5:25:41 PM
-120
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3938.0 Safari/537.36
2.24.0