time_difference
time_difference copied to clipboard
#in_months doesn't seem to respect months having different days
I'm trying to use TimeDifference to find the difference in months between two dates. I'd expect the difference between 2017-09-04 and 2017-12-04 to be exactly 3.0.
But this happens:
TimeDifference.between(Time.new(2017, 9, 4), Time.new(2017, 12, 4)).in_months
#=> 2.99
TimeDifference.between(Time.new(2017, 8, 4), Time.new(2017, 11, 4)).in_months
#=> 3.02
Would it make sense to add an #in_calendar_months
or similar that takes into account the different lengths of different months?
I've done a basic PR for this in #40 - let me know what you think!
I am using this gem and it is having an issue around the leap day in 2020.
2.6.5 :007 > x = Chronic.parse('March 8').to_date
=> Sun, 08 Mar 2020
2.6.5 :008 > y = Chronic.parse('March 10').to_date
=> Tue, 10 Mar 2020
2.6.5 :009 > TimeDifference.between(x, y).in_days
=> 1.96
I am not sure why it is less than 2.
Hmm... DST?
this is needed
TimeDifference.between(Time.now, 1.month.ago).in_months
0.99
I expected to be 1, but is based on 30days per month, any update on this?