Sha256: 15b81a45332ceb6aadd7bf5edf025a8cf8879e9a1ccb18a553a22961be20d026

Contents?: true

Size: 1.33 KB

Versions: 30

Compression:

Stored size: 1.33 KB

Contents

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

    def initialize(type)
      super
    end

    def next(pointer)
      super

      if !@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

30 entries across 30 versions & 5 rubygems

Version Path
chronic-mmlac-0.6.4.2 lib/chronic/repeaters/repeater_day.rb
chronic-0.9.1 lib/chronic/repeaters/repeater_day.rb
chronic-0.9.0 lib/chronic/repeaters/repeater_day.rb
Hokkaido-0.1.5 chronic/lib/chronic/repeaters/repeater_day.rb
Hokkaido-0.1.4 chronic/lib/chronic/repeaters/repeater_day.rb
Hokkaido-0.1.3 chronic/lib/chronic/repeaters/repeater_day.rb
Hokkaido-0.1.2 chronic/lib/chronic/repeaters/repeater_day.rb
Hokkaido-0.1.1 chronic/lib/chronic/repeaters/repeater_day.rb
Hokkaido-0.1.0 chronic/lib/chronic/repeaters/repeater_day.rb
Hokkaido-0.0.9 chronic/lib/chronic/repeaters/repeater_day.rb
Hokkaido-0.0.6 chronic/lib/chronic/repeaters/repeater_day.rb
Hokkaido-0.0.5 chronic/lib/chronic/repeaters/repeater_day.rb
Hokkaido-0.0.4 chronic/lib/chronic/repeaters/repeater_day.rb
chronic-0.8.0 lib/chronic/repeaters/repeater_day.rb
chronic-0.7.0 lib/chronic/repeaters/repeater_day.rb
chronic_2001-0.1.5 lib/chronic/repeaters/repeater_day.rb
chronic_2001-0.1.4 lib/chronic/repeaters/repeater_day.rb
chronic_2001-0.1.3 lib/chronic/repeaters/repeater_day.rb
chronic_2001-0.1.2 lib/chronic/repeaters/repeater_day.rb
chronic_2001-0.1.1 lib/chronic/repeaters/repeater_day.rb