Class: SayWhen::YearsCronValue

Inherits:
CronValue show all
Defined in:
lib/say_when/cron_expression.rb

Instance Attribute Summary

Attributes inherited from CronValue

#expression, #max, #min, #part, #values

Instance Method Summary collapse

Methods inherited from CronValue

#include?, #parse, parse_number, #to_s

Constructor Details

#initialize(exp) ⇒ YearsCronValue

Returns a new instance of YearsCronValue.



535
536
537
# File 'lib/say_when/cron_expression.rb', line 535

def initialize(exp)
  super(:year, 1970, (Date.today.year + 100), exp)
end

Instance Method Details

#last(date) ⇒ Object



548
549
550
551
552
553
554
555
# File 'lib/say_when/cron_expression.rb', line 548

def last(date)
  last_year = values.reverse.detect { |v| v < date.year }
  if last_year.nil?
    return nil
  else
    date.change(year: last_year, month: 12, day: 31, hour: 23, min: 59, sec: 59)
  end
end

#next(date) ⇒ Object



539
540
541
542
543
544
545
546
# File 'lib/say_when/cron_expression.rb', line 539

def next(date)
  next_year = values.detect { |v| v > date.year }
  if next_year.nil?
    return nil
  else
    date.change(year: next_year, month: 1, day: 1, hour: 0)
  end
end