Sha256: e955b00f7e09ffd8d70b66ee7cb65f7f12ac4130e622f6deff5b72ee9f6c8457

Contents?: true

Size: 690 Bytes

Versions: 16

Compression:

Stored size: 690 Bytes

Contents

# frozen_string_literal: true

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

16 entries across 16 versions & 1 rubygems

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