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)


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

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

#lastObject

:nodoc:



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

def last
  366
end

#leap_year?(year) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#length_of_year(year) ⇒ Object



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

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



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

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



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

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

#target_date_time_for(date_time) ⇒ Object



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

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

#target_for(date_or_time) ⇒ Object



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

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