PDA

View Full Version : [FIXED-1475] DateField.safeParse and 'c' or 'U' format



Condor
26 Dec 2010, 11:44 PM
DateField.safeParse determines if it should parse the time based on the format string containing 'g', 'G', 'h' or 'H', but it should also check for 'c' and 'U', because these formats contain time too.
And to be complete, we should probably also add 'i', 's' and 'u'.


Ext.override(Ext.form.DateField, }
safeParse : function(value, format) {
if (/[gGhHisucU]/.test(format.replace(/(\\.)/g, ''))) {
return Date.parseDate(value, format);
} else {
var parsedDate = Date.parseDate(value + ' ' + this.initTime, format + ' ' + this.initTimeFormat);
if (parsedDate) {
return parsedDate.clearTime();
}
}
}
});

meroy
29 Dec 2010, 12:40 PM
Which Ext release or SVN revision were you overriding above?

Condor
30 Dec 2010, 12:15 AM
Ah, it was already fixed in rev. 7321 (4 days before my post!).

I do however don't like the current formatContainsHourInfo code:

Date.formatContainsHourInfo = function(format){
var hourFormats = ['c', 'U', 'O', 'P', 'Z', 'M$']
if (hourFormats.indexOf(format) > -1) {
return true;
}
return /[gGhH]/.test(format.replace(/(\\.)/g, ''));
};
It doesn't detect 'O', 'P' or 'Z' as part of a dateFormat.

IMHO it should be:

Date.formatContainsHourInfo = (function(){
var stripEscapeRe = /(\\.)/g,
hourInfoRe = /([gGhHisucUOPZ]|M$)/;
return function(format){
return hourInfoRe.test(format.replace(stripEscapeRe, ''));
};
})();
(including regexp caching)

meroy
30 Dec 2010, 10:42 AM
Doesn't M$ require the backslash here as it's part of the regex string?



Date.formatContainsHourInfo = (function(){
var stripEscapeRe = /(\\.)/g,
hourInfoRe = /([gGhHisucUOPZ]|M\$)/;
return function(format){
return hourInfoRe.test(format.replace(stripEscapeRe, ''));
};
})();

Condor
3 Jan 2011, 7:53 AM
Doesn't M$ require the backslash here as it's part of the regex string?

Completely correct. I forgot that $ is the EOL indicator in a RegExp.

meroy
4 Jan 2011, 10:47 AM
The fix has been applied to SVN (3.3.x branch). Thanks Condor.