File: recurring_month_day.rb

package info (click to toggle)
mhc 1.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,320 kB
  • ctags: 3,529
  • sloc: ruby: 12,404; lisp: 7,448; makefile: 70; sh: 69
file content (64 lines) | stat: -rw-r--r-- 1,887 bytes parent folder | download | duplicates (4)
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
module RiCal
  class PropertyValue
    class RecurrenceRule < PropertyValue
      #- ©2009 Rick DeNatale, All rights reserved. Refer to the file README.txt for the license
      #
      # Instances of RecurringMonthDay represent BYMONTHDAY parts in recurrence rules
      class RecurringMonthDay < NumberedSpan # :nodoc:

        def last
          31
        end
        
        # return a list id for a given time to allow the enumerator to cache lists
        def list_id(time)
          time.month
        end
 
        # return a list of times which match the time parameter within the scope of the RecurringDay
        def matches_for(time)
          [time.change(:day => 1).advance(:days => target_for(time)- 1)]
        end
        
        # return a list id for a given time to allow the enumerator to cache lists
        def list_id(time)
          time.month
        end
 
        # return a list of times which match the time parameter within the scope of the RecurringDay
        def matches_for(time)
          [time.change(:day => 1).advance(:days => target_for(time)- 1)]
        end
        
        def target_date_time_for(date_time)
          matches_for(date_time)[0]
        end

        # return a list of times which match the time parameter within the scope of the RecurringDay
        def matches_for(time)
          [time.change(:day => 1).advance(:days => target_for(time)- 1)]
        end

        def target_date_time_for(date_time)
          matches_for(date_time)[0]
        end
        
        def fixed_day?
          @source > 0
        end

        def target_for(date_or_time)
          if fixed_day?
            @source
          else
            date_or_time.days_in_month + @source + 1
          end
        end

        def include?(date_or_time)
          date_or_time.mday == target_for(date_or_time)
        end
      end
    end
  end
end