/** * Return the details of the start/end date/time. * * The highest level means of customizing this function's output is simply to adjust the WordPress date and time * formats (via the General Settings admin screen). Beyond that however there are two filters which can be used to * exercise further control here. * * The first is 'tribe_events_event_schedule_details_formatting' which allows an array of format settings to be * altered - it's basic make-up is as a simple set of key:value pairs as follows. * * "datetime_separator": this is inserted between the date and the time and defaults to an ampersat @ character. * Note that if you modify this you should ordinarily be careful to include leading and trailing spaces (an * example might be ' at '). * * "same_year_format": if an event starts and ends in the same year it's assumed that including the year in the * output is superfluous. That being the case the function changes the date format, by default, to 'F j'. This * may not be ideal in all locales so an alternative can be provided here. Do note that this substitution is * only ever made if A) the event starts and ends in the same year and B) the date format does not include any * time formatting characters. * * This can also effectively be used to turn off the assumption that the year should be omitted, simply by * setting it to the value of the 'date_format' option, for example. * * "show_end_time": for single day events only (not including all day events) it may not always be desirable to * include the end time. In that situation, this setting can be set to false and the end time will not be * displayed. * * "time": if it is undesirable to show times and only dates should be displayed then this setting can be set to * false. If it is false it will by extension cause 'show_end_time' to be false. * * The resulting string can also be caught and manipulated, or completely overridden, using the * 'tribe_events_event_schedule_details' filter, should none of the above settings be sufficient. * * @since 3.0 * @param int|null $event * @return string */ function tribe_events_event_schedule_details($event = null, $before = '', $after = '') { if (is_null($event)) { global $post; $event = $post; } if (is_numeric($event)) { $event = get_post($event); } $schedule = ''; $format = ''; $date_format = get_option('date_format'); $time_format = get_option('time_format'); $microformatStartFormat = tribe_get_start_date($event, false, 'Y-m-dTh:i'); $microformatEndFormat = tribe_get_end_date($event, false, 'Y-m-dTh:i'); $settings = array('datetime_separator' => ' @ ', 'same_year_format' => 'F j', 'show_end_time' => true, 'time' => true); $settings = wp_parse_args(apply_filters('tribe_events_event_schedule_details_formatting', $settings), $settings); if (!$settings['time']) { $settings['show_end_time'] = false; } extract($settings); // If the date format will result in the year being shown but does *not* include any time formatting... if (TribeDateUtils::formatContainsYear($date_format) && !TribeDateUtils::formatContainsTime($date_format)) { // ... and it starts and ends in the current year then there is no need to display the year if (tribe_get_start_date($event, false, 'Y') === date('Y') && tribe_get_end_date($event, false, 'Y') === date('Y')) { $format = $same_year_format; } } if (tribe_event_is_multiday($event)) { // multi-date event $format2ndday = $format; // If the WordPress date setting matches DATEONLYFORMAT, make the string more readable if (get_option('date_format') == TribeDateUtils::DATEONLYFORMAT) { //If it's all day and the end date is in the same month and year, just show the day. if (tribe_event_is_all_day($event) && tribe_get_end_date($event, false, 'm') === tribe_get_start_date($event, false, 'm') && tribe_get_end_date($event, false, 'Y') === date('Y')) { $format2ndday = 'j'; } } if (tribe_event_is_all_day($event)) { // If the multi-day event begins and ends in the same month, just show the month once. if (tribe_get_end_date($event, false, 'm') === tribe_get_start_date($event, false, 'm') && tribe_get_end_date($event, false, 'Y') === date('Y')) { $schedule .= '<span class="date-start dtstart">'; $schedule .= tribe_get_start_date($event, true, $format); $schedule .= '<span class="value-title" title="' . $microformatStartFormat . '"></span>'; $schedule .= '</span> - '; $schedule .= '<span class="date-end dtend">'; $schedule .= tribe_get_end_date($event, true, $format2ndday); $schedule .= '<span class="value-title" title="' . $microformatEndFormat . '"></span>'; $schedule .= '</span>'; } else { $schedule .= '<span class="date-start dtstart">'; $schedule .= tribe_get_start_date($event, true, $format); $schedule .= '<span class="value-title" title="' . $microformatStartFormat . '"></span>'; $schedule .= '</span> - '; $schedule .= '<span class="date-end dtend">'; $schedule .= tribe_get_end_date($event, true, $format2ndday); $schedule .= '<span class="value-title" title="' . $microformatEndFormat . '"></span>'; $schedule .= '</span>'; } } else { $schedule .= '<span class="date-start dtstart">'; $schedule .= tribe_get_start_date($event, false, $format) . ($time ? $datetime_separator . tribe_get_start_date($event, false, $time_format) : ''); $schedule .= '<span class="value-title" title="' . $microformatStartFormat . '"></span>'; $schedule .= '</span> - '; $schedule .= '<span class="date-end dtend">'; $schedule .= tribe_get_end_date($event, false, $format2ndday) . ($time ? $datetime_separator . tribe_get_end_date($event, false, $time_format) : ''); $schedule .= '<span class="value-title" title="' . $microformatEndFormat . '"></span>'; $schedule .= '</span>'; } } elseif (tribe_event_is_all_day($event)) { // all day event $schedule .= '<span class="date-start dtstart">'; $schedule .= tribe_get_start_date($event, true, $format); $schedule .= '<span class="value-title" title="' . $microformatStartFormat . '"></span>'; $schedule .= '</span>'; } else { // single day event if (tribe_get_start_date($event, false, 'g:i A') === tribe_get_end_date($event, false, 'g:i A')) { // Same start/end time $schedule .= '<span class="date-start dtstart">'; $schedule .= tribe_get_start_date($event, false, $format) . ($time ? $datetime_separator . tribe_get_start_date($event, false, $time_format) : ''); $schedule .= '<span class="value-title" title="' . $microformatStartFormat . '"></span>'; $schedule .= '</span>'; } else { // defined start/end time $schedule .= '<span class="date-start dtstart">'; $schedule .= tribe_get_start_date($event, false, $format) . ($time ? $datetime_separator . tribe_get_start_date($event, false, $time_format) : ''); $schedule .= '<span class="value-title" title="' . $microformatStartFormat . '"></span>'; $schedule .= '</span>' . ($show_end_time ? ' - ' : ''); $schedule .= '<span class="end-time dtend">'; $schedule .= ($show_end_time ? tribe_get_end_date($event, false, $time_format) : '') . '<span class="value-title" title="' . $microformatEndFormat . '"></span>'; $schedule .= '</span>'; } } if (!empty($schedule)) { $schedule = $before . $schedule . $after; } return apply_filters('tribe_events_event_schedule_details', $schedule); }