Sha256: d89898cbc12dc9294d2ccd0747914bcc740d1fea6ee37f9c75047057616ec319

Contents?: true

Size: 1.37 KB

Versions: 7

Compression:

Stored size: 1.37 KB

Contents

module Chronic
  class RepeaterDay < Repeater #:nodoc:
    DAY_SECONDS = 86_400 # (24 * 60 * 60)

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

    def next(pointer)
      super

      unless @current_day_start
        @current_day_start = Chronic.time_class.local(@now.year, @now.month, @now.day)
      end

      direction = pointer == :future ? 1 : -1
      @current_day_start += direction * DAY_SECONDS

      Span.new(@current_day_start, @current_day_start + DAY_SECONDS)
    end

    def this(pointer = :future)
      super

      case pointer
      when :future
        day_begin = Chronic.construct(@now.year, @now.month, @now.day, @now.hour)
        day_end = Chronic.construct(@now.year, @now.month, @now.day) + DAY_SECONDS
      when :past
        day_begin = Chronic.construct(@now.year, @now.month, @now.day)
        day_end = Chronic.construct(@now.year, @now.month, @now.day, @now.hour)
      when :none
        day_begin = Chronic.construct(@now.year, @now.month, @now.day)
        day_end = Chronic.construct(@now.year, @now.month, @now.day) + DAY_SECONDS
      end

      Span.new(day_begin, day_end)
    end

    def offset(span, amount, pointer)
      direction = pointer == :future ? 1 : -1
      span + direction * amount * DAY_SECONDS
    end

    def width
      DAY_SECONDS
    end

    def to_s
      super << '-day'
    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.rb
gitlab-chronic-0.10.5 lib/chronic/repeaters/repeater_day.rb
asana2flowdock-1.0.0 vendor/bundle/ruby/1.9.1/gems/chronic-0.10.2/lib/chronic/repeaters/repeater_day.rb
chronic-mmlac-0.10.2.1 lib/chronic/repeaters/repeater_day.rb
chronic-0.10.2 lib/chronic/repeaters/repeater_day.rb
chronic-0.10.1 lib/chronic/repeaters/repeater_day.rb
chronic-0.10.0 lib/chronic/repeaters/repeater_day.rb