Sha256: 52f1a7ac9cae30f33fbc8a1dc527dcc25ed366c032485991495c5188988b4564

Contents?: true

Size: 835 Bytes

Versions: 7

Compression:

Stored size: 835 Bytes

Contents

module Chronic
  class RepeaterSecond < Repeater #:nodoc:
    SECOND_SECONDS = 1 # haha, awesome

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

    def next(pointer = :future)
      super

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

      unless @second_start
        @second_start = @now + (direction * SECOND_SECONDS)
      else
        @second_start += SECOND_SECONDS * direction
      end

      Span.new(@second_start, @second_start + SECOND_SECONDS)
    end

    def this(pointer = :future)
      super

      Span.new(@now, @now + 1)
    end

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

    def width
      SECOND_SECONDS
    end

    def to_s
      super << '-second'
    end
  end
end

Version data entries

7 entries across 7 versions & 4 rubygems

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