From e86bd439dbf69d64f846ff4bb9eafa9565ff2b5e Mon Sep 17 00:00:00 2001 From: Shreesh Arora Date: Mon, 23 Sep 2024 17:18:21 +0530 Subject: [PATCH] update date diff function --- .../classes/HotelCartBookingData.php | 8 ++++---- .../classes/HotelHelper.php | 16 ++++------------ 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/modules/hotelreservationsystem/classes/HotelCartBookingData.php b/modules/hotelreservationsystem/classes/HotelCartBookingData.php index e906d64cc..2a3bb3e5b 100644 --- a/modules/hotelreservationsystem/classes/HotelCartBookingData.php +++ b/modules/hotelreservationsystem/classes/HotelCartBookingData.php @@ -1379,7 +1379,7 @@ class HotelCartBookingData extends ObjectModel (Group::isFeatureActive() ? ' INNER JOIN `'._DB_PREFIX_.'htl_room_type_feature_pricing_group` fpg ON (fp.`id_feature_price` = fpg.`id_feature_price` AND fpg.`id_group` = '.(int) $id_group.')' : '').' WHERE fp.`id_cart` = 0 AND fp.`id_product`='.(int) $id_product.' AND fp.`active`=1 - AND fp.`date_selection_type` = '.(int) HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_SPECIFIC.' AND fp.`date_from` = DATE_FORMAT(\''.pSQL($date).'\', "%Y-%m-%d")' + AND fp.`date_selection_type` = '.(int) HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_SPECIFIC.' AND fp.`date_from` = \''.pSQL($date).'\'' )) { return $featurePrice; } @@ -1389,8 +1389,8 @@ class HotelCartBookingData extends ObjectModel (Group::isFeatureActive() ? ' INNER JOIN `'._DB_PREFIX_.'htl_room_type_feature_pricing_group` fpg ON (fp.`id_feature_price` = fpg.`id_feature_price` AND fpg.`id_group` = '.(int) $id_group.')' : '').' WHERE fp.`id_cart` = 0 AND fp.`id_product`='.(int) $id_product.' - AND fp.`is_special_days_exists`=1 AND fp.`active`=1 AND fp.`date_from` <= DATE_FORMAT(\''.pSQL($date).'\', "%Y-%m-%d") - AND fp.`date_to` >= DATE_FORMAT(\''.pSQL($date).'\', "%Y-%m-%d")' + AND fp.`is_special_days_exists`=1 AND fp.`active`=1 AND fp.`date_from` <= \''.pSQL($date).'\' + AND fp.`date_to` >= \''.pSQL($date).'\'' )) { foreach ($featurePrice as $fRow) { $specialDays = json_decode($fRow['special_days']); @@ -1406,7 +1406,7 @@ class HotelCartBookingData extends ObjectModel ON (fp.`id_feature_price` = fpg.`id_feature_price` AND fpg.`id_group` = '.(int) $id_group.')' : '').' WHERE fp.`id_cart` = 0 AND fp.`id_product`='.(int) $id_product.' AND fp.`date_selection_type` = '.(int) HotelRoomTypeFeaturePricing::DATE_SELECTION_TYPE_RANGE.' AND `is_special_days_exists`=0 AND `active`=1 - AND fp.`date_from` <= DATE_FORMAT(\''.pSQL($date).'\', "%Y-%m-%d") AND fp.`date_to` >= DATE_FORMAT(\''.pSQL($date).'\', "%Y-%m-%d")' + AND fp.`date_from` <= \''.pSQL($date).'\' AND fp.`date_to` >= \''.pSQL($date).'\'' )) { return $featurePrice; } diff --git a/modules/hotelreservationsystem/classes/HotelHelper.php b/modules/hotelreservationsystem/classes/HotelHelper.php index 3baf27a58..dc442e32d 100644 --- a/modules/hotelreservationsystem/classes/HotelHelper.php +++ b/modules/hotelreservationsystem/classes/HotelHelper.php @@ -2492,21 +2492,13 @@ class HotelHelper return false; } - /** - * This function returns the number of days between two dates. If same date is passed, it returns the hourly difference - */ public static function getNumberOfDays($dateFrom, $dateTo) { - $start = new DateTime($dateFrom); - $end = new DateTime($dateTo); - $difference = $start->diff($end); - if ($start->format('Y-m-d') == $end->format('Y-m-d')) { - $diff = $difference->h; - } else { - $diff = $difference->days; - } + $startDate = new DateTime($dateFrom); + $endDate = new DateTime($dateTo); + $daysDifference = $startDate->diff($endDate)->days; - return $diff; + return $daysDifference; } public static function validateDateRangeForHotel($dateFrom, $dateTo, $idHotel)