2 ms·
Inverting the date range probably confused the logic involved in accounting for leap dates. Possibly it fails to account for swapping the order of the dates to
by mjevans 5y ago
Inverting the date range probably confused the logic involved in accounting for leap dates. Possibly it fails to account for swapping the order of the dates to achieve an always positive result?
- qwertox 5y agoIt's not (only?) related to leap years. It appears to be related to the month of April and some other weird stuff. -- leap year 2012: 2019-01-31 to 2012-01-30 --> 7 years 1 day 2012-01-30 to 2019-01-31 --> 7 years 1 day 2019-01-31 to 2012-02-29 --> 6 years 11 months <---- Weird stuff 2012-02-29 to 2019-01-31 --> 6 years 11 months 3 days <---- Weird stuff 2019-01-31 to 2012-02-30 --> 6 years 10 months 30 days (2012-02-30 does not exist) 2012-02-30 to 2019-01-31 --> 6 years 10 months 30 days (2012-02-30 does not exist) 2019-01-31 to 2012-03-30 --> 6 years 10 months 1 day 2012-03-30 to 2019-01-31 --> 6 years 10 months 1 day 2019-01-31 to 2012-04-30 --> 6 years 9 months <---- April (any day in April) 2012-04-30 to 2019-01-31 --> 6 years 9 months 1 day 2019-01-31 to 2012-05-01 --> 6 years 8 months 30 days 2012-05-01 to 2019-01-31 --> 6 years 8 months 30 days -- non-leap year 2013: 2019-01-31 to 2013-04-30 --> 5 years 9 months <---- April (any day in April) 2013-04-30 to 2019-01-31 --> 5 years 9 months 1 day I stumbled upon it while testing some JavaScript time and date frameworks and wanted to use Wolfram|Alpha because I was somewhat confused with the correct interval between two dates.
- mjevans 5y agoTry your test cases in other languages. E.G. python3 import datetime ; (datetime.datetime.strptime("2019-01-31","%Y-%m-%d") - datetime.datetime.strptime("2012-02-29","%Y-%m-%d")) The result, which reminds me of one of the other reasons I avoid python for trivial projects, is the duration / interval answer of days=2528. Part of the bug is surely in Wolfram|Alpha returning the interval broken out in human durations; but importantly those durations __don't use fixed time values__. The precise length of a //year// and of a //month// are variable. I still suspect there's double or single counting of leap-days in those durations as the reverse ones clash with converting a duration back to a whole number.