Module: Icalendar::Timezone::TzProperties

Included in:
Daylight, Standard
Defined in:
lib/icalendar/timezone.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/icalendar/timezone.rb', line 9

def self.included(base)
  base.class_eval do
    required_property :dtstart, Icalendar::Values::DateTime
    required_property :tzoffsetfrom, Icalendar::Values::UtcOffset
    required_property :tzoffsetto, Icalendar::Values::UtcOffset

    optional_property :rrule, Icalendar::Values::Recur, true
    optional_property :comment
    optional_property :rdate, Icalendar::Values::DateTime
    optional_property :tzname

    transient_variable :@cached_occurrences
    transient_variable :@occurrences
  end
end

Instance Method Details

#occurrencesObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/icalendar/timezone.rb', line 25

def occurrences
  @occurrences ||= IceCube::Schedule.new(dtstart.to_time) do |s|
    rrule.each do |rule|
      s.add_recurrence_rule IceCube::Rule.from_ical(rule.value_ical)
    end
    rdate.each do |date|
      s.add_recurrence_time date.to_time
    end
  end.all_occurrences_enumerator
end

#previous_occurrence(from) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/icalendar/timezone.rb', line 36

def previous_occurrence(from)
  from = IceCube::TimeUtil.match_zone(from, dtstart.to_time)

  @cached_occurrences ||= []
  while @cached_occurrences.empty? || @cached_occurrences.last <= from
    begin
      @cached_occurrences << occurrences.next
    rescue StopIteration
      break
    end
  end

  @cached_occurrences.reverse_each.find { |occurrence| occurrence < from }
end