Sha256: fa1cafae4cb2edbf2777d72b05e42e48aac60123007f19daeee4b1f38b90ffcb

Contents?: true

Size: 758 Bytes

Versions: 16

Compression:

Stored size: 758 Bytes

Contents

# frozen_string_literal: true

module Montrose
  module Rule
    class DayOfMonth
      include Montrose::Rule

      def self.apply_options(opts)
        opts[:mday]
      end

      # Initializes rule
      #
      # @param [Array<Fixnum>] days - valid days of month, i.e. [1, 2, -1]
      #
      def initialize(days)
        @days = days
      end

      def include?(time)
        @days.include?(time.mday) || included_from_end_of_month?(time)
      end

      private

      # matches days specified at negative numbers
      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
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
montrose-0.18.0 lib/montrose/rule/day_of_month.rb
montrose-0.17.0 lib/montrose/rule/day_of_month.rb
montrose-0.16.0 lib/montrose/rule/day_of_month.rb
montrose-0.15.0 lib/montrose/rule/day_of_month.rb
montrose-0.14.0 lib/montrose/rule/day_of_month.rb
montrose-0.13.0 lib/montrose/rule/day_of_month.rb
montrose-0.12.0 lib/montrose/rule/day_of_month.rb
montrose-0.11.2 lib/montrose/rule/day_of_month.rb
montrose-0.11.1 lib/montrose/rule/day_of_month.rb
montrose-0.11.0 lib/montrose/rule/day_of_month.rb
montrose-0.10.1 lib/montrose/rule/day_of_month.rb
montrose-0.10.0 lib/montrose/rule/day_of_month.rb
montrose-0.9.0 lib/montrose/rule/day_of_month.rb
montrose-0.8.2 lib/montrose/rule/day_of_month.rb
montrose-0.8.1 lib/montrose/rule/day_of_month.rb
montrose-0.8.0 lib/montrose/rule/day_of_month.rb