#1855 closed defect (fixed)
DatePicker year rollover bug
Reported by: | guest | Owned by: | tk |
---|---|---|---|
Priority: | high | Milestone: | 0.9 |
Component: | General | Version: | 0.4 |
Keywords: | Cc: | ||
Blocked By: | Blocking: |
Description (last modified by )
From the _initUI method of DatePicker?.js
Clicking on date in January whilst viewing month of December causes DatePicker? to jump back to November
The following line clearly doesn't handle the case of nextDate being in January (month = 0) and curMonth being December (month == 11)
var curClass = (nextDate.getMonth()<this.curMonth.getMonth())?'previous':(nextDate.getMonth()==this.curMonth.getMonth())?'current':'next';
Fix is to replace above line with the following
var myMonth = nextDate.getMonth(); var curMonth = this.curMonth.getMonth(); var curClass = (myMonth==curMonth)?'current':(myMonth==0 && curMonth==11)?'next':(myMonth<curMonth)?'previous':'next';
Change History (5)
comment:1 Changed 14 years ago by
Description: | modified (diff) |
---|---|
Milestone: | → 0.5 |
Owner: | changed from anonymous to tk |
comment:2 Changed 14 years ago by
Status: | new → assigned |
---|
comment:3 Changed 14 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
(In [6881]) Fixes #1855 and fixes #1856, Datepicker now appends a djDateValue attribute to the calendar nodes so that it can track dates without using a formula. previous/current/next attributes are now determined by the following forumula: var curClass = (nextDate.getMonth() != this.curMonth.getMonth() && Number(nextDate) < Number(this.curMonth))?'previous':(nextDate.getMonth()==this.curMonth.getMonth())?'current':'next';
Basically if the months dont equal, and nextDate is less than curDate its the previous month, otherwise if they are equal its the current month, and if neither, then its the next month.
comment:4 Changed 14 years ago by
The above fix doesn't work for December dates in January. I did this (before noting ktiedt's fix).
var myMonth = nextDate.getMonth(); var curMonth = this.curMonth.getMonth(); var curClass = (myMonth==curMonth)?'current':(myMonth==0 && curMonth==11)?'next':(myMonth==11 && curMonth==0)?'previous':(myMonth<curMonth)?'previous':'next';
comment:5 Changed 14 years ago by
You are saying my above fix doesnt work? I tested it, it works perfectly... the reason is if 11 != 1 and (we're using timestamps now so...) 1234 < 1235 then 1234 is previous month and 1235 is curMonth same goes for January in December... timestamps are *always* incremental so January dates regardless of the year rollover are always higher than December dates of the previous year.
This fix doesnt completely fix the problem, and since the person who submitted it will not come forward with a name or anything to verify a CLA from, this fix cannot be applied....
A rewrite of the UI to data relation implementation will be required to fix this bug from what I can tell at this point.