From b83b4e5633566cb2aaf89d892bd8ee77aa9fea6e Mon Sep 17 00:00:00 2001 From: chiu Date: Tue, 26 May 2020 23:02:09 +0800 Subject: [PATCH] fix error --- app/models/property.rb | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/app/models/property.rb b/app/models/property.rb index 02af595..29aae9d 100644 --- a/app/models/property.rb +++ b/app/models/property.rb @@ -108,10 +108,6 @@ class Property if (b_interval == 'month' || b_interval == 'week') && booking.recurring_end_date.nil? b_interval = nil end - if b_interval != 'month' && b_interval != 'week' - b_sdata = booking.start_time - b_edata = booking.end_time - end while true if b_interval == '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_year = stime_tp.year + (booking.end_time.year-booking.start_time.year) 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_edata = "#{e_year}/#{e_month}/#{booking.end_time.day} #{booking.end_time.hour}:#{booking.end_time.minute}".to_datetime - elsif b_interval = 'week' - diff_day = booking.end_time -booking.start_time + 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 = Time.local(e_year,e_month,booking.end_time.day,booking.end_time.hour,booking.end_time.minute).to_datetime + elsif b_interval == 'week' + diff_day = booking.end_time - booking.start_time if (booking.end_time.wday <= booking.start_time.wday && diff_day>1) || diff_day > 7 over_one_week = true end - b_sdata = stime_tp - stime_tp.wday + booking.start_time.wday - if over_one_week && etime_tp.wday<=booking.start_time.wday + b_sdata_tp = stime_tp - stime_tp.wday.day + booking.start_time.wday.day + 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 end - b_edata_tp = b_sdata + (booking.end_time-booking.start_time).to_i.day - b_edata = "#{b_edata_tp.year}/#{b_edata_tp.month}/#{b_edata_tp.day} #{booking.end_time.hour}:#{booking.end_time.minute}".to_datetime + now_diff_day = etime_tp - stime_tp + 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 sdata = stime_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) available = false end + if !b_interval.blank? + puts '-------------' + puts booking.inspect + puts ['sdata',sdata,'b_sdata',b_sdata,'edata',edata,'b_edata',b_edata] + end end stime_tp = stime_tp + d_step etime_tp = etime_tp + d_step