Sha256: 8f97ce2416947887e1a5a39f3f86e294f70902449760b173647a8f195def366d

Contents?: true

Size: 1.6 KB

Versions: 7

Compression:

Stored size: 1.6 KB

Contents

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

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

    def next(pointer = :future)
      super

      unless @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

7 entries across 7 versions & 4 rubygems

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