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

bug next occurrence with start_time = Date.today.beginning_of_year #171

Closed
d4v1d82 opened this issue May 16, 2013 · 1 comment
Closed

bug next occurrence with start_time = Date.today.beginning_of_year #171

d4v1d82 opened this issue May 16, 2013 · 1 comment
Labels

Comments

@d4v1d82
Copy link

d4v1d82 commented May 16, 2013

I've noticed a wrong behavior with just one date. If I set as start_time Date.today.beginning_of_year and I try to get the next yearly (but also monthly) occurrence of 01/29/2013 I don't have 01/01/2014 as result but 01/30/2013.

If I try with start_time = Date.today.beginning_of_year + 1.day it works.

Here below the test to replicate the issue

it 'should calculate a current date even on 01/29/2013' do
    schedule = IceCube::Schedule.new()
    schedule.add_recurrence_rule IceCube::Rule.yearly
    schedule.start_time = Date.today.beginning_of_year
    date = schedule.next_occurrence(Date.new(2013,1,28)) #correct
    date.year.should == 2014
    date.month.should == 1

    date = schedule.next_occurrence(Date.new(2013,1,30)) #correct
    date.year.should == 2014
    date.month.should == 1

    date = schedule.next_occurrence(Date.new(2013,1,29)) #bug: return 01/30/2013
    date.year.should == 2014
    date.month.should == 1

  end
@avit avit closed this as completed in decd96d May 16, 2013
@avit
Copy link
Collaborator

avit commented May 16, 2013

This was a bit of an edge case when using next_occurrence and the distance from time - start_time (29) would equal days_to_next_month (29) so the step to the next time evaluated to zero.

We actually don't need to consider days_to_next_month unless there's a chance the next month is shorter (e.g. schedule start is on the 28th or after). In all other cases we can safely advance by the number of days in the current month, which avoids the issue.

rlivsey pushed a commit to rlivsey/ice_cube that referenced this issue Jun 18, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants