Open GoogleCodeExporter opened 8 years ago
have u solved it kelvin?
Original comment by fulus.in...@gmail.com
on 19 Apr 2010 at 6:59
Hi Kevin,
Great work on the date picker, I think I may have a fix for this issue. The
issue is in the Date.fromString function. We need to set the returned date in
the following order: year, month, and date to account for 29 Feb in leap years.
Hope this helps
Tony
Date.fromString = function(s)
{
var f = Date.format;
var d = new Date('01/01/1970');
if (s == '') return d;
s = s.toLowerCase();
var matcher = '';
var order = [];
var r = /(dd?d?|mm?m?|yy?yy?)+([^(m|d|y)])?/g;
var results;
while ((results = r.exec(f)) != null)
{
switch (results[1]) {
case 'd':
case 'dd':
case 'm':
case 'mm':
case 'yy':
case 'yyyy':
matcher += '(\\d+\\d?\\d?\\d?)+';
order.push(results[1].substr(0, 1));
break;
case 'mmm':
matcher += '([a-z]{3})';
order.push('M');
break;
}
if (results[2]) {
matcher += results[2];
}
}
var dm = new RegExp(matcher);
var result = s.match(dm);
var resYear, resMonth, resDate;
for (var i=0; i<order.length; i++) {
var res = result[i+1];
switch(order[i]) {
case 'd':
resDate = res;
break;
case 'm':
resMonth = Number(res)-1;
break;
case 'M':
for (var j=0; j<Date.abbrMonthNames.length; j++) {
if (Date.abbrMonthNames[j].toLowerCase() == res) break;
}
resMonth = j;
break;
case 'y':
resYear = res;
break;
}
}
// We need to set in this order to make sure 29 Feb in leap years are accounted for
if(resYear) d.setYear(resYear);
if(resMonth) d.setMonth(resMonth);
if(resDate) d.setDate(resDate);
return d;
};
Original comment by mrwo...@gmail.com
on 8 Apr 2011 at 3:44
Thanks, this seemed to work for me!
Original comment by marcus.f...@gmail.com
on 9 Jun 2011 at 9:21
Issue 132 has been merged into this issue.
Original comment by kelvin.l...@gmail.com
on 9 Jun 2011 at 9:32
Issue 307 has been merged into this issue.
Original comment by kelvin.l...@gmail.com
on 21 Sep 2011 at 8:09
Thanks, this code works for me!
Original comment by mohammad...@kritnu.com
on 3 Feb 2012 at 10:43
Any chance of adding this fix to the copy held in SVN
Original comment by hubme...@gmail.com
on 4 Feb 2012 at 7:06
Issue 338 has been merged into this issue.
Original comment by kelvin.l...@gmail.com
on 21 Feb 2012 at 9:15
Thank~
Original comment by elf.engl...@gmail.com
on 23 Feb 2012 at 4:53
Thx!
Works just fine!
Original comment by vincent....@gmail.com
on 27 Feb 2012 at 9:16
Thanks! Works for me too.
Original comment by peter.ag...@gmail.com
on 28 Feb 2012 at 3:30
Thank you very much. This works for me too.
Original comment by bila...@gmail.com
on 8 Mar 2012 at 8:31
Original issue reported on code.google.com by
kelvin.l...@gmail.com
on 15 Apr 2010 at 9:51