/** * Builds a set of options for displaying an hour chooser * @param string the current date (optional) * @return string a set of HTML options with hours (current hour selected) */ public static function getHourOptions($date = "", $isStart = false) { $hours = TribeEventsViewHelpers::hours(); if (count($hours) == 12) { $h = 'h'; } else { $h = 'H'; } $options = ''; if (empty($date)) { $hour = $isStart ? '08' : (count($hours) == 12 ? '05' : '17'); } else { $timestamp = strtotime($date); $hour = date($h, $timestamp); // fix hours if time_format has changed from what is saved if (preg_match('(pm|PM)', $timestamp) && $h == 'H') { $hour = $hour + 12; } if ($hour > 12 && $h == 'h') { $hour = $hour - 12; } } foreach ($hours as $hourText) { if ($hour == $hourText) { $selected = 'selected="selected"'; } else { $selected = ''; } $options .= "<option value='{$hourText}' {$selected}>{$hourText}</option>\n"; } return $options; }