Opened 12 years ago

Closed 11 years ago

#6242 closed defect (fixed)

[patch][CLA]dojo.date.locale.parse fails for ddMMMyyyy (and variants)

Reported by: guest Owned by: Adam Peller
Priority: high Milestone: 1.2
Component: Date Version: 1.1b1
Keywords: Cc: seth@…
Blocked By: Blocking:

Description (last modified by Adam Peller)

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 (1)

bug6242.diff (1.4 KB) - added by guest 12 years ago.

Download all attachments as: .zip

Change History (5)

Changed 12 years ago by guest

Attachment: bug6242.diff added

comment:1 Changed 12 years ago by Adam Peller

Milestone: 1.2

comment:2 Changed 12 years ago by Adam Peller

Summary: dojo.date.locale.parse fails for ddMMMyyyy (and variants)[patch]dojo.date.locale.parse fails for ddMMMyyyy (and variants)

comment:3 Changed 12 years ago by Dustin Machi

Summary: [patch]dojo.date.locale.parse fails for ddMMMyyyy (and variants)[patch][CLA]dojo.date.locale.parse fails for ddMMMyyyy (and variants)

comment:4 Changed 11 years ago by Adam Peller

Description: modified (diff)
Resolution: fixed
Status: newclosed

fixed in [13541]

Note: See TracTickets for help on using tickets.