Example #1
0
/**
 * Return the duration of an event
 *
 * @since 0.1.5
 *
 * @param  mixed $post
 *
 * @return string
 */
function wp_get_event_duration($post = false)
{
    // Get the post object & start date
    $post = get_post($post);
    $all_day = (bool) get_post_meta($post->ID, 'wp_event_calendar_all_day', true);
    $start_date = strtotime(get_post_meta($post->ID, 'wp_event_calendar_date_time', true));
    $end_date = strtotime(get_post_meta($post->ID, 'wp_event_calendar_end_date_time', true));
    // Start an output buffer
    ob_start();
    // All day event
    if (true === $all_day) {
        // 1 day
        if (date('d', $start_date) === date('d', $end_date)) {
            esc_html_e('All Day', 'wp-event-calendar');
            // More than 1 day
        } else {
            echo wp_event_calendar_human_diff_time(strtotime('midnight', $start_date), strtotime('midnight', $end_date));
        }
        // Specific times
    } else {
        echo wp_event_calendar_human_diff_time($start_date, $end_date);
    }
    // Get the output buffer
    $retval = ob_get_clean();
    // Filter & return
    return apply_filters('wp_get_event_end_date_time', $retval, $post, $all_day, $start_date, $end_date);
}
/**
 * Return the duration of an event
 *
 * @since 0.1.5
 *
 * @param  mixed $post
 *
 * @return string
 */
function wp_get_event_duration($post = false)
{
    // Get the post object & start date
    $post = get_post($post);
    $all_day = get_post_meta($post->ID, 'wp_event_calendar_all_day', true);
    $start_date = get_post_meta($post->ID, 'wp_event_calendar_date_time', true);
    $end_date = get_post_meta($post->ID, 'wp_event_calendar_end_date_time', true);
    $human_time = wp_event_calendar_human_diff_time($start_date, $end_date);
    // Start an output buffer
    ob_start();
    // All day event
    if (!empty($all_day)) {
        // 1 day
        if ($start_date === $end_date) {
            esc_html_e('All Day', 'wp-event-calendar');
            // More than 1 day
        } else {
            echo $human_time;
        }
        // Specific times
    } else {
        // No duration to calculate
        if (empty($start_date) || empty($end_date) || $start_date === $end_date) {
            echo '—';
            // Some odd duration
        } else {
            echo $human_time;
        }
    }
    // Get the output buffer
    $retval = ob_get_clean();
    // Filter & return
    return apply_filters('wp_get_event_end_date_time', $retval, $post, $all_day, $start_date, $end_date);
}