ice-cube-ruby / ice_cube

Ruby Date Recurrence Library - Allows easy creation of recurrence rules and fast querying
MIT License
2.41k stars 358 forks source link

count issue with hourly and daily rules #413

Closed uzaif313 closed 7 years ago

uzaif313 commented 7 years ago

i follow below process

  schedule=IceCube::Schedule.new(Date.today,end_time:Date.today+13.days)
  schedule.add_recurrence_rule IceCube::Rule.daily.day(1,3,5)
  schedule.add_recurrence_rule IceCube::Rule.hourly(3).count(4)
  schedule.occurrences(end_time)
  # its show this 

[2017-08-17 00:00:00 +0530,
 2017-08-17 03:00:00 +0530,
 2017-08-17 06:00:00 +0530,
 2017-08-17 09:00:00 +0530,
 2017-08-18 00:00:00 +0530,
 2017-08-21 00:00:00 +0530,
 2017-08-23 00:00:00 +0530,
 2017-08-25 00:00:00 +0530,
 2017-08-28 00:00:00 +0530,
 2017-08-30 00:00:00 +0530]

as above output display correct form of count for 17 but its not display hourly based count for other days

avit commented 7 years ago

This looks correct to me.

its not display hourly based count for other days

You have set hourly(3) = every 3 hours, and count(4) = 4 times only. The 4 hourly occurrences are based on the start time, and then they stop:

[2017-08-17 00:00:00 +0530,
 2017-08-17 03:00:00 +0530,
 2017-08-17 06:00:00 +0530,
 2017-08-17 09:00:00 +0530,

After this, the hourly rule is done because of the count limit, so it does the daily.day(1,3,5) occurrences only.

uzaif313 commented 7 years ago

@avit Thanks for response can you tell me how can I repeat count for every occurrence

avit commented 7 years ago

Also, end_time:Date.today+13.days will set the duration (length) of each occurrence, not when the schedule stops repeating. You might want to use until if you want the schedule to stop instead.

how can I repeat count for every occurrence

I don't understand. Can you tell me more exactly what you mean? Maybe give an example of the result you want?

uzaif313 commented 7 years ago

Thanks @avit for response

i need something like below occurrence which will repeat daily with hourly rules


 2017-08-17 03:00:00 +0530,
 2017-08-17 06:00:00 +0530,
 2017-08-17 09:00:00 +0530,
 2017-08-18 03:00:00 +0530,
 2017-08-18 06:00:00 +0530,
 2017-08-18 09:00:00 +0530,
 2017-08-19 03:00:00 +0530,
 2017-08-19 06:00:00 +0530,
 2017-08-19 09:00:00 +0530,
 2017-08-20 03:00:00 +0530,
 2017-08-20 06:00:00 +0530,
 2017-08-20 09:00:00 +0530,
]
avit commented 7 years ago

You can do it with 3 daily rules:

schedule.add_recurrence_rule IceCube::Rule.daily.hour_of_day(3)
schedule.add_recurrence_rule IceCube::Rule.daily.hour_of_day(6)
schedule.add_recurrence_rule IceCube::Rule.daily.hour_of_day(9)

Or 1 hourly rule:

schedule.add_recurrence_rule IceCube::Rule.hourly.hour_of_day(3, 6, 9)

The first way is more efficient, but both of these will work.

uzaif313 commented 7 years ago

Thanks for response @avit :+1: its really help me. thanks a lot again. can we make above code based on frequency? eg. Daily Tuesday and Friday every 3 hours repeat frequency is 3

avit commented 7 years ago

Yes of course, just add .day(:tuesday, :friday) to the above.

uzaif313 commented 7 years ago

:+1:

 schedule = IceCube::Schedule.new(Time.now,end_time:Time.now+12.days+4.hours)
 schedule.add_recurrence_rule IceCube::Rule.daily.day(1,3,5).hour_of_day(3,6,9)
schedule.occurrences(Time.now+13.days)

this can also give occurrence within 3 hours on daily rule

uzaif313 commented 7 years ago

hi @avit can we repeat time hourly schedule between start_time and end_time with some frequency eg. we need like this Weekly mondays, tuesday every 2 hours with frequency of 3 so it will give repeat schedule on 3 time in days between start_time and end_time

uzaif313 commented 7 years ago

how can i combine multiple rules with add_recurrences_rule method