Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#in_months doesn't seem to respect months having different days #39

Open
pedantic-git opened this issue Dec 4, 2017 · 4 comments
Open

Comments

@pedantic-git
Copy link

pedantic-git commented Dec 4, 2017

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?

@pedantic-git
Copy link
Author

I've done a basic PR for this in #40 - let me know what you think!

@martinstreicher
Copy link

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.

@martinstreicher
Copy link

Hmm... DST?

@joecabezas
Copy link

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?

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

No branches or pull requests

3 participants