#3232·dayjs

relativeTime treats a zero threshold as an unlimited bound

Author: xu91102Created Sep 26, 2026Updated Sep 26, 2026

The relativeTime plugin treats a custom threshold r: 0 as an unlimited threshold rather than a bound of zero:

javascript
dayjs.extend(relativeTime, {
  thresholds: [
    { l: 's', r: 0, d: 'second' },
    { l: 'mm', d: 'minute' }
  ]
})
const start = dayjs('2020-01-01')
start.add(2, 'minute').from(start, true) // 'a few seconds', expected '2 minutes'

The !t.r fallback conflates zero with an omitted bound. Expected: only omitted bounds are unlimited; a zero difference still matches the first entry.

Reproduced against dev 436bde0bcded312781cbe45dc2b0ef079a36d8e3 on macOS/Node.js. An isolated plugin regression fails on the original code. Investigated with OpenAI Codex assistance.