Skip to content

"years()" method returns inaccurate values #6

@rfire12

Description

@rfire12

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions