Class: RiCal::PropertyValue::RecurrenceRule::RecurringYearDay

Inherits:
NumberedSpan show all
Defined in:
lib/ri_cal/property_value/recurrence_rule/recurring_year_day.rb

Overview

:nodoc:

Instance Attribute Summary

Attributes inherited from NumberedSpan

#source

Instance Method Summary collapse

Methods inherited from NumberedSpan

#==, #initialize, #ordinal, #to_s, #valid?

Constructor Details

This class inherits a constructor from RiCal::PropertyValue::RecurrenceRule::NumberedSpan

Instance Method Details

#fixed_day?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/ri_cal/property_value/recurrence_rule/recurring_year_day.rb', line 33

def fixed_day?
  @source > 0
end

#include?(date_or_time) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/ri_cal/property_value/recurrence_rule/recurring_year_day.rb', line 45

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

#lastObject



6
7
8
# File 'lib/ri_cal/property_value/recurrence_rule/recurring_year_day.rb', line 6

def last
  366
end

#leap_year?(year) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/ri_cal/property_value/recurrence_rule/recurring_year_day.rb', line 10

def leap_year?(year)
  year % 4 == 0 && (year % 400 == 0 || year % 100 != 0)
end

#length_of_year(year) ⇒ Object



15
16
17
# File 'lib/ri_cal/property_value/recurrence_rule/recurring_year_day.rb', line 15

def length_of_year(year)
  leap_year?(year) ? 366 : 365
end

#list_id(time) ⇒ Object

return a list id for a given time to allow the enumerator to cache lists



20
21
22
# File 'lib/ri_cal/property_value/recurrence_rule/recurring_year_day.rb', line 20

def list_id(time)
  time.year
end

#matches_for(time) ⇒ Object

return a list of times which match the time parameter within the scope of the RecurringDay



25
26
27
# File 'lib/ri_cal/property_value/recurrence_rule/recurring_year_day.rb', line 25

def matches_for(time)
  [time.change(:month => 1, :day => 1).advance(:days => target_for(time)- 1)]
end

#target_date_time_for(date_time) ⇒ Object



29
30
31
# File 'lib/ri_cal/property_value/recurrence_rule/recurring_year_day.rb', line 29

def target_date_time_for(date_time)
  matches_for(date_time)[0]
end

#target_for(date_or_time) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/ri_cal/property_value/recurrence_rule/recurring_year_day.rb', line 37

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