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

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

Overview

  • ©2009 Rick DeNatale, All rights reserved. Refer to the file README.txt for the license

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

#include?(date_or_time) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/ri_cal/property_value/recurrence_rule/recurring_year_day.rb', line 43

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

#lastObject

:nodoc:



8
9
10
# File 'lib/ri_cal/property_value/recurrence_rule/recurring_year_day.rb', line 8

def last
  366
end

#leap_year?(year) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/ri_cal/property_value/recurrence_rule/recurring_year_day.rb', line 12

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

#length_of_year(year) ⇒ Object



17
18
19
# File 'lib/ri_cal/property_value/recurrence_rule/recurring_year_day.rb', line 17

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



22
23
24
# File 'lib/ri_cal/property_value/recurrence_rule/recurring_year_day.rb', line 22

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



27
28
29
# File 'lib/ri_cal/property_value/recurrence_rule/recurring_year_day.rb', line 27

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

#target_date_time_for(date_time) ⇒ Object



31
32
33
# File 'lib/ri_cal/property_value/recurrence_rule/recurring_year_day.rb', line 31

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

#target_for(date_or_time) ⇒ Object



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

def target_for(date_or_time)
  if @source > 0
    @source
  else
    length_of_year(date_or_time.year) + @source + 1
  end
end