Permalink
Browse files

Fixed date parsing of 31st dates when current month has 30 days (!!).

Patch from rich@tablexi.com. Fixed #2975.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@13713 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 037b579 commit 443cb9b6edb227211effcbc9e1534ee04a9579af @malcolmt malcolmt committed Sep 10, 2010
Showing with 13 additions and 7 deletions.
  1. +13 −7 django/contrib/admin/media/js/dateparse.js
@@ -100,37 +100,41 @@ var dateParsePatterns = [
{ re: /^(\d{1,2})(?:st|nd|rd|th)? (\w+)$/i,
handler: function(bits) {
var d = new Date();
- d.setDate(parseInt(bits[1], 10));
+ d.setDate(1);
d.setMonth(parseMonth(bits[2]));
+ d.setDate(parseInt(bits[1], 10));
return d;
}
},
// 4th Jan 2003
{ re: /^(\d{1,2})(?:st|nd|rd|th)? (\w+),? (\d{4})$/i,
handler: function(bits) {
var d = new Date();
- d.setDate(parseInt(bits[1], 10));
- d.setMonth(parseMonth(bits[2]));
+ d.setDate(1);
d.setYear(bits[3]);
+ d.setMonth(parseMonth(bits[2]));
+ d.setDate(parseInt(bits[1], 10));
return d;
}
},
// Jan 4th
{ re: /^(\w+) (\d{1,2})(?:st|nd|rd|th)?$/i,
handler: function(bits) {
var d = new Date();
- d.setDate(parseInt(bits[2], 10));
+ d.setDate(1);
d.setMonth(parseMonth(bits[1]));
+ d.setDate(parseInt(bits[2], 10));
return d;
}
},
// Jan 4th 2003
{ re: /^(\w+) (\d{1,2})(?:st|nd|rd|th)?,? (\d{4})$/i,
handler: function(bits) {
var d = new Date();
- d.setDate(parseInt(bits[2], 10));
- d.setMonth(parseMonth(bits[1]));
+ d.setDate(1);
d.setYear(bits[3]);
+ d.setMonth(parseMonth(bits[1]));
+ d.setDate(parseInt(bits[2], 10));
return d;
}
},
@@ -158,16 +162,18 @@ var dateParsePatterns = [
{ re: /(\d{1,2})\/(\d{1,2})\/(\d{4})/,
handler: function(bits) {
var d = new Date();
+ d.setDate(1);
d.setYear(bits[3]);
- d.setDate(parseInt(bits[2], 10));
d.setMonth(parseInt(bits[1], 10) - 1); // Because months indexed from 0
+ d.setDate(parseInt(bits[2], 10));
return d;
}
},
// yyyy-mm-dd (ISO style)
{ re: /(\d{4})-(\d{1,2})-(\d{1,2})/,
handler: function(bits) {
var d = new Date();
+ d.setDate(1);
d.setYear(parseInt(bits[1]));
d.setMonth(parseInt(bits[2], 10) - 1);
d.setDate(parseInt(bits[3], 10));

0 comments on commit 443cb9b

Please sign in to comment.