Method: RiCal::FastDateTime#nth_wday_in_year
- Defined in:
- lib/ri_cal/fast_date_time.rb
#nth_wday_in_year(n, which_wday) ⇒ Object
e.g. to obtain the 2nd Monday of the receivers year use
time.nth_wday_in_year(2, 1)
185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/ri_cal/fast_date_time.rb', line 185 def nth_wday_in_year(n, which_wday) if n > 0 first_of_year = change(:month => 1, :day => 1) first_in_year = first_of_year.advance(:days => (which_wday - first_of_year.wday + 7) % 7) first_in_year.advance(:days => (7*(n - 1))) else december25 = change(:month => 12, :day => 25) last_in_year = december25.advance(:days => (which_wday - december25.wday + 7) % 7) last_in_year.advance(:days => (7 * (n + 1))) end end |