Sha256: a1ae7285695135e19a6f48ef709e1e5f142a554316839879b40001e5efc171b4

Contents?: true

Size: 1.24 KB

Versions: 7

Compression:

Stored size: 1.24 KB

Contents

module Chronic
  class RepeaterDayName < Repeater #:nodoc:
    DAY_SECONDS = 86400 # (24 * 60 * 60)

    def initialize(type, options = {})
      super
      @current_date = nil
    end

    def next(pointer)
      super

      direction = pointer == :future ? 1 : -1

      unless @current_date
        @current_date = ::Date.new(@now.year, @now.month, @now.day)
        @current_date += direction

        day_num = symbol_to_number(@type)

        while @current_date.wday != day_num
          @current_date += direction
        end
      else
        @current_date += direction * 7
      end
      next_date = @current_date.succ
      Span.new(Chronic.construct(@current_date.year, @current_date.month, @current_date.day), Chronic.construct(next_date.year, next_date.month, next_date.day))
    end

    def this(pointer = :future)
      super

      pointer = :future if pointer == :none
      self.next(pointer)
    end

    def width
      DAY_SECONDS
    end

    def to_s
      super << '-dayname-' << @type.to_s
    end

    private

    def symbol_to_number(sym)
      lookup = {:sunday => 0, :monday => 1, :tuesday => 2, :wednesday => 3, :thursday => 4, :friday => 5, :saturday => 6}
      lookup[sym] || raise("Invalid symbol specified")
    end
  end
end

Version data entries

7 entries across 7 versions & 4 rubygems

Version Path
gitlab-chronic-0.10.6 lib/chronic/repeaters/repeater_day_name.rb
gitlab-chronic-0.10.5 lib/chronic/repeaters/repeater_day_name.rb
asana2flowdock-1.0.0 vendor/bundle/ruby/1.9.1/gems/chronic-0.10.2/lib/chronic/repeaters/repeater_day_name.rb
chronic-mmlac-0.10.2.1 lib/chronic/repeaters/repeater_day_name.rb
chronic-0.10.2 lib/chronic/repeaters/repeater_day_name.rb
chronic-0.10.1 lib/chronic/repeaters/repeater_day_name.rb
chronic-0.10.0 lib/chronic/repeaters/repeater_day_name.rb