BUG 11865 Problema con los campos fecha SOLVED

- The dates was stored with mask
- Before save dates unmask the value
This commit is contained in:
Julio Cesar Laura
2013-05-14 16:10:01 -04:00
parent dae407c822
commit e905a73b91
2 changed files with 72 additions and 2 deletions

View File

@@ -507,6 +507,9 @@ class Form extends XmlForm
$values[$k][$j] = $newValues[$k][$j]; $values[$k][$j] = $newValues[$k][$j];
$values[$k][$j][$kk . "_label"] = $newValues[$k][$j][$kk . "_label"]; $values[$k][$j][$kk . "_label"] = $newValues[$k][$j][$kk . "_label"];
break; break;
case 'date':
$values[$k][$j][$kk] = $this->fields[$k]->fields[$kk]->maskDateValue( $newValues[$k][$j][$kk], $this->fields[$k]->fields[$kk] );
break;
default: default:
//If there are no dropdowns previously setted and the evaluated field is not a dropdown //If there are no dropdowns previously setted and the evaluated field is not a dropdown
//only then rewritte the $values //only then rewritte the $values
@@ -530,6 +533,9 @@ class Form extends XmlForm
} }
} }
break; break;
case 'date':
$values[$k] = $this->fields[$k]->maskDateValue( $newValues[$k], $this->fields[$k] );
break;
default: default:
if ($this->fields[$k]->validateValue( $newValues[$k], $this )) { if ($this->fields[$k]->validateValue( $newValues[$k], $this )) {
$values[$k] = $this->fields[$k]->maskValue( $newValues[$k], $this ); $values[$k] = $this->fields[$k]->maskValue( $newValues[$k], $this );

View File

@@ -4523,8 +4523,8 @@ class XmlForm_Field_Date extends XmlForm_Field_SimpleText
$min = '%M'; $min = '%M';
$sec = '%S'; $sec = '%S';
$sizehour = strpos( $mask, $hour ); $sizehour = strpos( $mask, $hour );
$sizemin = strpos( $mask, $hour ); $sizemin = strpos( $mask, $min );
$sizesec = strpos( $mask, $hour ); $sizesec = strpos( $mask, $sec );
$Time = 'false'; $Time = 'false';
if (($sizehour !== false) && ($sizemin !== false) && ($sizesec !== false)) { if (($sizehour !== false) && ($sizemin !== false) && ($sizesec !== false)) {
@@ -4567,6 +4567,70 @@ class XmlForm_Field_Date extends XmlForm_Field_SimpleText
} }
return $html; return $html;
} }
public function maskDateValue ($value, $field)
{
$value = trim($value);
$mask = $field->mask;
if ($value == '' || $mask == '') {
return $value;
}
if (strpos( $mask, '%' ) === false) {
if (strpos( $mask, '-' ) !== false) {
$separator = '-';
}
if (strpos( $mask, '/' ) !== false) {
$separator = '/';
}
if (strpos( $mask, '.' ) !== false) {
$separator = '.';
}
$maskparts = explode( $separator, $mask );
$mask = '';
foreach ($maskparts as $part) {
if ($mask != '') {
$mask .= $separator;
}
if ($part == 'yyyy') {
$part = 'Y';
}
if ($part == 'dd') {
$part = 'd';
}
if ($part == 'mm') {
$part = 'm';
}
if ($part == 'yy') {
$part = 'y';
}
$mask .= '%' . $part;
}
}
$withHours = (strpos($mask, '%H') !== false || strpos($mask, '%M') !== false || strpos($mask, '%S') !== false);
$tmp = str_replace( "%", "", $mask );
return $this->date_create_from_format($tmp, $value, $withHours);
}
function date_create_from_format( $dformat, $dvalue, $withHours = false )
{
$schedule = $dvalue;
$schedule_format = str_replace(array('Y','m','d','H','M','S'),array('%Y','%m','%d','%H','%M','%S') ,$dformat);
$ugly = strptime($schedule, $schedule_format);
$ymd = sprintf(
'%04d-%02d-%02d %02d:%02d:%02d',
$ugly['tm_year'] + 1900,
$ugly['tm_mon'] + 1,
$ugly['tm_mday'],
$ugly['tm_hour'],
$ugly['tm_min'],
$ugly['tm_sec']
);
$new_schedule = new DateTime($ymd);
return $new_schedule->format('Y-m-d' . ($withHours ? ' H:i:s' : ''));
}
} }
/** /**