Sha256: 438601329fa74a9a6f63c1dee02f87c98743038832f454c20c265549f16106f8

Contents?: true

Size: 659 Bytes

Versions: 6

Compression:

Stored size: 659 Bytes

Contents

module Montrose
  module Rule
    class DayOfYear
      include Montrose::Rule

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

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

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

      private

      def included_from_end_of_month?(time)
        year_days = ::Montrose::Utils.days_in_year(time.year) # given by activesupport
        @days.any? { |d| year_days + d + 1 == time.yday }
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
montrose-0.6.0 lib/montrose/rule/day_of_year.rb
montrose-0.5.0 lib/montrose/rule/day_of_year.rb
montrose-0.4.3 lib/montrose/rule/day_of_year.rb
montrose-0.4.2 lib/montrose/rule/day_of_year.rb
montrose-0.4.1 lib/montrose/rule/day_of_year.rb
montrose-0.4.0 lib/montrose/rule/day_of_year.rb