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

Distance between end of year and beginning of year should return 12 months #58

Open
satheshhmax opened this issue May 8, 2015 · 2 comments

Comments

@satheshhmax
Copy link

When i'm trying to calculate months between given date its not showing proper result for an exact year calculation.

irb(main):013:0> start_time = Time.now.beginning_of_year
=> 2015-01-01 00:00:00 +0530
irb(main):014:0> end_time = Time.now.end_of_year
=> 2015-12-31 23:59:59 +0530

For the above given value i expect result as 12 months OR 12 months, 30 days, 23 hours and so on.

irb(main):015:0> DOTIW::TimeHash.new(nil, Time.now.beginning_of_year, Time.now.end_of_year, {}).to_hash
=> {:years=>0, :months=>11, :days=>30}

If i reduce 1 day from end time, it shows proper answer.

irb(main):016:0> DOTIW::TimeHash.new(nil, Time.now.beginning_of_year, Time.now.end_of_year-1.day, {}).to_hash
=> {:years=>0, :months=>11, :days=>29, :hours=>23, :minutes=>59, :seconds=>59}
@radar
Copy link
Owner

radar commented May 8, 2015

I don't know how to fix this without breaking existing behaviour. If you could investigate this and find a patch for it I would happily review it.

Thanks

On 8 May 2015, at 13:31, Sathesh Kumar [email protected] wrote:

When i'm trying to calculate months between given date its not showing proper result for an exact year calculation.

irb(main):013:0> start_time = Time.now.beginning_of_year
=> 2015-01-01 00:00:00 +0530
irb(main):014:0> end_time = Time.now.end_of_year
=> 2015-12-31 23:59:59 +0530
For the above given value i expect result as 12 months OR 12 months, 30 days, 23 hours and so on.

irb(main):015:0> DOTIW::TimeHash.new(nil, Time.now.beginning_of_year, Time.now.end_of_year, {}).to_hash
=> {:years=>0, :months=>11, :days=>30}
If i reduce 1 day from end time, it shows proper answer.

irb(main):016:0> DOTIW::TimeHash.new(nil, Time.now.beginning_of_year, Time.now.end_of_year-1.day, {}).to_hash
=> {:years=>0, :months=>11, :days=>29, :hours=>23, :minutes=>59, :seconds=>59}

Reply to this email directly or view it on GitHub.

dblock added a commit to dblock/distance_of_time_in_words that referenced this issue Jul 2, 2020
@dblock
Copy link
Collaborator

dblock commented Jul 2, 2020

This is still a non-feature, it would be nice if end of year minus beginning of year was smart enough to say "12 months", but seems non-trivial. Spec in dblock@74bc2cc.

@dblock dblock changed the title Issue with calculation Distance between end of year and beginning of year should return 12 months Jul 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants