Skip to content
This repository has been archived by the owner on Jan 15, 2020. It is now read-only.

incorrect number of months can occure #3

Open
sergiks opened this issue Jul 19, 2016 · 2 comments
Open

incorrect number of months can occure #3

sergiks opened this issue Jul 19, 2016 · 2 comments

Comments

@sergiks
Copy link

sergiks commented Jul 19, 2016

Take two dates: 28 Feb 2015 and 28 Mar 2015.

Correct diff should be 1 month. Current datediff() implementation returns 0 months, 28 days:

{"years":0,"months":0,"days":28,"hours":0,"minutes":0,"seconds":0}

Although I find this solution quite elegant, it is not really accurate.

upd. I wrote another implementation of date difference that solves the issue.

@dmfilipenko
Copy link
Owner

@sergiks thanks for this notice. I think, that's correct difference between those two dates, it could be one month or 28 days. http://www.calculator.net/date-calculator.html?today=02%2F28%2F2015&ageat=03%2F28%2F2015&calctype=diff&x=63&y=13

@sergiks
Copy link
Author

sergiks commented Jul 22, 2016

@dmfilipenko I agree on that. Another example, Feb 15 to Mar 17:

JSON.stringify( datediff( new Date(2016,01,15,12,0,0), new Date(2016,02,17,12,0,0)))

I'd expect that to be 1 month, 2 days. But as current solution transposes the interval back to Jan 1, the result is 1 month 0 days (because there's 31 day in January).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants