catch exception from unparsable date and display it empty instead

This commit is contained in:
Ralf Becker 2014-11-12 19:24:06 +00:00
parent 3db39c4130
commit 2961398a27

View File

@ -253,6 +253,7 @@ var et2_date = et2_inputWidget.extend(
// Handle just time as a string in the form H:i
if(typeof _value == 'string' && isNaN(_value))
{
try {
// silently fix skiped minutes or times with just one digit, as parser is quite pedantic ;-)
var fix_reg = new RegExp((this._type == "date-timeonly"?'^':' ')+'([0-9]+)(:[0-9]*)?( ?(a|p)m?)?$','i');
var matches = _value.match(fix_reg);
@ -327,6 +328,11 @@ var et2_date = et2_inputWidget.extend(
this.set_validation_error(false);
}
}
// catch exception from unparsable date and display it empty instead
catch(e) {
return this.set_value(null);
}
} else if (typeof _value == 'object' && _value.date) {
this.date = _value.date;
} else if (typeof _value == 'object' && _value.valueOf) {
@ -785,11 +791,17 @@ var et2_date_ro = et2_valueWidget.extend([et2_IDetachedDOM],
}
else if(typeof _value == 'string' && isNaN(_value))
{
try {
// parseDateTime to handle string PHP: DateTime local date/time format
var parsed = (typeof jQuery.datepicker.parseDateTime("yy-mm-dd","hh:mm:ss", _value) !='undefined')?
jQuery.datepicker.parseDateTime("yy-mm-dd","hh:mm:ss", _value):
jQuery.datepicker.parseDateTime(this.egw().preference('dateformat'),this.egw().preference('timeformat') == '24' ? 'H:i' : 'g:i a', _value);
}
// display unparsable dates as empty
catch(e) {
this.span.attr("datetime", "").text("");
return;
}
var text = new Date(parsed);
// Update local variable, but remove the timezone offset that javascript adds