| Issue 79: | DatePicker bugs with %d/%m/%y format (Year 09) | |
| 1 person starred this issue and may be notified of changes. | Back to list |
This is the case
<form>
<table>
<tr>
<td>Date input 2 (dd/mm/yy): </td>
<td>
<input type=\"text\" name=\"date\" value=\"\" id=\"my_date\"/>
<script type=\"text/javascript\">
new DatePicker('my_date', {
format: '%d/%m/%y'
});
</script>
</td>
</tr>
</table>
</form>
The first click is ok, you see on the top of The Datepicker "February
2009".
Datepicker return "19/02/09" (Great).
But...
But if you click again you see the Year "February 9" on the top and
Datepicker return me "19/02/" (No Great).
How to solve:
You can see the problem (format year wrong with %d/%m/%y) when
Datepicker works with $parsePatterns (we use Date.$culture="GB").
In this case if you use
format: '%a, %m %d %y' // Mon, Jan 01 07 (This is ok, not use
$parsePatterns)
In this case if you use
format: '%d/%m/%y' // 24/02/09 (This is not ok, this use
$parsePatterns)
So i solve this problem with a little code
in the $parsePatterns.
This is the patch code:
if(d.get('year') < 100 ){
d.increment('year', 2000);
}
Here we go... with the code:
$parsePatterns: [
{
//"12.31.08", "12-31-08", "12/31/08", "12.31.2008", "12-31-2008",
"12/31/2008"
re: /^(\d{1,2})[\.\-\/](\d{1,2})[\.\-\/](\d{2,4})$/,
handler: function(bits){
var d = new Date();
var culture = Date.$cultures[Date.$culture];
d.set('year' , bits[Date.$cIndex('year')]);
// Patch Begin
if(d.get('year') < 100 ){
d.increment('year', 2000);
}
// Patch End
d.set('date' , bits[Date.$cIndex('date')]);
d.set('month', bits[Date.$cIndex('month')] - 1);
return Date.fixY2K(d);
}
},
|
|
,
Mar 02, 2009
This not work on month != February 2009.
This seem a bugs of d.increment.
I don't Know why but if your system's date is
on feb 2009 d.increment('year', 2000);
-->d.increment return 09 + 2000 = 2009 [ok this work well]
But
on mar 2009 d.increment('year', 2000);
-->d.increment return 09 + 2000 = 2007 [ko no good]
So try to solve whit this code and it's work:
{
//"12.31.08", "12-31-08", "12/31/08", "12.31.2008", "12-31-2008", "12/31/2008"
re: /^(\d{1,2})[\.\-\/](\d{1,2})[\.\-\/](\d{2,4})$/,
handler: function(bits){
var d = new Date();
var culture = Date.$cultures[Date.$culture];
// criscd begin
if( bits[Date.$cIndex('year')] < 100){
d.set('year' , '20' + bits[Date.$cIndex('year')]);
} else {
d.set('year' , bits[Date.$cIndex('year')] );
}
// criscd end
d.set('date' , bits[Date.$cIndex('date')]);
d.set('month', bits[Date.$cIndex('month')] - 1);
return Date.fixY2K(d);
}
},
|
|
,
Mar 18, 2009
There are actually a few bugs involved with this ticket.
#1:
The class does not adjust for the culture correctly.
DatePicker.clickCalendar function, first line:
if(this.options.format == "%d/%m/%Y") Date.$culture = "GB";
Should be:
if(this.options.format.contains('%d/%m')) Date.$culture = "GB";
As long as the day comes before the month, the culture should be European, even the
format chosen is %X%d%m. [In this ticket, the person was using: "%d/%m/%y", which
did not match. ]
|
|
,
Mar 18, 2009
#2:
The Date.fixY2K() function does not handle two digit dates at all.
Where it says:
if (newDate.get('year') < 2000 && d.toString().indexOf(newDate.get('year')) < 0) {
newDate.increment('year', 100);
}
It should really be something like:
var yr = newDate.get('year') < 2000;
if(yr < 2000) new Date.set('year', (yr < 45 ? 2000 : 1900)+yr);
a) I did not understand the second condition you had, and it did not affect my tests.
Add it back.
b) I switched to "set" instead of "increment" as increment is a relatively expensive
function [there is no need to test for a leap year 2000 times], and is not needed
here. Increment is where a person is adding a year. Here, we don't need to add 2000
years to the year 0014 - we need to start with the year 2014!
c) I assume that 45 is a good turnover date for a two digit year to be past 2000
#3:
Christian refers to a bug with increment in which it drops a day for every leap year,
and falls a month when using increment over 1000 years.
a)I did not use increment [so it does not affect this issue]
b) do not understand why when you increment the year you adjust for leap years
Once the above two changes are made, this issue is solved.
|
|
,
May 07, 2009
All tickets are now on github: http://github.com/anutron/clientcide/issues/
Status: WontFix
|
|
|
|