public static function getRemainingDaysQuiet($futureDate) { try { return getRemainingDays($futureDate); } catch (\InvalidArgumentException $e) { return $futureDate; } }
function isPastDate($date) { if (!($date = getSanitizedDate($date))) { throw new \InvalidArgumentException(sprintf('$date argument [%s] does not match correct format [%s]', $date, DATE_REGEX)); } if (getRemainingDays($date) < 0) { return true; } return false; }
$currentDate = DateTime::createFromFormat('Y-m-d', '2015-05-03'); $date = DateTime::createFromFormat('Y-m-d', $date); $remainingDays = $currentDate->diff($date)->days; if ($currentDate->diff($date)->invert) { $remainingDays *= -1; } return $remainingDays; } $page = intval($_GET['page']); $pageSize = intval($_GET['pageSize']); $pattern = "/\\[\\s*(?P<eventDate>(?:\\d{4}-\\d{2}-\\d{2})|(?:\\d{4}\\/\\d{2}\\/\\d{2})),\\s+(?P<hashtag>#[a-zA-Z.\\-]+),\\s+'(?P<eventName>.*?)',\\s+(?P<location>[a-zA-Z\\-,]+),\\s+(?P<totalTickets>\\d+),\\s+(?P<soldTickets>\\d+)\\s*\\]/"; preg_match_all($pattern, $_GET['conferences'], $conferences, PREG_SET_ORDER); foreach ($conferences as $index => $conference) { $conference['availableTickets'] = intval($conference['totalTickets']) - intval($conference['soldTickets']); $conference['eventDate'] = preg_replace('/\\//', '-', $conference['eventDate']); $conference['daysLeft'] = getRemainingDays($conference['eventDate']); $conferences[$index] = $conference; } uasort($conferences, function ($a, $b) { if ($a['eventDate'] === $b['eventDate']) { if ($a['location'] === $b['location']) { if ($a['availableTickets'] === $b['availableTickets']) { return strcmp($a['eventName'], $b['eventName']); } return $b['availableTickets'] - $a['availableTickets']; } return strcmp($a['location'], $b['location']); } return strcmp($b['eventDate'], $a['eventDate']); }); $conferences = array_slice($conferences, ($page - 1) * $pageSize, $pageSize);