mirror of
https://github.com/plashchynski/crono.git
synced 2026-03-28 04:12:00 +01:00
25 lines
483 B
Ruby
25 lines
483 B
Ruby
module Periodicity
|
|
class Period
|
|
def initialize(period, at: nil)
|
|
@period = period
|
|
@at_hour, @at_min = parse_at(at) if at
|
|
end
|
|
|
|
def next
|
|
@period.from_now.change({hour: @at_hour, min: @at_min}.compact)
|
|
end
|
|
|
|
def parse_at(at)
|
|
case at
|
|
when String
|
|
time = Time.parse(at)
|
|
return time.hour, time.min
|
|
when Hash
|
|
return at[:hour], at[:min]
|
|
else
|
|
raise "Unknown 'at' format"
|
|
end
|
|
end
|
|
end
|
|
end
|