lib/fugit/cron.rb in fugit-0.9.4 vs lib/fugit/cron.rb in fugit-0.9.5
- old
+ new
@@ -65,10 +65,12 @@
return s if s.is_a?(self)
original = s
s = SPECIALS[s] || s
+ return nil unless s.is_a?(String)
+
#p s; Raabro.pp(Parser.parse(s, debug: 3))
h = Parser.parse(s)
return nil unless h
@@ -78,14 +80,14 @@
def self.do_parse(s)
parse(s) || fail(ArgumentError.new("not a cron string #{s.inspect}"))
end
- class NextTime # TODO at some point, use ZoTime
+ class TimeCursor # TODO at some point, use ZoTime
def initialize(t)
- @t = t.is_a?(NextTime) ? t.time : t
+ @t = t.is_a?(TimeCursor) ? t.time : t
end
def time; @t; end
def to_i; @t.to_i; end
@@ -171,11 +173,11 @@
def monthday_match?(nt)
return true if @monthdays.nil?
- last = (NextTime.new(nt).inc_month.time - 24 * 3600).day + 1
+ last = (TimeCursor.new(nt).inc_month.time - 24 * 3600).day + 1
@monthdays
.collect { |d| d < 1 ? last + d : d }
.include?(nt.day)
end
@@ -192,49 +194,49 @@
end
def match?(t)
t = Fugit.do_parse_at(t)
- t = NextTime.new(t)
+ t = TimeCursor.new(t)
month_match?(t) && day_match?(t) &&
hour_match?(t) && min_match?(t) && sec_match?(t)
end
def next_time(from=Time.now)
- nt = NextTime.new(from)
+ t = TimeCursor.new(from)
loop do
-#p [ :l, Fugit.time_to_s(nt.time) ]
- (from.to_i == nt.to_i) && (nt.inc(1); next)
- month_match?(nt) || (nt.inc_month; next)
- day_match?(nt) || (nt.inc_day; next)
- hour_match?(nt) || (nt.inc_hour; next)
- min_match?(nt) || (nt.inc_min; next)
- sec_match?(nt) || (nt.inc_sec(@seconds); next)
+#p [ :l, Fugit.time_to_s(t.time) ]
+ (from.to_i == t.to_i) && (t.inc(1); next)
+ month_match?(t) || (t.inc_month; next)
+ day_match?(t) || (t.inc_day; next)
+ hour_match?(t) || (t.inc_hour; next)
+ min_match?(t) || (t.inc_min; next)
+ sec_match?(t) || (t.inc_sec(@seconds); next)
break
end
- nt.time
+ t.time
end
def previous_time(from=Time.now)
- nt = NextTime.new(from)
+ t = TimeCursor.new(from)
loop do
-#p [ :l, Fugit.time_to_s(nt.time) ]
- (from.to_i == nt.to_i) && (nt.inc(-1); next)
- month_match?(nt) || (nt.dec_month; next)
- day_match?(nt) || (nt.dec_day; next)
- hour_match?(nt) || (nt.dec_hour; next)
- min_match?(nt) || (nt.dec_min; next)
- sec_match?(nt) || (nt.dec_sec(@seconds); next)
+#p [ :l, Fugit.time_to_s(t.time) ]
+ (from.to_i == t.to_i) && (t.inc(-1); next)
+ month_match?(t) || (t.dec_month; next)
+ day_match?(t) || (t.dec_day; next)
+ hour_match?(t) || (t.dec_hour; next)
+ min_match?(t) || (t.dec_min; next)
+ sec_match?(t) || (t.dec_sec(@seconds); next)
break
end
- nt.time
+ t.time
end
# Mostly used as a #next_time sanity check.
# Avoid for "business" use, it's slow.
#