fix error

This commit is contained in:
chiu 2020-05-26 23:02:09 +08:00
parent 386cb0c5e0
commit b83b4e5633
1 changed files with 21 additions and 12 deletions

View File

@ -108,10 +108,6 @@ class Property
if (b_interval == 'month' || b_interval == 'week') && booking.recurring_end_date.nil? if (b_interval == 'month' || b_interval == 'week') && booking.recurring_end_date.nil?
b_interval = nil b_interval = nil
end end
if b_interval != 'month' && b_interval != 'week'
b_sdata = booking.start_time
b_edata = booking.end_time
end
while true while true
if b_interval == 'month' if b_interval == 'month'
diff_month = booking.end_time.month - booking.start_time.month diff_month = booking.end_time.month - booking.start_time.month
@ -119,19 +115,27 @@ class Property
e_month = stime_tp.month + diff_month e_month = stime_tp.month + diff_month
e_year = stime_tp.year + (booking.end_time.year-booking.start_time.year) e_year = stime_tp.year + (booking.end_time.year-booking.start_time.year)
e_month = e_month - 12 e_month = e_month - 12
b_sdata = "#{stime_tp.year}/#{stime_tp.month}/#{booking.start_time.day} #{booking.start_time.hour}:#{booking.start_time.minute}".to_datetime b_sdata = Time.local(stime_tp.year,stime_tp.month,booking.start_time.day,booking.start_time.hour,booking.start_time.minute).to_datetime
b_edata = "#{e_year}/#{e_month}/#{booking.end_time.day} #{booking.end_time.hour}:#{booking.end_time.minute}".to_datetime b_edata = Time.local(e_year,e_month,booking.end_time.day,booking.end_time.hour,booking.end_time.minute).to_datetime
elsif b_interval = 'week' elsif b_interval == 'week'
diff_day = booking.end_time -booking.start_time diff_day = booking.end_time - booking.start_time
if (booking.end_time.wday <= booking.start_time.wday && diff_day>1) || diff_day > 7 if (booking.end_time.wday <= booking.start_time.wday && diff_day>1) || diff_day > 7
over_one_week = true over_one_week = true
end end
b_sdata = stime_tp - stime_tp.wday + booking.start_time.wday b_sdata_tp = stime_tp - stime_tp.wday.day + booking.start_time.wday.day
if over_one_week && etime_tp.wday<=booking.start_time.wday b_sdata = Time.local(b_sdata_tp.year,b_sdata_tp.month,b_sdata_tp.day,booking.start_time.hour,booking.start_time.minute).to_datetime
if over_one_week && etime_tp.wday <= booking.start_time.wday
b_sdata = b_sdata - 7.day b_sdata = b_sdata - 7.day
end end
b_edata_tp = b_sdata + (booking.end_time-booking.start_time).to_i.day now_diff_day = etime_tp - stime_tp
b_edata = "#{b_edata_tp.year}/#{b_edata_tp.month}/#{b_edata_tp.day} #{booking.end_time.hour}:#{booking.end_time.minute}".to_datetime if (etime_tp.wday <= stime_tp.wday && now_diff_day>1) || now_diff_day > 7
b_sdata = b_sdata + 7.day
end
b_edata_tp = b_sdata + (booking.end_time - booking.start_time).to_i.day
b_edata = Time.local(b_edata_tp.year,b_edata_tp.month,b_edata_tp.day,booking.end_time.hour,booking.end_time.minute).to_datetime
else
b_sdata = booking.start_time
b_edata = booking.end_time
end end
sdata = stime_tp sdata = stime_tp
edata = etime_tp edata = etime_tp
@ -139,6 +143,11 @@ class Property
if (sdata <= b_sdata && edata >= b_sdata) || (sdata >= b_sdata && edata <= b_edata) || (sdata <= b_edata && edata >= b_edata) if (sdata <= b_sdata && edata >= b_sdata) || (sdata >= b_sdata && edata <= b_edata) || (sdata <= b_edata && edata >= b_edata)
available = false available = false
end end
if !b_interval.blank?
puts '-------------'
puts booking.inspect
puts ['sdata',sdata,'b_sdata',b_sdata,'edata',edata,'b_edata',b_edata]
end
end end
stime_tp = stime_tp + d_step stime_tp = stime_tp + d_step
etime_tp = etime_tp + d_step etime_tp = etime_tp + d_step