The fix is to change things like this:<p><pre><code> targetEndDate = new Date();
targetEndDate.setFullYear( endDate.getFullYear() );
targetEndDate.setMonth( endDate.getMonth() );
targetEndDate.setDate( endDate.getDate() );
</code></pre>
to<p><pre><code> targetEndDate = new Date();
targetEndDate.setFullYear(
endDate.getFullYear(),
endDate.getMonth(),
endDate.getDate());
</code></pre>
That works because setFullYear has a three argument form that takes the year, month, and date avoiding the inconsistency that can arise by setting those one at a time.<p>But you know what else has a three argument for that take the year, month, and date? The Date constructor.<p>So why not fix it like this?<p><pre><code> targetEndDate = new Date(
endDate.getFullYear(),
endDate.getMonth(),
endDate.getDate());
</code></pre>
Using the empty constructor would initial the object with the current date and time, but they promptly overwrite those.<p>The Date construction also has a form that takes another Date object, so I wonder if they could have simple used:<p><pre><code> targetEndDate = new Date(endDate);</code></pre>