JosephMajaseSithole / datejs

Automatically exported from code.google.com/p/datejs
0 stars 0 forks source link

[FIXED] Date.parseExact() with four character day or month (MMMM | dddd) #1

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Date.parseExact('July 2004', 'MMMM yyyy') // [FAIL]

Improperly returns null.

Same problem when using four character day specifier ('dddd') in .parseExact().

Original issue reported on code.google.com by geoff%co...@gtempaccount.com on 12 Nov 2007 at 12:46

GoogleCodeExporter commented 8 years ago
Fixed. 

Within g.format, modified regex to include four character day and month format
specifiers. 

// Old
_.rtoken(/^(dd?d?|MM?M?|yy?y?y?|hh?|HH?|mm?|ss?|tt?|zz?z?)/), 

// New
_.rtoken(/^(dd?d?d?|MM?M?M?|yy?y?y?|hh?|HH?|mm?|ss?|tt?|zz?z?)/), 

Also had to add a g.dddd and g.MMMM token. 

// Old
g.ddd = _.cache(_.process(g.ctoken("sun mon tue wed thu fri sat"), 

// New 
g.ddd = g.dddd = _.cache(_.process(g.ctoken("sun mon tue wed thu fri sat"),

Also modified the day to default to '1' instead of the current date. 

Example

// If today is 13-Nov-2007

// Old
"July 2004" // 13-Jul-2004

// New
"July 2004" // 1-Jul-2004

All (100%) of the current .parseExact() tests are passing.

Original comment by geoff%co...@gtempaccount.com on 13 Nov 2007 at 10:21