Fix recurring event.
This commit is contained in:
parent
c902128062
commit
d78aab6408
|
@ -85,8 +85,20 @@ class PHire
|
|||
end
|
||||
events
|
||||
end
|
||||
|
||||
def convert_datetime(time)
|
||||
if time.class == Time
|
||||
return time.to_datetime
|
||||
elsif time.class == DateTime
|
||||
return time
|
||||
elsif time.class == String
|
||||
return DateTime.parse(time)
|
||||
else
|
||||
return Time.at(time).to_datetime #time is seconds
|
||||
end
|
||||
end
|
||||
def self.recurring_event(start_date,end_date,property_id,date_only=false)
|
||||
start_date = convert_datetime(start_date)
|
||||
end_date = convert_datetime(end_date)
|
||||
@property = Property.find(property_id) rescue nil
|
||||
@recurring = []
|
||||
if @property != nil
|
||||
|
@ -111,11 +123,14 @@ class PHire
|
|||
new_end_date = [recurring_end_date,end_date].min
|
||||
@end_date = re.end_time
|
||||
if @start_date < start_date
|
||||
add_interval = nil
|
||||
if re.recurring_interval == "week"
|
||||
@start_date += ((start_date - @start_date).to_i / 7) * interval
|
||||
add_interval = ((start_date - @start_date).to_i / 7).send("week")
|
||||
else
|
||||
@start_date += ((start_date.year * 12 + start_date.month) - (@start_date.year * 12 + @start_date.month) - 1) * interval
|
||||
add_interval = ((start_date.year * 12 + start_date.month) - (@start_date.year * 12 + @start_date.month) - 1).send("month")
|
||||
end
|
||||
@start_date += add_interval
|
||||
@end_date += add_interval
|
||||
end
|
||||
while @start_date <= new_end_date do
|
||||
if unavailable && (unavailable_start_date <= @start_date) && (unavailable_end_date >= @end_date) && !((@start_date.strftime("%w").to_i .. @end_date.strftime("%w").to_i).to_a & unavailable_weekdays).empty?
|
||||
|
|
Loading…
Reference in New Issue