/** * Gets the date and time from a given $slug * * @param string $slug Slug to parse * @return int */ public static function getTimestamp($slug) { if (!preg_match(Pattern::DATE_OR_DATETIME, $slug, $matches) || !Pattern::isValidDate($matches[0])) { return FALSE; } $date_string = substr($matches[0], 0, 10); $delimiter = substr($date_string, 4, 1); $date_array = explode($delimiter, $date_string); // check to see if this is a full date and time $time_string = strlen($matches[0]) > 11 ? substr($matches[0], 11, 4) : '0000'; // construct the stringed time $date = $date_array[2] . '-' . $date_array[1] . '-' . $date_array[0]; $time = substr($time_string, 0, 2) . ":" . substr($time_string, 2); return strtotime("{$date} {$time}"); }
/** * is_valid_date * Determines if a given date or datetime represents a real date * * @deprecated Use Pattern::isValidDate() instead * * @param string $date A yyyy-mm-dd(-hhii)[-ish] formatted string for checking * @return boolean */ public static function is_valid_date($date) { Log::warn("Use of Statamic_Helper::is_valid_date() is deprecated. Use Pattern::isValidDate() instead.", "core", "Statamic_Helper"); return Pattern::isValidDate($date); }