function parse($dt) { if (is_a($dt, 'PHPRPC_Date')) { return $dt; } if (is_int($dt)) { return new PHPRPC_Date($dt); } $shortFormat = '(\\d|\\d{2}|\\d{3}|\\d{4})-([1-9]|0[1-9]|1[012])-([1-9]|0[1-9]|[12]\\d|3[01])'; if (preg_match("/^{$shortFormat}\$/", $dt, $match)) { $year = intval($match[1]); $month = intval($match[2]); $day = intval($match[3]); if (PHPRPC_Date::isValidDate($year, $month, $day)) { $date = new PHPRPC_Date(false); $date->year = $year; $date->month = $month; $date->day = $day; return $date; } else { return false; } } $longFormat = $shortFormat . ' (\\d|0\\d|1\\d|2[0-3]):(\\d|[0-5]\\d):(\\d|[0-5]\\d)'; if (preg_match("/^{$longFormat}\$/", $dt, $match)) { $year = intval($match[1]); $month = intval($match[2]); $day = intval($match[3]); if (PHPRPC_Date::isValidDate($year, $month, $day)) { $date = new PHPRPC_Date(false); $date->year = $year; $date->month = $month; $date->day = $day; $date->hour = intval($match[4]); $date->minute = intval($match[5]); $date->second = intval($match[6]); return $date; } else { return false; } } $fullFormat = $longFormat . '\\.(\\d|\\d{2}|\\d{3})'; if (preg_match("/^{$fullFormat}\$/", $dt, $match)) { $year = intval($match[1]); $month = intval($match[2]); $day = intval($match[3]); if (PHPRPC_Date::isValidDate($year, $month, $day)) { $date = new PHPRPC_Date(false); $date->year = $year; $date->month = $month; $date->day = $day; $date->hour = intval($match[4]); $date->minute = intval($match[5]); $date->second = intval($match[6]); $date->millisecond = intval($match[7]); return $date; } else { return false; } } return false; }
function today() { $date = PHPRPC_Date::now(); $date->hour = 0; $date->minute = 0; $date->second = 0; return $date; }