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:
@@ -507,6 +507,9 @@ class Form extends XmlForm
|
||||
$values[$k][$j] = $newValues[$k][$j];
|
||||
$values[$k][$j][$kk . "_label"] = $newValues[$k][$j][$kk . "_label"];
|
||||
break;
|
||||
case 'date':
|
||||
$values[$k][$j][$kk] = $this->fields[$k]->fields[$kk]->maskDateValue( $newValues[$k][$j][$kk], $this->fields[$k]->fields[$kk] );
|
||||
break;
|
||||
default:
|
||||
//If there are no dropdowns previously setted and the evaluated field is not a dropdown
|
||||
//only then rewritte the $values
|
||||
@@ -530,6 +533,9 @@ class Form extends XmlForm
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'date':
|
||||
$values[$k] = $this->fields[$k]->maskDateValue( $newValues[$k], $this->fields[$k] );
|
||||
break;
|
||||
default:
|
||||
if ($this->fields[$k]->validateValue( $newValues[$k], $this )) {
|
||||
$values[$k] = $this->fields[$k]->maskValue( $newValues[$k], $this );
|
||||
|
||||
@@ -4523,8 +4523,8 @@ class XmlForm_Field_Date extends XmlForm_Field_SimpleText
|
||||
$min = '%M';
|
||||
$sec = '%S';
|
||||
$sizehour = strpos( $mask, $hour );
|
||||
$sizemin = strpos( $mask, $hour );
|
||||
$sizesec = strpos( $mask, $hour );
|
||||
$sizemin = strpos( $mask, $min );
|
||||
$sizesec = strpos( $mask, $sec );
|
||||
$Time = 'false';
|
||||
|
||||
if (($sizehour !== false) && ($sizemin !== false) && ($sizesec !== false)) {
|
||||
@@ -4567,6 +4567,70 @@ class XmlForm_Field_Date extends XmlForm_Field_SimpleText
|
||||
}
|
||||
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' : ''));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user