Allow to specify an order schedule for new orders.
This commit is contained in:
parent
6e990fed4c
commit
219eb71bc9
16 changed files with 204 additions and 8 deletions
|
|
@ -42,7 +42,7 @@ module DateTimeAttributeValidate
|
|||
self.instance_variable_get("@#{attribute}_date_value") || self.send("#{attribute}_date").try {|e| e.strftime('%Y-%m-%d')}
|
||||
end
|
||||
define_method("#{attribute}_time_value") do
|
||||
self.instance_variable_get("@#{attribute}_time_value") || self.send("#{attribute}_time").try {|e| e.strftime('%H:%m')}
|
||||
self.instance_variable_get("@#{attribute}_time_value") || self.send("#{attribute}_time").try {|e| e.strftime('%H:%M')}
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
|||
30
lib/foodsoft_date_util.rb
Normal file
30
lib/foodsoft_date_util.rb
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
module FoodsoftDateUtil
|
||||
# find next occurence given a recurring ical string and time
|
||||
def self.next_occurrence(start=Time.now, from=start, options={})
|
||||
if options[:recurr]
|
||||
schedule = IceCube::Schedule.new(start)
|
||||
schedule.add_recurrence_rule rule_from(options[:recurr])
|
||||
# @todo handle ical parse errors
|
||||
occ = (schedule.next_occurrence(from).to_time rescue nil)
|
||||
else
|
||||
occ = start
|
||||
end
|
||||
if occ and options[:time]
|
||||
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)
|
||||
if p.is_a? String
|
||||
IceCube::Rule.from_ical(p)
|
||||
elsif p.is_a? Hash
|
||||
IceCube::Rule.from_hash(p)
|
||||
else
|
||||
p
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue