lib/chronic/repeaters/repeater_minute.rb in chronic-0.2.3 vs lib/chronic/repeaters/repeater_minute.rb in chronic-0.3.0

- old
+ new

@@ -1,11 +1,16 @@ class Chronic::RepeaterMinute < Chronic::Repeater #:nodoc: MINUTE_SECONDS = 60 - + + def initialize(type) + super + @current_minute_start = nil + end + def next(pointer = :future) super - + if !@current_minute_start case pointer when :future @current_minute_start = Time.construct(@now.year, @now.month, @now.day, @now.hour, @now.min + 1) when :past @@ -13,17 +18,17 @@ end else direction = pointer == :future ? 1 : -1 @current_minute_start += direction * MINUTE_SECONDS end - + Chronic::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 = Time.construct(@now.year, @now.month, @now.day, @now.hour, @now.min) when :past @@ -31,22 +36,22 @@ minute_end = @now when :none minute_begin = Time.construct(@now.year, @now.month, @now.day, @now.hour, @now.min) minute_end = Time.construct(@now.year, @now.month, @now.day, @now.hour, @now.min) + MINUTE_SECONDS end - + Chronic::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 \ No newline at end of file +end