Created
September 1, 2015 09:52
-
-
Save jdhobbsuk/1e8305721296934d6a5f to your computer and use it in GitHub Desktop.
Format time with removal of 00 (on hour), and auto compile start / end time
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
// Format date to remove 00 with on-hour times | |
// ------------------------------------------------------------- | |
function mixd_format_time($time, $meridiem = false){ | |
$full_time = intval($time); | |
$time = str_split($time, 2); | |
$hour = date('g', mktime($time[0], 0, 0, 1, 1, 2000)); | |
$minute = $time[1]; | |
$day_split = ''; | |
if($meridiem): | |
$day_split = date('a', mktime($time[0], 0, 0, 1, 1, 2000)); | |
endif; | |
if($minute == '00'): | |
$time = $hour.$day_split; | |
else: | |
$time = $hour.':'.$minute.$day_split; | |
endif; | |
return $time; | |
} | |
// Compile Time | |
// ------------------------------------------------------------- | |
function mixd_compile_time($start_time, $finish_time, $separator = ' – '){ | |
if($start_time != ''): | |
if($start_time != '?'): | |
$start = mixd_format_time($start_time, true); | |
else: | |
$start = $start_time; | |
endif; | |
endif; | |
if($finish_time != ''): | |
if($finish_time != '?'): | |
$finish = mixd_format_time($finish_time, true); | |
else: | |
$finish = $finish_time; | |
endif; | |
endif; | |
if($start && $finish): | |
return $start.$separator.$finish; | |
else: | |
if($start): | |
return $start; | |
endif; | |
endif; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment