Strict thresholds doc example outputs anything over 1 year as '1 year'
- Dominant language
- JavaScript
- Stars
- 48.7k
- Forks
- 2.5k
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
Using the strict thresholds from the API docs with the `form()` method to calculate age sets everything above one year to exactly one year.
This is the example in the docs:
```// strict thresholds
var thresholds = [
{ l: 's', r: 1 },
{ l: 'm', r: 1 },
{ l: 'mm', r: 59, d: 'minute' },
{ l: 'h', r: 1 },
{ l: 'hh', r: 23, d: 'hour' },
{ l: 'd', r: 1 },
{ l: 'dd', r: 29, d: 'day' },
{ l: 'M', r: 1 },
{ l: 'MM', r: 11, d: 'month' },
{ l: 'y' },
{ l: 'yy', d: 'year' }
]
```
This is what gets output:
```
const date = '2012-05-12';
console.log(dayjs().from(dayjs(date), true))
// Output: 'One year'
```
**Expected behavior**
I would expect to get '9 years'.
**Information**
- Day.js Version 1.10.4
- OS: macOS Big Sur
- Browser Chrome 89.0.4389.90 (Official Build) (x86_64), verified in Firefox and Safari too
- Time zone: [e.g. GMT+02:00]
Adding `r: 1` so you get ` { l: 'y' : 1}` for the year threshold seems to fix it _in my case_ , but I am not sure if this is by coincidence or if there's another way of doing this properly.
Is this a mistake that should go in there, or is there anything else going on?
Contributor guide
Research direction
Start by reproducing the API documentation's strict-threshold example with form() and the supplied date, then compare the result with the expected nine-year output. Check whether the documented threshold configuration or the form() behavior is responsible; done means the example produces the correct result or the documentation accurately explains the required configuration.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- backend-api-design, documentation
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100