Opened 13 years ago

Closed 12 years ago

Last modified 12 years ago

#2729 closed defect (fixed)

dojo.date.format module, function dojo.date.parse: problem with abbrev. month names

Reported by: guest Owned by: Adam Peller
Priority: high Milestone: 1.0
Component: Date Version: 0.4.2
Keywords: Cc:
Blocked By: Blocking:

Description

I found something of a problem with the dojo.date.parse function when trying to parse a submitted value which had just been generated by the dojo.date.format function. In other words, I took the default value generated by dojo.date.format() for a 'dateOnly', medium 'formatLength' date object and send it back to be parsed by dojo.date.parse(). It would seem that what comes out from dojo.date.format as a localized default should be parsable by dojo.date.parse as a localized default. And this is true for the 'en' localization. When I try 'fr', it doesn't work, giving a debug message of --Could not parse month name: 'avr'.-- for avril (April) in French.

The debug message is telling in that it should be 'avr.' and is not getting the period at the end of the abbreviation. So I looked around in the dojo.date.parse function and found this:

case "M":

if (l > 2) {

if (!options.strict) {

v = v.replace(/./g, "");

v = v.toLowerCase();

}

blah..blah

The v = v.replace(/./g, ""); line is removing the period so that later on, it never matches. This was a problem for me since most of the values my users will submit are those generated earlier by my little calendar script via dojo.date.format().

The quick fix is to remove the above line, but I wouldn't presume to know why that line was there in the first place or what might be the best coarse of action to fix the problem. Without that line, everything works fine for me. As far as I can tell, the intent was to make the parse function less restrictive.

Here is the full case "M" of the dojo.date.parse function:

case "M":

if (l > 2) {

if (!options.strict) {

v = v.replace(/./g, "");

v = v.toLowerCase();

} var months = info+ widthList[l - 3?].concat(); for (var j = 0; j < months.length; j++) {

if (!options.strict) {

months[j] = months[j].toLowerCase();

} if (v == months[j]) {

result.setMonth(j); expected.month = j; break;

}

} if (j == months.length) {

dojo.debug("dojo.date.parse: Could not parse month name: '" + v + "'."); return null;

}

} else {

result.setMonth(v - 1); expected.month = v - 1;

} break;

I commented out the line in question. Different browsers obviously all worked the same and I am using the latest build (0.4.2) of dojo.

Thanks in advance

dojo user -> dwight

Change History (4)

comment:1 Changed 13 years ago by Adam Peller

Owner: changed from anonymous to Adam Peller

comment:2 Changed 13 years ago by Adam Peller

Component: GeneralDate
Milestone: 1.0
Type: enhancementdefect

comment:3 Changed 12 years ago by Adam Peller

Resolution: fixed
Status: newclosed

(In [8725]) Replace for loops with dojo.forEach to reduce code. Fix non-strict comparison for month parsing. Fixes #2729

comment:4 Changed 12 years ago by Adam Peller

Resolution: fixed

(In [8748]) Fixes IE regression. Fixes #2729

Note: See TracTickets for help on using tickets.