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
This commit is contained in:
Malcolm Tredinnick 2010-09-10 18:09:18 +00:00
parent 037b579b5e
commit 443cb9b6ed
1 changed files with 13 additions and 7 deletions

View File

@ -100,8 +100,9 @@ var dateParsePatterns = [
{ re: /^(\d{1,2})(?:st|nd|rd|th)? (\w+)$/i, { re: /^(\d{1,2})(?:st|nd|rd|th)? (\w+)$/i,
handler: function(bits) { handler: function(bits) {
var d = new Date(); var d = new Date();
d.setDate(parseInt(bits[1], 10)); d.setDate(1);
d.setMonth(parseMonth(bits[2])); d.setMonth(parseMonth(bits[2]));
d.setDate(parseInt(bits[1], 10));
return d; return d;
} }
}, },
@ -109,9 +110,10 @@ var dateParsePatterns = [
{ re: /^(\d{1,2})(?:st|nd|rd|th)? (\w+),? (\d{4})$/i, { re: /^(\d{1,2})(?:st|nd|rd|th)? (\w+),? (\d{4})$/i,
handler: function(bits) { handler: function(bits) {
var d = new Date(); var d = new Date();
d.setDate(parseInt(bits[1], 10)); d.setDate(1);
d.setMonth(parseMonth(bits[2]));
d.setYear(bits[3]); d.setYear(bits[3]);
d.setMonth(parseMonth(bits[2]));
d.setDate(parseInt(bits[1], 10));
return d; return d;
} }
}, },
@ -119,8 +121,9 @@ var dateParsePatterns = [
{ re: /^(\w+) (\d{1,2})(?:st|nd|rd|th)?$/i, { re: /^(\w+) (\d{1,2})(?:st|nd|rd|th)?$/i,
handler: function(bits) { handler: function(bits) {
var d = new Date(); var d = new Date();
d.setDate(parseInt(bits[2], 10)); d.setDate(1);
d.setMonth(parseMonth(bits[1])); d.setMonth(parseMonth(bits[1]));
d.setDate(parseInt(bits[2], 10));
return d; return d;
} }
}, },
@ -128,9 +131,10 @@ var dateParsePatterns = [
{ re: /^(\w+) (\d{1,2})(?:st|nd|rd|th)?,? (\d{4})$/i, { re: /^(\w+) (\d{1,2})(?:st|nd|rd|th)?,? (\d{4})$/i,
handler: function(bits) { handler: function(bits) {
var d = new Date(); var d = new Date();
d.setDate(parseInt(bits[2], 10)); d.setDate(1);
d.setMonth(parseMonth(bits[1]));
d.setYear(bits[3]); d.setYear(bits[3]);
d.setMonth(parseMonth(bits[1]));
d.setDate(parseInt(bits[2], 10));
return d; return d;
} }
}, },
@ -158,9 +162,10 @@ var dateParsePatterns = [
{ re: /(\d{1,2})\/(\d{1,2})\/(\d{4})/, { re: /(\d{1,2})\/(\d{1,2})\/(\d{4})/,
handler: function(bits) { handler: function(bits) {
var d = new Date(); var d = new Date();
d.setDate(1);
d.setYear(bits[3]); d.setYear(bits[3]);
d.setDate(parseInt(bits[2], 10));
d.setMonth(parseInt(bits[1], 10) - 1); // Because months indexed from 0 d.setMonth(parseInt(bits[1], 10) - 1); // Because months indexed from 0
d.setDate(parseInt(bits[2], 10));
return d; return d;
} }
}, },
@ -168,6 +173,7 @@ var dateParsePatterns = [
{ re: /(\d{4})-(\d{1,2})-(\d{1,2})/, { re: /(\d{4})-(\d{1,2})-(\d{1,2})/,
handler: function(bits) { handler: function(bits) {
var d = new Date(); var d = new Date();
d.setDate(1);
d.setYear(parseInt(bits[1])); d.setYear(parseInt(bits[1]));
d.setMonth(parseInt(bits[2], 10) - 1); d.setMonth(parseInt(bits[2], 10) - 1);
d.setDate(parseInt(bits[3], 10)); d.setDate(parseInt(bits[3], 10));