DatePicker widget pick the wrong date when near the change of year
------------------------------------------------------------------

                 Key: WW-2915
                 URL: https://issues.apache.org/struts/browse/WW-2915
             Project: Struts 2
          Issue Type: Bug
          Components: Plugin - Dojo Tags
    Affects Versions: 2.0.14, 2.1.3
         Environment: Verified on Tomcat 6.x using any browser on any platform
            Reporter: Nicolò D'Ercole
            Priority: Minor


The DatePicker dojo widget pick the wrong date when the month selected is 
January or December and the user click on a date outside of the month.
Using the DropdownDatePicker the error is easily noticeable.

Example 1: Select the month December 2008, then, without changing the selected 
month, choose one of the first days of January: the date visualized will be 
somewhere in November 2008.
Example 2: Select the month January 2009, then, without changing the selected 
month, choose one ot the last days of December: the date visualized will be 
atound March 2009.

I verified the problem lies on the DatePicker.js inside 
org/apache/struts2/static/dojo/src/widget at the line 243 (on Struts 2.0.14).
The line is:
 var curClass = 
((nextDate.getMonth()<this.curMonth.getMonth())?'previous':(nextDate.getMonth()==this.curMonth.getMonth())?'current':'next';
which obviously assign the wrong style when you select January or December.

I also verified that on Struts 2.1.3 that same line is
var curClass = ((nextDate.getMonth()<this.curMonth.getMonth() && 
Number(nextDate) < 
Number(this.curMonth))?'previous':(nextDate.getMonth()==this.curMonth.getMonth())?'current':'next';
which fix the thing when you select December but not when you select January.

My proposed solution for that line would be something like
var curClass = (((nextDate.getMonth()<this.curMonth.getMonth() && 
Number(nextDate) < Number(this.curMonth)) || (nextDate.getMonth() - 10 > 
this.curMonth.getMonth()))?'previous':(nextDate.getMonth()==this.curMonth.getMonth())?'current':'next';
which fix both the problems with January and December.

Let me know if I have not been clear enough and if you need other explanation 
or information.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to