Here’s the story:
I created a drop-down calendar control for a website I’m helping to build at work. The website needs to work not only with American date formats, but in British, French, Italian, German and Spanish formats as well, including a format which includes the three-letter abbreviation for the month (e.g., 31-Dec-2007). The Date.parse function built into the browser cannot parse this particular format, so I was hoping to leverage the localization features of the AJAX Extensions library. However, I kept getting an error at a function called “Sys$CultureInfo$_getAbbrMonthIndex”, deep in the bowels of the library. Here’s the entire function (line breaks added):
function Sys$CultureInfo$_getAbbrMonthIndex(value) {
if (!this._upperAbbrMonths) {
this._upperAbbrMonths = this._toUpperArray(
this.dateTimeFormat.AbbreviatedMonthNames);
}
return Array.indexOf(this._upperMonths,
this._toUpper(value));
}
Can you spot the error? Hello!? It populates an array called _upperAbbrMonths, then promptly looks for an entry in the _upperMonths array. Suffice it to say, if that particular field has not been defined yet, you get a variable undefined error. I fixed it by registering a startup script in our base Page class with the following script:
Sys.CultureInfo.prototype._getAbbrMonthIndex = function(value)
{
if (!this._upperAbbrMonths) {
this._upperAbbrMonths = this._toUpperArray(
this.dateTimeFormat.AbbreviatedMonthNames);
}
return Array.indexOf(this._upperAbbrMonths,
this._toUpper(value));
};
That fixes the bug. The interesting this is that this bug is “fixed” according to MS, because the new version of the library produced in .NET 3.5 has it fixed. Of course, if you’re stuck in .NET 2.0, you’re SOL.
