Last active
October 1, 2018 17:20
-
-
Save flymio/06e7d4ea54be4b4736a205bf066f7b38 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Complete the timeConversion function below. | |
*/ | |
function timeConversion($s) { | |
if (preg_match('/(.+?)(\w{2})$/',$s, $matches)){ | |
$date = explode(":", $matches[1]); | |
if ($matches[2] == 'PM' && $date[0] < 12){ | |
$date[0]+=12; | |
} | |
if ($matches[2] == 'AM' && $date[0] == 12){ | |
$date[0]=0; | |
} | |
$date[0] = sprintf("%02d",$date[0]); | |
echo implode(':', $date); | |
return implode(':', $date); | |
} | |
} | |
$fptr = fopen(getenv("OUTPUT_PATH"), "w"); | |
$__fp = fopen("php://stdin", "r"); | |
fscanf($__fp, "%[^\n]", $s); | |
$result = timeConversion($s); | |
fwrite($fptr, $result . "\n"); | |
fclose($__fp); | |
fclose($fptr); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment