Date format

Home Forums Calendar Products Events Calendar PRO Date format

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #993161
    Lasse Johansson
    Participant

    Hi,

    I’m using the list-widget to show some events from a specific category. My wish is to only show the title and the date for the event. My question is if there is any function for show the date like this “10 – 12 august” instead of the default way “10 august – 12 august”. So, if the start and end date is in the same month I just want to show the month after the end date.

    #993250
    Brian
    Member

    Hi,

    Thanks for using our plugins. I can answer your questions.

    I played around with our settings and could not find an easy to way to do as you describe.

    The function used to show the Event Date and times there is used across all views of the site.

    You could replace that function in the template to do as you describe, but there is not much we can do to support a customization like that.

    I can try to answer some questions to help get you started if you like.

    Let me know.

    Thanks

    #993326
    Lasse Johansson
    Participant

    Hi,

    I have copied the widget files into my theme so I can customize the widget.

    So what can i replace the function with to get my wished result?

    #993427
    Brian
    Member

    Hi,

    I did some more digging when trying to help get you started on a custom function and found a filter to do as you ask instead of having to customize the function.

    Please add this to your theme’s functions.php:

    add_filter( 'tribe_format_second_date_in_range', 'tribe_restore_no_month_format', 10, 2 );
    function tribe_restore_no_month_format( $format, $event ) {
    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' ) ) {
    $format = 'j';
    }
    return $format;
    }

    That should then show only the date and not the month for the multiday events.

    Let me know if that works for you.

    Thanks

    #993440
    Lasse Johansson
    Participant

    It’s almost worked :/

    Now I get “27 september – 29”, but i wish to get “27 – 29 september”.

    #993580
    Brian
    Member

    Hello,

    That is all I have for you on this unfortunately.

    You can try creating your own function to modify the one that displays the date to get it exactly how you like.

    This is the function:

    tribe_events_event_schedule_details()

    This is what that function does:

    /**
    * Return the details of the start/end date/time.
    *
    * The highest level means of customizing this function's output is simply to adjust the date format settings under
    * Events > Settings > Display, and WordPress 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.
    *
    * "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.
    *
    * @category Events
    * @TODO use tribe_get_datetime_format() and related functions if possible
    *
    * @param int|null $event
    * @param string $before
    * @param string $after
    *
    * @return mixed|void
    */
    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 = '<span class="date-start dtstart">';
    $format = '';
    $date_without_year_format = tribe_get_date_format();
    $date_with_year_format = tribe_get_date_format( true );
    $time_format = get_option( 'time_format' );
    $datetime_separator = tribe_get_option( 'dateTimeSeparator', ' @ ' );
    $time_range_separator = tribe_get_option( 'timeRangeSeparator', ' - ' );
    $microformatStartFormat = tribe_get_start_date( $event, false, 'Y-m-dTh:i' );
    $microformatEndFormat = tribe_get_end_date( $event, false, 'Y-m-dTh:i' );

    $settings = array(
    '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 );

    $format = $date_with_year_format;

    // if 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 = $date_without_year_format;
    }

    if ( tribe_event_is_multiday( $event ) ) { // multi-date event

    $format2ndday = apply_filters( 'tribe_format_second_date_in_range', $format, $event );

    if ( tribe_event_is_all_day( $event ) ) {
    $schedule .= tribe_get_start_date( $event, true, $format );
    $schedule .= '<span class="value-title" title="' . $microformatStartFormat . '"></span>';
    $schedule .= '</span>' . $time_range_separator;
    $schedule .= '<span class="date-end dtend">';
    $schedule .= tribe_get_end_date( $event, true, $format2ndday );
    $schedule .= '<span class="value-title" title="' . $microformatEndFormat . '"></span>';
    } else {
    $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>' . $time_range_separator;
    $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>';
    }
    } elseif ( tribe_event_is_all_day( $event ) ) { // all day event
    $schedule .= tribe_get_start_date( $event, true, $format );
    $schedule .= '<span class="value-title" title="' . $microformatStartFormat . '"></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 .= 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>';
    } else { // defined start/end time
    $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 ? $time_range_separator : '' );
    $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>';

    $schedule = $before . $schedule . $after;

    return apply_filters( 'tribe_events_event_schedule_details', $schedule, $event->ID );
    }

    You can rename that function and add it to a custom plugin or your theme’s functions.php.

    Beyond providing that I am not able to help out much more on this customization.

    Thanks

    #997572
    Support Droid
    Keymaster

    This topic has not been active for quite some time and will now be closed.

    If you still need assistance please simply open a new topic (linking to this one if necessary)
    and one of the team will be only too happy to help.

Viewing 7 posts - 1 through 7 (of 7 total)
  • The topic ‘Date format’ is closed to new replies.