class Holidays::DateCalculator::DayOfMonth
see www.irt.org/articles/js050/index.htm<br>–
=> 28
Holidays::DateCalculatorFactory.day_of_month_calculator.call(2008, 1, :last, 1)
Last Monday of January, 2008:
=> 18
Holidays::DateCalculatorFactory.day_of_month_calculator.call(2008, 12, :third, :thursday)
Third Thursday of December, 2008:
=> 7
Holidays::DateCalculatorFactory.day_of_month_calculator.call(2008, 1, :first, :monday)
First Monday of January, 2008:
===== Examples
Returns an integer.
(Saturday) or as a symbol (e.g. :monday).
[wday] Day of the week as an integer from 0 (Sunday) to 6:fourth, :fifth or :last.
[week] One of :first, :second, :third,
[month] Integer from 1-12.
[year] Integer.
==== Parameters
week.
Calculate day of the month based on the week number and the day of the
def call(year, month, week, wday)
def call(year, month, week, wday) raise ArgumentError, "Week parameter must be one of Holidays::WEEKS (provided #{week})." unless weeks.include?(week) or weeks.has_value?(week) unless wday.kind_of?(Numeric) and wday.between?(0,6) or day_symbols.index(wday) raise ArgumentError, "Wday parameter must be an integer between 0 and 6 or one of Holidays::DAY_SYMBOLS." end week = weeks[week] if week.kind_of?(Symbol) wday = day_symbols.index(wday) if wday.kind_of?(Symbol) # :first, :second, :third, :fourth or :fifth if week > 0 return ((week - 1) * 7) + 1 + ((wday - Date.civil(year, month,(week-1)*7 + 1).wday) % 7) end days = month_lengths[month-1] days = 29 if month == 2 and Date.leap?(year) return days - ((Date.civil(year, month, days).wday - wday + 7) % 7) - (7 * (week.abs - 1)) end
def day_symbols
def day_symbols Holidays::DAY_SYMBOLS end
def month_lengths
def month_lengths Holidays::MONTH_LENGTHS end
def weeks
def weeks Holidays::WEEKS end