Module: Protocol::Caldav::Ical::Rrule
- Defined in:
- lib/protocol/caldav/ical/rrule.rb
Constant Summary collapse
- DAYS =
{ 'MO' => 1, 'TU' => 2, 'WE' => 3, 'TH' => 4, 'FR' => 5, 'SA' => 6, 'SU' => 0 }.freeze
Class Method Summary collapse
-
.expand(dtstart:, rrule_value:, range_start:, range_end:, exdates: [], max_count: 10000) ⇒ Array<Time>
Expand an RRULE into concrete occurrence start times within a range.
Class Method Details
.expand(dtstart:, rrule_value:, range_start:, range_end:, exdates: [], max_count: 10000) ⇒ Array<Time>
Expand an RRULE into concrete occurrence start times within a range.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/protocol/caldav/ical/rrule.rb', line 22 def (dtstart:, rrule_value:, range_start:, range_end:, exdates: [], max_count: 10000) parts = parse_rrule(rrule_value) freq = parts['FREQ'] if freq interval = (parts['INTERVAL'] || '1').to_i count = parts['COUNT']&.to_i if parts['UNTIL'] until_time = parse_dt(parts['UNTIL']) else until_time = nil end byday = parts['BYDAY']&.split(',') bymonthday = parts['BYMONTHDAY']&.split(',')&.map(&:to_i) bymonth = parts['BYMONTH']&.split(',')&.map(&:to_i) occurrences = [] current = dtstart generated = 0 loop do # Stop conditions if until_time && current > until_time break end if current > range_end break end if count && generated >= count break end if occurrences.length >= max_count break end candidates = ( freq, current, interval, byday, bymonthday, bymonth, dtstart, ) candidates.each do |candidate| if until_time && candidate > until_time break end if count && generated >= count break end if occurrences.length >= max_count break end generated += 1 if candidate < range_start && candidate < dtstart next end if candidate >= range_end next end if exdates.any? { |ex| times_equal?(candidate, ex) } next end if candidate >= range_start occurrences << candidate end end current = advance(freq, current, interval) end occurrences.sort else [dtstart] end end |