WordPress.org

Ready to get started?Download WordPress

Forums

FT Calendar
[resolved] Recurring Event by Day is not working (11 posts)

  1. nshiflett
    Member
    Posted 3 years ago #

    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/

  2. Lew Ayotte
    Member
    Plugin Author

    Posted 3 years ago #

    Hi nshiflett,

    I'm looking into this...

  3. nshiflett
    Member
    Posted 3 years ago #

    Thank you!

  4. Lew Ayotte
    Member
    Plugin Author

    Posted 3 years ago #

    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.

  5. Lew Ayotte
    Member
    Plugin Author

    Posted 3 years ago #

    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;
  6. nshiflett
    Member
    Posted 3 years ago #

    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?

  7. nshiflett
    Member
    Posted 3 years ago #

    btw, thanks for the quick response on this!

  8. Lew Ayotte
    Member
    Plugin Author

    Posted 3 years ago #

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

  9. nshiflett
    Member
    Posted 3 years ago #

    sure thing, on it's way.

  10. Lew Ayotte
    Member
    Plugin Author

    Posted 3 years ago #

    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 :)

  11. nshiflett
    Member
    Posted 3 years ago #

    Thank you!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic