Skip to content

Commit

Permalink
Revise #montday_match? for HyphenRange
Browse files Browse the repository at this point in the history
  • Loading branch information
jmettraux committed Mar 3, 2024
1 parent c4eda19 commit 1a87bda
Showing 1 changed file with 36 additions and 6 deletions.
42 changes: 36 additions & 6 deletions lib/fugit/cron.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,12 @@ def inc_min
end

def inc_sec
if sec = @cron.seconds.find { |s| s > @t.sec }
#if sec = @cron.seconds.find { |s| s > @t.sec }
if sec = @cron.send(:next_second, @t.sec)
inc(sec - @t.sec)
else
inc(60 - @t.sec + @cron.seconds.first)
#inc(60 - @t.sec + @cron.seconds.first)
inc(60 - @t.sec + @cron.send(:first_second))
end
end

Expand Down Expand Up @@ -194,11 +196,12 @@ def monthday_match?(nt)

return true if @monthdays.nil?

last = (TimeCursor.new(self, nt).inc_month.time - 24 * 3600).day + 1
#last = (TimeCursor.new(self, nt).inc_month.time - 24 * 3600).day + 1
#@monthdays
# .collect { |d| d < 1 ? last + d : d }
# .include?(nt.day)

@monthdays
.collect { |d| d < 1 ? last + d : d }
.include?(nt.day)
@monthdays.find { |range| range.include?(nt.day) }
end

def day_match?(nt)
Expand Down Expand Up @@ -503,6 +506,27 @@ def hash

protected

# if sec = @cron.seconds.find { |s| s > @t.sec }
# if sec = @cron.next_second(@t.sec)
# if sec = @cron.send(:next_second, @t.sec)
#
def next_second(current_second)

@seconds
.collect { |range| range.next_after(current_second) }
.compact
.sort
.first
end

def first_second

@seconds
.collect(&:first)
.sort
.first
end

# def compact_month_days
#
# return true if @months == nil || @monthdays == nil
Expand Down Expand Up @@ -635,6 +659,12 @@ def initialize(key, a)
def include?(i)
expanded.include?(i)
end
def next_after(i)
expanded.find { |e| e > i }
end
def first
expanded.first
end
protected
def expanded
@expanded ||= (@sta..@edn).step(@sla).to_a
Expand Down

0 comments on commit 1a87bda

Please sign in to comment.