I'm trying to receive data from input that I changed from "text" to the "time" selector. Now when the data goes in, it's generating the following error listed below. I understand why this is happening, but don't know where and how to change the code so that the code can process the PHP "time" input.
Error:
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (013:59) at position 0 (0): Unexpected character' in C:\xampp\htdocs\index.php:240 Stack trace: #0 C:\xampp\htdocs\index.php(240): DateTime->__construct('013:59') #1 C:\xampp\htdocs\index.php(84): format_time('13:59') #2 {main} thrown in C:\xampp\htdocs\index.php on line 240
Relevant Code:
if($to){
$s = (int)format_time($start);
$e = (int)format_time($end);
function ct($time){
$timezone_offset = 14400000; //EST vs UTC in ms
return new MongoDB\BSON\UTCDateTime(strtotime($time)*1000 + $timezone_offset);
}
function now_in_mongo($offset = 0){
return new MongoDB\BSON\UTCDateTime(time()*1000 + $offset*1000);
}
function format_time($time){
if(strlen($time) != 6){
$time = "0$time";
}
$date = new DateTime($time);
$date->add(new DateInterval('PT4H'));
return $date->format('His');
}