Skip to content

Instantly share code, notes, and snippets.

@flymio
Last active October 1, 2018 17:20
Show Gist options
  • Save flymio/06e7d4ea54be4b4736a205bf066f7b38 to your computer and use it in GitHub Desktop.
Save flymio/06e7d4ea54be4b4736a205bf066f7b38 to your computer and use it in GitHub Desktop.
<?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