File: yearly_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 (57 lines) | stat: -rw-r--r-- 1,618 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
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 YearlyIncrementer < FrequencyIncrementer #:nodoc:

           attr_reader :wkst

           def initialize(rrule, sub_cycle_incrementer)
             @wkst = rrule.wkst_day
             super(rrule, sub_cycle_incrementer)
           end

           def self.from_rrule(rrule, start_time)
             conditional_incrementer(rrule, "YEARLY", ByMonthIncrementer)
           end

           def advance_what
             :years
           end

           def step(date_time)
             if contains_weeknum_incrementer?
               result = date_time
               multiplier.times do
                 result = result.at_start_of_next_iso_year(wkst)
               end
               result
             else
               super(date_time)
             end
           end

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

           def end_of_occurrence(date_time)
             if contains_weeknum_incrementer?
               date_time.end_of_iso_year(wkst)
             else
               date_time.end_of_year
             end
           end
        end
      end
    end
  end
end