melvinsembrano / date-diff

Minimalized Javascript Dates arithmetic extension
MIT License
32 stars 7 forks source link

"years()" method returns inaccurate values #6

Open rfire12 opened 3 years ago

rfire12 commented 3 years ago

Current Behaviour

When day and month are too close between each other, e.g.: 2021-01-17 and 2015-02-04, years throws 6 as the year difference instead of 5.9~ish

Expected Behaviour

Using years with these dates: 2021-01-17 and 2015-02-04 should return 5.9~ish instead of 6.

Steps to Reproduce

import DateDiff from 'date-diff';

const diff = new DateDiff( new Date(2021, 01, 17), new Date( 2015, 02, 04 ) );
console.log(diff.years()); // output: 6

Environment 🌎

Windows 10 - WSL 2 node v10.20.1

A workaround is to use months instead of years, and then calculate the years difference from that.