viehlieb
fb8ccfea4a
mv lib to app/lib due to upgrade removing concerns from autoload path resolve zeitwerk issues make foodsoft run for dev on rails 7 and ruby 2.7 fix mail file permission bug fix database_config fix articles controller test ActiveModell::Error bump Gemfile.lock
33 lines
917 B
Ruby
33 lines
917 B
Ruby
module FoodsoftDateUtil
|
|
# find next occurence given a recurring ical string and time
|
|
def self.next_occurrence(start = Time.now, from = start, options = {})
|
|
occ = nil
|
|
if options && options[:recurr]
|
|
schedule = IceCube::Schedule.new(start)
|
|
schedule.add_recurrence_rule rule_from(options[:recurr])
|
|
# @todo handle ical parse errors
|
|
occ = begin
|
|
schedule.next_occurrence(from).to_time
|
|
rescue
|
|
nil
|
|
end
|
|
end
|
|
if options && options[:time] && occ
|
|
occ = occ.beginning_of_day.advance(seconds: Time.parse(options[:time]).seconds_since_midnight)
|
|
end
|
|
occ
|
|
end
|
|
|
|
# @param p [String, Symbol, Hash, IceCube::Rule] What to return a rule from.
|
|
# @return [IceCube::Rule] Recurring rule
|
|
def self.rule_from(p)
|
|
case p
|
|
when String
|
|
IceCube::Rule.from_ical(p)
|
|
when Hash
|
|
IceCube::Rule.from_hash(p)
|
|
else
|
|
p
|
|
end
|
|
end
|
|
end
|