File: enumeration_support_methods.rb

package info (click to toggle)
mhc 1.2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,452 kB
  • sloc: ruby: 12,700; lisp: 7,577; makefile: 70; sh: 68
file content (100 lines) | stat: -rw-r--r-- 3,263 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
99
100
module RiCal
  class PropertyValue
    class RecurrenceRule < PropertyValue
      #- ©2009 Rick DeNatale, All rights reserved. Refer to the file README.txt for the license
      #
      module EnumerationSupportMethods # :nodoc:

        # if the recurrence rule has a bysetpos part we need to search starting with the
        # first time in the frequency period containing the start time specified by DTSTART
        def adjust_start(start_time) # :nodoc:
          if by_list[:bysetpos]
            case freq
            when "SECONDLY"
              start_time
            when "MINUTELY"
              start_time.change(:seconds => 0)
            when "HOURLY"
              start_time.change(
              :minutes => 0,
              :seconds => start_time.sec
              )
            when "DAILY"
              start_time.change(
              :hour => 0,
              :minutes => start_time.min,
              :seconds => start_time.sec
              )
            when "WEEKLY"
              start_of_week(time)
            when "MONTHLY"
              start_time.change(
              :day => 1,
              :hour => start_time.hour,
              :minutes => start_time.min,
              :seconds => start_time.sec
              )
            when "YEARLY"
              start_time.change(
              :month => 1,
              :day => start_time.day,
              :hour => start_time.hour,
              :minutes => start_time.min,
              :seconds => start_time.sec
              )
            end
          else
            start_time
          end
        end

        def enumerator(component) # :nodoc:
          Enumerator.for(self, component, by_list[:bysetpos])
        end

        def exhausted?(count, time) # :nodoc:
          (@count && count > @count) || (@until && (time > @until))
        end

        def in_same_set?(time1, time2) # :nodoc:
          case freq
          when "SECONDLY"
            [time1.year, time1.month, time1.day, time1.hour, time1.min, time1.sec] ==
            [time2.year, time2.month, time2.day, time2.hour, time2.min, time2.sec]
          when "MINUTELY"
            [time1.year, time1.month, time1.day, time1.hour, time1.min] ==
            [time2.year, time2.month, time2.day, time2.hour, time2.min]
          when "HOURLY"
            [time1.year, time1.month, time1.day, time1.hour] ==
            [time2.year, time2.month, time2.day, time2.hour]
          when "DAILY"
            [time1.year, time1.month, time1.day] ==
            [time2.year, time2.month, time2.day]
          when "WEEKLY"
            sow1 = start_of_week(time1)
            sow2 = start_of_week(time2)
            [sow1.year, sow1.month, sow1.day] ==
            [sow2.year, sow2.month, sow2.day]
          when "MONTHLY"
            [time1.year, time1.month] ==
            [time2.year, time2.month]
          when "YEARLY"
            time1.year == time2.year
          end
        end

         def by_rule_list(which) # :nodoc:
          if @by_list
            @by_list[which]
          else
            nil
          end
        end

        def incrementer_from_start_time(start_time)
          RecurrenceRule::OccurrenceIncrementer.from_rrule(self, start_time)
        end
      end
    end
  end
end