Ticket #6242 (closed defect: fixed)
[patch][CLA]dojo.date.locale.parse fails for ddMMMyyyy (and variants)
| Reported by: | guest | Owned by: | peller |
|---|---|---|---|
| Priority: | normal | Milestone: | 1.2 |
| Component: | Date | Version: | 1.1b1 |
| Severity: | normal | Keywords: | |
| Cc: | seth@… |
Description (last modified by peller) (diff)
These will return null:
dojo.date.locale.parse("1Aug2006",{datePattern:"ddMMMyyyy",selector: "date",locale: "en" });
dojo.date.locale.parse("Aug2006",{datePattern:"MMMyyyy",selector: "date",locale: "en" });
yet these will return dates:
dojo.date.locale.parse("1 Aug 2006",{datePattern:"dd MMM yyyy",selector: "date",locale: "en" });
dojo.date.locale.parse("Aug 2006",{datePattern:"MMM yyyy",selector: "date",locale: "en" });
The problem is in the regular expression that is getting built up in dojo.date.locale.parse.
Here's a diff for a fix of dojo/date/locale.js:
Index: dojo/date/locale.js
===================================================================
--- dojo/date/locale.js (revision 13124)
+++ dojo/date/locale.js (working copy)
@@ -505,13 +505,13 @@
s = '\d{2,4}';
break;
case 'M':
- s = (l>2) ? '\S+' : p2+'[1-9]|1[0-2]';
+ s = (l>2) ? '\S+?' : p2+'[1-9]|1[0-2]';
break;
case 'D':
s = p2+'[1-9]|'+p3+'[1-9][0-9]|[12][0-9][0-9]|3[0-5][0-9]|36[0-6]';
break;
case 'd':
- s = p2+'[1-9]|[12]\d|3[01]';
+ s = '[12]\d|'+p2+'[1-9]|3[01]';
break;
case 'w':
s = p2+'[1-9]|[1-4][0-9]|5[0-3]';
And here's some tests to prove it works:
Index: dojo/tests/date/locale.js
===================================================================
--- dojo/tests/date/locale.js (revision 13124)
+++ dojo/tests/date/locale.js (working copy)
@@ -88,6 +88,10 @@
// ...but not in strict mode
t.f( Boolean(dojo.date.locale.parse("8/11/2006", {formatLength:'short', selector:'date', locale:'en', strict:true})));
+ // test dates with no spaces
+ t.is( aug_11_2006, dojo.date.locale.parse("11Aug2006",{selector: 'date',datePattern: 'ddMMMyyyy'}));
+ t.is( new Date(2006,07,1), dojo.date.locale.parse("Aug2006",{selector: 'date',datePattern: 'MMMyyyy'}));
+
//en: 'medium' fmt: MMM d, yyyy
// Tolerate either 8 or 08 for month part.
t.is( aug_11_2006, dojo.date.locale.parse("Aug 11, 2006", {formatLength:'medium', selector:'date', locale:'en'}));
My CLA is in the mail. Hope you don't mind the fix from some joker off the street.
Attachments
Change History
Note: See
TracTickets for help on using
tickets.