Module: FoodsoftDateUtil
- Defined in:
- app/lib/foodsoft_date_util.rb
Class Method Summary collapse
-
.next_occurrence(start = Time.now, from = start, options = {}) ⇒ Object
find next occurence given a recurring ical string and time.
-
.rule_from(rule) ⇒ IceCube::Rule
Recurring rule.
Class Method Details
.next_occurrence(start = Time.now, from = start, options = {}) ⇒ Object
find next occurence given a recurring ical string and time
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'app/lib/foodsoft_date_util.rb', line 3 def self.next_occurrence(start = Time.now, from = start, = {}) occ = nil if && [:recurr] schedule = IceCube::Schedule.new(start) schedule.add_recurrence_rule rule_from([:recurr]) # @todo handle ical parse errors occ = begin schedule.next_occurrence(from).to_time rescue StandardError nil end end occ = occ.beginning_of_day.advance(seconds: Time.parse([:time]).seconds_since_midnight) if && [:time] && occ occ end |
.rule_from(rule) ⇒ IceCube::Rule
Returns Recurring rule.
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/lib/foodsoft_date_util.rb', line 21 def self.rule_from(rule) case rule when String IceCube::Rule.from_ical(rule) when Hash IceCube::Rule.from_hash(rule) when ActionController::Parameters IceCube::Rule.from_hash(rule.to_hash) else rule end end |