Support » Plugin: Schedule Posts Calendar » Today-Button wrong month

  • Resolved garee

    (@garee)


    The Today-Button sets the wrong month: instead of the actual month (february) it sets the date to 1 (january). The javascript-method getMonth() returns values from 0 to 11. So I fixed the problem by adding 1 to the month in scp_calendar_today() in schedule-posts-calendar.js:


    var sMon = new String(currentDate.getMonth()+1);

    https://wordpress.org/plugins/schedule-posts-calendar/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Greg Ross

    (@gregross)

    It’s a little more complicated than that as we need the zero based index when selectedIndex is used later on.

    Try the following:

    function scp_calendar_today()
    	{
    	var currentDate = new Date();
    
    	SchedulePostsCalendar.setDate(currentDate);
    
    	var sDay = new String(currentDate.getDate());
    	var sMon = new String(currentDate.getMonth());
    	var sMonReal = new String(currentDate.getMonth()+1);
    	var sYear = new String(currentDate.getFullYear());
    	var sHour = new String(currentDate.getHours());
    	var sMin = new String(currentDate.getMinutes());
    
    	var dateString = '';
    	if( sDay.length < 2 ) { sDay = '0' + sDay; }
    	dateString += sDay + '/';
    	if( sMonReal.length < 2 ) { sMonReal = '0' + sMonReal; }
    	dateString += sMonReal + '/' + sYear + ' ';
    	if( sHour.length < 2 ) { sHour = '0' + sHour; }
    	dateString += sHour + ':';
    	if( sMin.length < 2 ) { sMin = '0' + sMin; }
    	dateString += sMin;
    
    	document.getElementById('mm').selectedIndex = sMon;
    	document.getElementById('jj').value = sDay;
    	document.getElementById('aa').value = sYear;
    	document.getElementById('hh').value = sHour;
    	document.getElementById('mn').value = sMin;
    
    	document.getElementById('calendarHere').value = dateString;
    	}

    Thanks, that works!

    Plugin Author Greg Ross

    (@gregross)

    What browser are you running?

    Chrome and Safari on OSX. I get the wrong month only when the popup-calendar is enabled in settings. With the collapsible version everything is fine.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Today-Button wrong month’ is closed to new replies.