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

Defining during range to work across days #124

Closed
yoonwaiyan opened this issue Nov 20, 2019 · 2 comments · Fixed by #138
Closed

Defining during range to work across days #124

yoonwaiyan opened this issue Nov 20, 2019 · 2 comments · Fixed by #138

Comments

@yoonwaiyan
Copy link

Hi, thanks again for the during implementation for the time range. However recently we've stumbled into issue where user defined a time range to run scheduled events to run during 11:00 pm-5:30 am. This call fails to run and it'll run indefinitely:

Montrose.every(1.hours).during("11:00 pm-5:30 am").starts(Time.now).events.first

One way to cater is calling two separate queries and merge both arrays of events but it's a better idea if montrose gem can solve this issue instead of patching it. Is it possible?

@rossta
Copy link
Owner

rossta commented Nov 25, 2019

Yes I believe it would be possible, but I may not get to it soon. I will gladly accept patches.

@MyklClason
Copy link

A bit old, but here is a workaround by splitting it on midnight and building a schedule. I leave the split logic for others to implement as not sure the best way to do it offhand.

options = {... , during: "11:00 pm-5:30 am", ...}

Montrose::Schedule.build do |s|
  during_split_midnight(options [during').map do |during|
    options[:during] = during
    s << Montrose.r(options)
  end
end

during_split_midnight just splits it into start to midnight and midnight to start as an array, if the range passes midnight, else it returns [during]

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

Successfully merging a pull request may close this issue.

3 participants