Sha256: c3474a349162b8c5f9d647de7e7647c3ebe6be1b77388ede7ac80516a9f09e1b

Contents?: true

Size: 1.54 KB

Versions: 30

Compression:

Stored size: 1.54 KB

Contents

module Chronic
  class RepeaterMinute < Repeater #:nodoc:
    MINUTE_SECONDS = 60

    def initialize(type)
      super
    end

    def next(pointer = :future)
      super

      if !@current_minute_start
        case pointer
        when :future
          @current_minute_start = Chronic.construct(@now.year, @now.month, @now.day, @now.hour, @now.min + 1)
        when :past
          @current_minute_start = Chronic.construct(@now.year, @now.month, @now.day, @now.hour, @now.min - 1)
        end
      else
        direction = pointer == :future ? 1 : -1
        @current_minute_start += direction * MINUTE_SECONDS
      end

      Span.new(@current_minute_start, @current_minute_start + MINUTE_SECONDS)
    end

    def this(pointer = :future)
      super

      case pointer
      when :future
        minute_begin = @now
        minute_end = Chronic.construct(@now.year, @now.month, @now.day, @now.hour, @now.min)
      when :past
        minute_begin = Chronic.construct(@now.year, @now.month, @now.day, @now.hour, @now.min)
        minute_end = @now
      when :none
        minute_begin = Chronic.construct(@now.year, @now.month, @now.day, @now.hour, @now.min)
        minute_end = Chronic.construct(@now.year, @now.month, @now.day, @now.hour, @now.min) + MINUTE_SECONDS
      end

      Span.new(minute_begin, minute_end)
    end

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

    def width
      MINUTE_SECONDS
    end

    def to_s
      super << '-minute'
    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_minute.rb
chronic-0.9.1 lib/chronic/repeaters/repeater_minute.rb
chronic-0.9.0 lib/chronic/repeaters/repeater_minute.rb
Hokkaido-0.1.5 chronic/lib/chronic/repeaters/repeater_minute.rb
Hokkaido-0.1.4 chronic/lib/chronic/repeaters/repeater_minute.rb
Hokkaido-0.1.3 chronic/lib/chronic/repeaters/repeater_minute.rb
Hokkaido-0.1.2 chronic/lib/chronic/repeaters/repeater_minute.rb
Hokkaido-0.1.1 chronic/lib/chronic/repeaters/repeater_minute.rb
Hokkaido-0.1.0 chronic/lib/chronic/repeaters/repeater_minute.rb
Hokkaido-0.0.9 chronic/lib/chronic/repeaters/repeater_minute.rb
Hokkaido-0.0.6 chronic/lib/chronic/repeaters/repeater_minute.rb
Hokkaido-0.0.5 chronic/lib/chronic/repeaters/repeater_minute.rb
Hokkaido-0.0.4 chronic/lib/chronic/repeaters/repeater_minute.rb
chronic-0.8.0 lib/chronic/repeaters/repeater_minute.rb
chronic-0.7.0 lib/chronic/repeaters/repeater_minute.rb
chronic_2001-0.1.5 lib/chronic/repeaters/repeater_minute.rb
chronic_2001-0.1.4 lib/chronic/repeaters/repeater_minute.rb
chronic_2001-0.1.3 lib/chronic/repeaters/repeater_minute.rb
chronic_2001-0.1.2 lib/chronic/repeaters/repeater_minute.rb
chronic_2001-0.1.1 lib/chronic/repeaters/repeater_minute.rb