Support » Plugin: FT Calendar » [Plugin: FT Calendar] Recurring Event by Day is not working

  • Resolved nshiflett

    (@nshiflett)


    I’ve created an event that takes place on the first Wednesday of every month, beginning on the Apr. 6, 2011. However, when I view May, June, etc the recurring event is using the 6th day of the month instead of the first Wednesday of every month. Is there anything that I can do to correct this? Thank you.

    http://wordpress.org/extend/plugins/ft-calendar/

Viewing 10 replies - 1 through 10 (of 10 total)
  • Lew Ayotte

    (@layotte)

    Hi nshiflett,

    I’m looking into this…

    nshiflett

    (@nshiflett)

    Thank you!

    Lew Ayotte

    (@layotte)

    I have a fix for you, but it is kind of complicated…

    In /classes/class-shortcodes.php, add this at line 1214:

    function get_nth_weekday_of_month( $strdate ) {
    
    	$englishnumber = array(
    						'first',
    						'second',
    						'third',
    						'fourth',
    						'fifth'
    					);
    
    	$date = date_i18n( 'j', $strdate );
    	$day = date_i18n( 'w', $strdate ) + 1;
    	$firstday = date_i18n( 'w', strtotime( date_i18n( 'Y-m-1', $strdate ) ) ) + 1;
    
    	for ( $i = 0; $i <= 5; $i++ ) {
    
    		if ( ( $day + ( 7 * $i ) ) >= $date ) {
    
    			if ( $day < $firstday ) {
    
    				$i--;
    
    			}
    
    			return $englishnumber[$i];
    
    		}
    
    	}
    
    	return false;
    
    }

    Again, in /classes/class-shortcodes.php, replace lines 1111-1130 with this:

    case 'monthly' :
    	$s_y = date_i18n( 'Y', $str_rsdate * 86400 );
    	$s_m = date_i18n( 'n', $str_rsdate * 86400 );
    	$c_y = date_i18n( 'Y', $strdate );
    	$c_m = date_i18n( 'n', $strdate );
    
    	$month_diff = ( $c_y - $s_y ) * 12 + ( $c_m - $s_m );
    
    	if ( 0 == $month_diff % $cal_data->r_every ) {
    		if ( 0 == $cal_data->r_by ) { // by day of month
    			if ( date_i18n( 'd', $strdate ) == date_i18n( 'd', strtotime( $cal_data->r_start_datetime ) ) ) {
    				$cal_entries[date_i18n( 'Y-m-d', $strdate )][$rstime][] = $cal_data->id;
    			}
    		} else { // by day of week
    			$dom = $this->get_nth_weekday_of_month( strtotime( $cal_data->r_start_datetime ) );
    			$cdom = $this->get_nth_weekday_of_month( $strdate );
    			if ( date_i18n( 'D', $strdate ) == date_i18n( 'D', strtotime( $cal_data->r_start_datetime ) )
    					&& $dom == $cdom ) {
    				$cal_entries[date_i18n( 'Y-m-d', $strdate )][$rstime][] = $cal_data->id;
    			}
    		}
    	}
    	break;

    Then in /includes/js/write-edit-post.js, replace line 291 with:

    r_by: $('input.repeats_by:selected').val(),

    I will be adding this to the next release.

    Lew Ayotte

    (@layotte)

    Whoops,

    that second code snippet should have been this:

    case 'monthly' :
    	$s_y = date_i18n( 'Y', $str_rsdate * 86400 );
    	$s_m = date_i18n( 'n', $str_rsdate * 86400 );
    	$c_y = date_i18n( 'Y', $strdate );
    	$c_m = date_i18n( 'n', $strdate );
    
    	$month_diff = ( $c_y - $s_y ) * 12 + ( $c_m - $s_m );
    
    	if ( 0 == $month_diff % $cal_data->r_every ) {
    		if ( 0 == $cal_data->r_by ) { // by day of month
    			if ( date_i18n( 'd', $strdate ) == date_i18n( 'd', strtotime( $cal_data->r_start_datetime ) ) ) {
    				$cal_entries[date_i18n( 'Y-m-d', $strdate )][$rstime][] = $cal_data->id;
    			}
    		} else { // by day of week
    			$dom = $this->get_nth_weekday_of_month( strtotime( $cal_data->r_start_datetime ) );
    			$cdom = $this->get_nth_weekday_of_month( $strdate );
    			if ( date_i18n( 'D', $strdate ) == date_i18n( 'D', strtotime( $cal_data->r_start_datetime ) )
    					&& $dom == $cdom ) {
    				$cal_entries[date_i18n( 'Y-m-d', $strdate )][$rstime][] = $cal_data->id;
    			}
    		}
    	}
    	break;
    nshiflett

    (@nshiflett)

    No luck, I applied the recommended corrections and I’ve recreated the recurring event and still get the same results. Would you like me to paste the code here?

    nshiflett

    (@nshiflett)

    btw, thanks for the quick response on this!

    Lew Ayotte

    (@layotte)

    Can you email me your site and administrator credentials so I can take a peak? info -at- calendar-plugin.com

    nshiflett

    (@nshiflett)

    sure thing, on it’s way.

    Lew Ayotte

    (@layotte)

    Ok, that is weird… the JS code I pasted above should have been this:

    r_by: $('input.repeats_by:checked').val(),

    Not sure how “checked” got turned into “selected” above… but anyway, I updated your JS file. It seems to be working now… you may need to refresh your browser cache to get the new JS changes.

    I set the event to:
    April 6, 2011 5:30 pm to April 6, 2011 7:30 pm
    (Repeating Monthly on the first Wednesday of the month)

    But I can’t remember if that is what it should have been 🙂

    nshiflett

    (@nshiflett)

    Thank you!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘[Plugin: FT Calendar] Recurring Event by Day is not working’ is closed to new replies.