class Montrose::Rule::DayOfMonth

Public Class Methods

apply_options(opts) click to toggle source
# File lib/montrose/rule/day_of_month.rb, line 8
def self.apply_options(opts)
  opts[:mday]
end
new(days) click to toggle source

Initializes rule

@param [Array<Fixnum>] days - valid days of month, i.e. [1, 2, -1]

# File lib/montrose/rule/day_of_month.rb, line 16
def initialize(days)
  @days = days
end

Public Instance Methods

include?(time) click to toggle source
# File lib/montrose/rule/day_of_month.rb, line 20
def include?(time)
  @days.include?(time.mday) || included_from_end_of_month?(time)
end

Private Instance Methods

included_from_end_of_month?(time) click to toggle source

matches days specified at negative numbers

# File lib/montrose/rule/day_of_month.rb, line 27
def included_from_end_of_month?(time)
  month_days = ::Montrose::Utils.days_in_month(time.month, time.year) # given by activesupport
  @days.any? { |d| month_days + d + 1 == time.mday }
end