Date Display: If Month = Month

Home Forums Calendar Products Events Calendar PRO Date Display: If Month = Month

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #1161639
    leviticus
    Participant

    I am using a modified version of the code found on https://theeventscalendar.com/support/forums/topic/remove-times-from-event-schedule-details-function/ to alter the date display.

    I’m curious if there is a way to have the date display differently if multi-day events have the same month (ex: October 1 – 5, 2016) than multi-day events that have different months (ex: October 28 – November 3, 2016).

    Here’s what I have so far:

    
    /**
     * Modifies tribe_events_event_schedule_details format
     *
     * @param string $schedule  the output HTML
     * @param int    $event_id  post ID of the event we are interested in
     * @param string $before    part of the HTML wrapper that was prepended
     * @param string $after     part of the HTML wrapper that was appended
     */
    function tribe_events_event_schedule_details_custom ( $schedule, $event_id = null, $before = '', $after = '' ) {
    
       $inner                    = '<span class="tribe-event-date-start">';
       $format                   = 'F j, Y';
       $time_format              = get_option( 'time_format' );
       $datetime_separator       = tribe_get_option( 'dateTimeSeparator', ' @ ' );
       $time_range_separator     = tribe_get_option( 'timeRangeSeparator', ' - ' );
    
       $settings = array(
          'show_end_time' => false,
          'time'          => false,
       );
    
       /**
        * @var $show_end_time
        * @var $time
        */
    
       if ( tribe_event_is_multiday( $event_id ) ) { // multi-date event
    
       extract( $settings );
          $format2ndday = apply_filters( 'tribe_format_second_date_in_range', $format, $event_id );
    
          if ( tribe_event_is_all_day( $event_id ) ) {
             $inner .= tribe_get_start_date( $event_id, true, 'F j' );
             $inner .= '</span>' . $time_range_separator;
             $inner .= '<span class="tribe-event-date-end">';
    
             $end_date_full = tribe_get_end_date( $event_id, true, Tribe__Date_Utils::DBDATETIMEFORMAT );
             $end_date_full_timestamp = strtotime( $end_date_full );
    
             // if the end date is <= the beginning of the day, consider it the previous day
             if ( $end_date_full_timestamp <= strtotime( tribe_beginning_of_day( $end_date_full ) ) ) {
                $end_date = tribe_format_date( $end_date_full_timestamp - DAY_IN_SECONDS, false, $format2ndday );
             } else {
                $end_date = tribe_get_end_date( $event_id, false, $format2ndday );
             }
    
             $inner .= $end_date;
          } else {
             $inner .= tribe_get_start_date( $event_id, false, 'F j' ) . ( $time ? $datetime_separator . tribe_get_start_date( $event_id, false, $time_format ) : '' );
             $inner .= '</span>' . $time_range_separator;
             $inner .= '<span class="tribe-event-date-end">';
             
    		 $start_month = tribe_get_start_date($event_id, true, 'm');
    		 $end_month = tribe_get_end_date($event_id, true, 'm');
    		 
    		 if ( $start_month = $end_month ) {
    			 $inner .= tribe_get_end_date( $event_id, false, ' j, Y' );
    		 } else {
    			 $inner .= tribe_get_end_date( $event_id, false, $format2ndday ) . ( $time ? $datetime_separator . tribe_get_end_date( $event_id, false, $time_format ) : '' );
    		 }
    		 
    	  }
       } elseif ( tribe_event_is_all_day( $event_id ) ) { // all day event
          $inner .= tribe_get_start_date( $event_id, true, $format );
       } else { // single day event   
       
             $inner .= tribe_get_start_date( $event_id, true, $format ) . '</span>';
             $inner .= '<span class="time">' . tribe_get_start_date( $event_id, true, 'g:i a' );
             $inner .= ' - ';
             $inner .= tribe_get_end_date( $event_id, true, 'g:i a' );
       }
    
       $inner .= '</span>';
    
       /**
        * Provides an opportunity to modify the *inner* schedule details HTML (ie before it is
        * wrapped).
        *
        * @param string $inner_html  the output HTML
        * @param int    $event_id    post ID of the event we are interested in
        */
       $inner = apply_filters( 'tribe_events_event_schedule_details_inner', $inner, $event_id->ID );
    
       // Wrap the schedule text
       $schedule = $before . $inner . $after;
    
       return $schedule;
    
    }
    add_filter( 'tribe_events_event_schedule_details', 'tribe_events_event_schedule_details_custom', 10, 4 );
    
    #1161778
    Andras
    Keymaster

    Hello leviticus and thanks for reaching out!

    I think you are on the right track. In the middle though I see that a comparison is using ‘=’  instead of ‘==’.

    if ( $start_month = $end_month ) {

    should be

    if ( $start_month == $end_month ) {

    Try and let me know if that solves it.

    Cheers,
    Andras

    #1164076
    leviticus
    Participant

    This reply is private.

    • This reply was modified 7 years, 7 months ago by leviticus.
    #1164078
    leviticus
    Participant

    I think that did the trick. Thanks for you help!

    #1164201
    Andras
    Keymaster

    Hey there leviticus,

    Thanks for reporting back on that! I’m super happy to hear it helped and you are one step closer to the perfect website!

    I am going to close this ticket, but if you need anything else related to this topic or another please start a new thread in the forum and we’ll help you out.

    Cheers,
    Andras

    PS: We’d be grateful if you could give us feedback on your satisfaction with support. Just click on one of the classy looking emojis below. 🙂 If you can spare a few words, that’s even better. Thanks!

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Date Display: If Month = Month’ is closed to new replies.