iamkun / iamkun/dayjs

relativeTime outputs wrong amount of months

Open
#1,137 3 comments 3 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
48.7k
Forks
2.5k
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**
When you put in custom thresholds for relativeTime to output everything up to 9999 months as months, and enter a duration longer than 36 months, some months get lost.

**Expected behavior**
Output of correct amount of month

**Information**
- dayjs 1.9.3
- Windows
- Chrome
- CEST

I created a fiddle here https://jsfiddle.net/sy50xg2e/1/

**Details**
```
const config = {
thresholds: [
{l: 's', r: 59, d: 'second'},
{l: 'm', r: 59},
{l: 'mm', r: 59, d: 'minute'},
{l: 'h', r: 23},
{l: 'hh', r: 23, d: 'hour'},
{l: 'd', r: 29},
{l: 'dd', r: 29, d: 'day'},
{l: 'M', r: 1},
{l: 'MM', r: 9999, d: 'month'}
// {l: 'y', r: 1},
// {l: 'yy', r: 9999, d: 'year'}
]

};

dayjs.extend(dayjs_plugin_relativeTime, config)
dayjs.extend(dayjs_plugin_duration)

console.log(dayjs.duration(36, "month").humanize());
console.log(dayjs.duration(37, "month").humanize());
console.log(dayjs.duration(38, "month").humanize());
console.log(dayjs.duration(9999, "month").humanize());
```

The output is:
```
"36 months"
"36 months"
"37 months"
"9855 months"
```

I'd expect, 36, 37, 38, 9999.

Contributor guide

Open the contributing guide

Research direction

Start with the relativeTime and duration plugins and reproduce the issue using the provided JSFiddle configuration and duration examples. Verify that humanize() preserves the correct month counts for 36, 37, 38, and 9999 months; done means the outputs match the expected values without breaking the existing thresholds.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.