RiCal::CoreExtensions::Time::WeekDayPredicates

 Provide predicate and related methods for use by the RiCal gem
 This module is included by Time, Date, and DateTime

Public Instance Methods

nth_wday_in_month(n, which_wday, for_time = self) click to toggle source

e.g. to obtain the 3nd Tuesday of the receivers month use

  time.nth_wday_in_month(2, 2)
# File lib/ri_cal/core_extensions/time/week_day_predicates.rb, line 20
        def nth_wday_in_month(n, which_wday, for_time = self)
          first_of_month = for_time.to_ri_cal_property_value.change(:day => 1)
          first_in_month = first_of_month.advance(:days => (which_wday - first_of_month.wday))
          first_in_month = first_in_month.advance(:days => 7) if first_in_month.month != first_of_month.month
          if n > 0
            first_in_month.advance(:days => (7*(n - 1)))
          else
            possible = first_in_month.advance(:days => 21)
            possible = possible.advance(:days => 7) while possible.month == first_in_month.month
            last_in_month = possible.advance(:days => - 7)
            (last_in_month.advance(:days => - (7*(n.abs - 1))))
          end
        end
nth_wday_in_month?(n, which_wday) click to toggle source

A predicate to determine whether or not the receiver falls on a particular weekday of its month.

Parameters

n:the ordinal number being requested
which_wday:the weekday using Ruby time conventions, i.e. 0 => Sunday, 1 => Monday, …
# File lib/ri_cal/core_extensions/time/week_day_predicates.rb, line 39
        def nth_wday_in_month?(n, which_wday)
          target = nth_wday_in_month(n, which_wday)
          [self.year, self.month, self.day] == [target.year, target.month, target.day]
        end
start_of_week_with_wkst(wkst) click to toggle source

Return a DateTime which is the beginning of the first day on or before the receiver with the specified wday

# File lib/ri_cal/core_extensions/time/week_day_predicates.rb, line 46
        def start_of_week_with_wkst(wkst)
           wkst ||= 1
           date = ::Date.civil(self.year, self.month, self.day)
           date -= 1 while date.wday != wkst
           date
        end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.