File: by_month_incrementer.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 (52 lines) | stat: -rw-r--r-- 1,446 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
module RiCal
  class PropertyValue
    class RecurrenceRule < PropertyValue
      #- ©2009 Rick DeNatale, All rights reserved. Refer to the file README.txt for the license
      #
      class OccurrenceIncrementer # :nodoc:
        class ByMonthIncrementer < ListIncrementer #:nodoc:

          def self.for_rrule(rrule)
            conditional_incrementer(rrule, :bymonth, MonthlyIncrementer)
          end

          def occurrences_for(date_time)
            if contains_daily_incrementer?
              list.map {|value| date_time.change(:month => value, :day => 1)}
            else
              list.map {|value| date_time.in_month(value)}
            end
          end

          def range_advance(date_time)
            advance_year(date_time)
          end

          def start_of_cycle(date_time)
            if contains_daily_incrementer?
              date_time.change(:month => 1, :day => 1)
            else
              date_time.change(:month => 1)
            end
          end

          def varying_time_attribute
            :month
          end

          def advance_cycle(date_time)
            if contains_daily_incrementer?
              first_day_of_year(advance_year(date_time))
            else
              advance_year(date_time).change(:month => 1)
            end
          end

          def end_of_occurrence(date_time)
            date_time.end_of_month
          end
        end
      end
    end
  end
end