} if ($d === "decembre") { return 12; } return 0; } if ($argv[1] === NULL) { return; } $t = explode(' ', $argv[1]); $time = array_filter($t); if ($t != $time) { echo "Wrong Format\n"; return; } if (!to_day($time[0]) || !is_numeric($time[1]) || strlen($time[1]) > 2 || $time[1] > 31 || !is_numeric($time[3]) || strlen($time[3]) > 4 || $time[3] < 1970) { echo "Wrong Format\n"; return; } if (!month($time[2])) { echo "Wrong Format\n"; return; } $h = explode(":", $time[4]); $h2 = array_filter($h); if ($h != $h2) { echo "Wrong Format\n"; return; } foreach ($h as $elem) { if (!is_numeric($elem) || strlen($elem) != 2) {
/** * Checks if the specific datetime is a valid time to book, according to the days. * * @param $from * @param $to * @return bool */ public function isBookableTime($from, $to) { $from_time = to_time($from); $to_time = to_time($to); $day_from = to_day($from); $day_to = to_day($to); $date_from = to_date($from); $date_to = to_date($to); $query = $this->timetable->days(); if ($date_from == $date_to) { return $query->where('day', $day_to)->where('from', '<=', $from_time)->where('to', '>=', $to_time)->count() > 0; } else { $date1 = new DateTime($date_from); $date2 = new DateTime($date_to); $interval = $date1->diff($date2); $nb_days = $interval->days; if ($nb_days > 7) { $nb_days = 7; } $days = self::daysOfWeek(); $index = array_search($day_from, $days); return $query->where(function ($query) use($days, $index, $nb_days, $from_time, $to_time) { $query->orWhere(function ($query) use($days, $index, $from_time) { $query->where('day', $days[$index])->where('from', '<=', $from_time)->where('to', '24:00:00.0000'); }); for ($i = 1; $i < $nb_days; $i++) { $index++; $index = $index % 7; $query->orWhere(function ($query) use($days, $index) { $query->where('day', $days[$index])->where('from', '00:00:00.0000')->where('to', '24:00:00.0000'); }); } $index++; $index = $index % 7; $query->orWhere(function ($query) use($days, $index, $to_time) { $query->where('day', $days[$index])->where('from', '00:00:00.0000')->where('to', '>=', $to_time); }); })->count() == $nb_days + 1; } }