From afa62d1d67e828b9e69940bacf31d02aad647993 Mon Sep 17 00:00:00 2001 From: chiu Date: Wed, 3 Jun 2020 21:05:49 +0800 Subject: [PATCH] fix erorr --- app/helpers/admin/property_hires_helper.rb | 18 +++++++++++++++--- app/models/property.rb | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app/helpers/admin/property_hires_helper.rb b/app/helpers/admin/property_hires_helper.rb index cb29814..098d7c3 100644 --- a/app/helpers/admin/property_hires_helper.rb +++ b/app/helpers/admin/property_hires_helper.rb @@ -3,9 +3,21 @@ module Admin::PropertyHiresHelper def check_for_availability(stime, etime, pid, interval=nil, recurring_end_date=nil) property = Property.find(pid) return {"success" => false, "msg" => "Values are not ok."} if property.nil? || stime.blank? || etime.blank? - stime = DateTime.parse(stime + Time.zone.to_s) rescue nil - etime = DateTime.parse(etime + Time.zone.to_s) rescue nil - recurring_end_date = DateTime.parse(recurring_end_date + Time.zone.to_s) rescue nil + if !stime.blank? + stime = DateTime.parse(stime + Time.zone.to_s) rescue nil + else + stime = nil + end + if !etime.blank? + etime = DateTime.parse(etime + Time.zone.to_s) rescue nil + else + etime = nil + end + if !recurring_end_date.blank? + recurring_end_date = DateTime.parse(recurring_end_date + Time.zone.to_s) rescue nil + else + recurring_end_date = nil + end data = {} return {"success" => false, "msg" => "Starting time cannot be greater than ending time."} if stime > etime if property.is_available_for_hire?(stime, etime) diff --git a/app/models/property.rb b/app/models/property.rb index 534d106..393ed16 100644 --- a/app/models/property.rb +++ b/app/models/property.rb @@ -146,7 +146,7 @@ class Property end stime_tp = stime_tp + d_step etime_tp = etime_tp + d_step - break if recurring_end_date.blank? || recurring_end_date < stime_tp + break if recurring_end_date.blank? || d_step==0 || recurring_end_date < stime_tp end break if available == false end