-
Notifications
You must be signed in to change notification settings - Fork 358
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
Fix first weekly occurrences with non-Sunday week start #383
Fix first weekly occurrences with non-Sunday week start #383
Conversation
3b2f2cf
to
e4f2d29
Compare
f251c57
to
c922ce1
Compare
Sorry for the delay - will have this back to you tonight! |
Instead of requiring a Schedule instance, rules only need a start time to align themselves to. This will allow the validate methods to be used in different contexts.
This option only applies to weekly rules and should not be listed everywhere to avoid confusion.
Simplify the Schedule and only handle realigning the start wday for weekly rules where it's needed.
c922ce1
to
7fe1719
Compare
Realignment for start time doesn't apply to any rule types other than WeeklyRule. It also must be kept separate from the schedule's own start time because it's possible for it to move backwards to the start of the week.
7fe1719
to
9eba907
Compare
Thanks, I'd just like a second pair of eyes on this since it's pretty big. (I hope it should make sense to review per-commit.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 and test coverage looks good too
left a few general comments but nothing that should block this.
thank you!
@@ -25,8 +25,8 @@ def dst_adjust? | |||
false | |||
end | |||
|
|||
def validate(step_time, schedule) | |||
t0, t1 = schedule.start_time.to_i, step_time.to_i | |||
def validate(step_time, start_time) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -4,7 +4,7 @@ class HourlyRule < ValidatedRule | |||
|
|||
include Validations::HourlyInterval | |||
|
|||
def initialize(interval = 1, week_start = :sunday) | |||
def initialize(interval = 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
always thought these were a little clunky so I'm happy to see them go
|
||
days = (step_time - start_time).to_i / ONE_DAY | ||
interval = base_interval_validation.validate(step_time, start_time).to_i | ||
min_wday = TimeUtil.normalize_wday(wday_validations.min_by(&:day).day, week_start) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe here this is the equivalent of map(&:day).min
which may read nicer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did it this way because min_by
takes one pass over the array and map.min
takes two.
(However, this method is only called once per query, and it's a tiny array of 7 so it's not going to be significant either way.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely - sounds good!
This change corrects the wday offset to account for the week start option in weekly rules.
Some refactoring was done to avoid adding conditionals and more complexity into the Schedule class which was coordinating this:
week_start
except for the Weekly rule that uses it. This is to avoid confusion about where this option is actually used.Much thanks to #360 and #284 for spotting the core issue here.