Bootstrap plug-in datetimepicker start month set bug

Time:2019-11-18

Download address of datetimepicker plug-in

The code is as follows:

//Date input box
$("input").datetimepicker({
    Format: 'yyyy mm', // date format is year month
    Startview: 3, // the starting page selects the page for the month
    Minview: 3, // the minimum page is the month selection page
    autoclose: true,
    language:'zh-CN'
});
$("input.dateStart").on("click",function(){
    //Set the date value of the next input box to the end date
    $(this).datetimepicker("setEndDate",$(this).next().val());
});
$("input.dateEnd").on("click",function(){
    //Set the date value of the previous input box to the start date
    $(this).datetimepicker("setStartDate",$(this).prev().val());
});

It is found in use that after setting the date in the start date input box and clicking the end date input box, the optional start month displayed is always two months later than the month in the open date input box. For example, the date in the start date input box is 2016-01, and the optional start month displayed in the end date period input box is March. But conversely, there is no problem with the optional end month in the start date input box. The preliminary judgment is that there is a problem in the statement of setting the start month.
Bootstrap plug-in datetimepicker start month set bug

Bootstrap plug-in datetimepicker start month set bug

Look at the source code and find out the reason. 630 lines of code should be minus 1, not plus 1

Bootstrap plug-in datetimepicker start month set bug

startYear = this.startDate !== -Infinity ? this.startDate.getUTCFullYear() : -Infinity,
//****************Bug lines**********************//
//startMonth = this.startDate !== -Infinity ? this.startDate.getUTCMonth() + 1 : -Infinity,
//******************Change to**********************//
startMonth = this.startDate !== -Infinity ? this.startDate.getUTCMonth() - 1 : -Infinity,
endYear = this.endDate !== Infinity ? this.endDate.getUTCFullYear() : Infinity,
endMonth = this.endDate !== Infinity ? this.endDate.getUTCMonth() + 1 : Infinity,

Normal after modification:
Bootstrap plug-in datetimepicker start month set bug