From e977c0cf1fbb4252f19c28f1537e89af75f0d5b9 Mon Sep 17 00:00:00 2001 From: Nimako Date: Fri, 3 May 2019 16:10:28 +0000 Subject: [PATCH 1/3] Class updated --- booking.php | 109 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 101 insertions(+), 8 deletions(-) diff --git a/booking.php b/booking.php index 2013a02..6ae739c 100644 --- a/booking.php +++ b/booking.php @@ -3,43 +3,135 @@ // . interface BookingStructure { - private function bookASlot($from, $to); + public function bookASlot($from, $to); } class Booking implements BookingStructure { + + private $from; + private $to; + + private $maxMinute = 120; + private $minMinute = 30; + + private $closingTime; + private $openingTime; + + private $response = ""; + private $bookedSlots = [ ['from'=>'8:00', 'to'=>'9:30'] ]; - public function _construct($openingTime, $closingTime) + + public function __construct($openingTime, $closingTime) { - //add code here + $this->openingTime = $openingTime; + $this->closingTime = $closingTime; } public function getAllBookings() { - // add code here + return $this->bookedSlots; } - public function bookASlot() + public function bookASlot($from, $to) { - //add code here + + $this->from = $from; + $this->to = $to; + + $from_hour = $from_minute = 0; + list($from_hour, $from_minute) = explode(':', $from); + + $to_hour = $to_minute = 0; + list($to_hour, $to_minute) = explode(':', $to); + + $booked_from_hour = $booked_from_minute = 0; + list($booked_from_hour, $booked_from_minute) = explode(':',$this->bookedSlots[0]['from']); + + $booked_to_hour = $booked_to_minute = 0; + list($booked_to_hour, $booked_to_minute) = explode(':',$this->bookedSlots[0]['to']); + + $booking_hours_from_minute= $this->convertHoursToMinutes($this->from); + $booking_hours_to_minute= $this->convertHoursToMinutes($this->to); + + $bookin_minutes_difference = $booking_hours_to_minute - $booking_hours_from_minute; + + $booking_hour_difference = $to_hour - $booked_from_hour; + + $closingTimeHourTo = explode(':',$this->closingTime)['0']; + $openingTimeHourFrom = explode(':',$this->openingTime)['0']; + + $booked_from = $this->bookedSlots[0]["from"]; + $booked_to = $this->bookedSlots[0]["to"]; + + $this->response= ($to_hour <= $booked_to_hour)?'Sorry there is a meeting from {booked_from} & {$booked_to} ':""; + + + if($bookin_minutes_difference===0 || $bookin_minutes_difference <$this->minMinute){ + + $this->response = "Sorry you can't book less than a 30 min slot
"; + + } + if($booking_hour_difference>2 && $to_hour<=$closingTimeHourTo) { + + $this->response = "Sorry you can't book above a 2 hour slot
"; + + } + + if($to_hour>$closingTimeHourTo){ + + $this->response = "Sorry you can't book outside of the closing time
"; + + } + + if(empty($this->response)){ + + $this->bookedSlots = [ + ['from' => $this->from, + 'to' => $this->to] + ]; + return $this->bookedSlots; + }else{ + + return $this->response; + } + } public function getOpeningTime() { - // add code here + return $this->openingTime; } public function getClosingTime() { - // add code here + return $this->closingTime; } + + + public function convertHoursToMinutes($time){ + + $minute = 0; + $time = explode(":", $time); + + $hours = $time[0]; + if(!empty($time[1])) { + $m = $time[1]; + }else{ + $minute = "00"; + } + $mm = ($hours * 60)+$minute; + return $mm; + } + } + /* Test Cases */ $bookingInstance = new Booking("6:30", "18:00"); var_dump($bookingInstance->getAllBookings()); // array(1) { [0]=> array(2) { ["from"]=> string(4) "8:00" ["to"]=> string(4) "9:30" } } @@ -52,3 +144,4 @@ public function getClosingTime() var_dump($bookingInstance->getClosingTime()); // string(5) "18:00" var_dump($bookingInstance->getAllBookings()); // array(2) { [0]=> array(2) { ["from"]=> string(4) "8:00" ["to"]=> string(4) "9:30" } [1]=> array(2) { ["from"]=> string(5) "12:00" ["to"]=> string(5) "12:15" } } + From c4285e5b5ad40f0a0613ffad1adb3b2558088aaa Mon Sep 17 00:00:00 2001 From: Nimako Date: Fri, 3 May 2019 16:27:08 +0000 Subject: [PATCH 2/3] Booking Class updated --- booking.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/booking.php b/booking.php index 6ae739c..2e23d63 100644 --- a/booking.php +++ b/booking.php @@ -23,7 +23,6 @@ class Booking implements BookingStructure private $bookedSlots = [ ['from'=>'8:00', 'to'=>'9:30'] - ]; public function __construct($openingTime, $closingTime) @@ -49,7 +48,7 @@ public function bookASlot($from, $to) $to_hour = $to_minute = 0; list($to_hour, $to_minute) = explode(':', $to); - $booked_from_hour = $booked_from_minute = 0; + $booked_from_hour = $booked_from_minute = 0; list($booked_from_hour, $booked_from_minute) = explode(':',$this->bookedSlots[0]['from']); $booked_to_hour = $booked_to_minute = 0; @@ -115,16 +114,16 @@ public function getClosingTime() public function convertHoursToMinutes($time){ - $minute = 0; + $minutes = 0; $time = explode(":", $time); $hours = $time[0]; if(!empty($time[1])) { $m = $time[1]; }else{ - $minute = "00"; + $minutes = "00"; } - $mm = ($hours * 60)+$minute; + $mm = ($hours * 60)+$minutes; return $mm; } From 813c750748901a437a14f4d4c645ae072912b093 Mon Sep 17 00:00:00 2001 From: Nimako Date: Mon, 6 May 2019 18:02:07 +0000 Subject: [PATCH 3/3] Name and Email added --- booking.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/booking.php b/booking.php index 2e23d63..0d0d092 100644 --- a/booking.php +++ b/booking.php @@ -1,6 +1,6 @@ . +// . interface BookingStructure { public function bookASlot($from, $to);