iamkun / iamkun/dayjs

Calculation of diff in years is wrong for leap-years (since v1.8.32)

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

Description

We use `diff()` to calculate the current age of people according to their date of birth. For someone who is born on February 29th at a leap-year, this calculation seems to be broken since version 1.8.32

Taken a person born on 2016-02-29, with version 1.8.31 on February 28th 2017 this person is still 0 years old. On March 1st, this person turns 1.
With version 1.8.32, this person is already 1 year old on February 28th 2017, which is - at least here in Germany - not correct.

If the calculation is carried out in a leap year (e.g. 2020), it is correct in both versions.

Fiddle for version 1.8.31: https://jsfiddle.net/enqbx39r/1
Fiddle for version 1.8.32: https://jsfiddle.net/49yfb7wt/1

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the reported diff() results with a person born on 2016-02-29, comparing February 28 and March 1 in versions 1.8.31 and 1.8.32. Use the linked JSFiddles as reference and inspect the diff() implementation and its tests. Done means February 28, 2017 returns 0 years and March 1 returns 1, while leap-year behavior remains correct.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend
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.