automatic conversation of not set DB timestamps returned by MySQL as "0000-00-00 00:00:00" to null

This commit is contained in:
Ralf Becker 2012-01-11 01:03:45 +00:00
parent c7dc8748b7
commit b34d6f9d35
2 changed files with 9 additions and 2 deletions

View File

@ -112,7 +112,7 @@ class date_widget
// automatic convert db timestamps to unix timestamps, our db class does the reverse on writing them // automatic convert db timestamps to unix timestamps, our db class does the reverse on writing them
if ($value && !$data_format && !is_numeric($value) && ($v = strtotime($value))) if ($value && !$data_format && !is_numeric($value) && ($v = strtotime($value)))
{ {
$value = $v; $value = $value === '0000-00-00 00:00:00' ? null : $v;
} }
// for date-(time|hour)only widgets we distinct between between 0 and ''/null timestamps // for date-(time|hour)only widgets we distinct between between 0 and ''/null timestamps
if (!$value && ($type != 'date-timeonly' && $type != 'date-houronly' || (string)$value === '')) if (!$value && ($type != 'date-timeonly' && $type != 'date-houronly' || (string)$value === ''))

View File

@ -374,11 +374,18 @@ class so_sql
foreach($this->timestamps as $name) foreach($this->timestamps as $name)
{ {
if (isset($data[$name]) && $data[$name]) if (isset($data[$name]) && $data[$name])
{
if ($data[$name] === '0000-00-00 00:00:00')
{
$data[$name] = null;
}
else
{ {
$data[$name] = egw_time::server2user($data[$name],$this->timestamp_type); $data[$name] = egw_time::server2user($data[$name],$this->timestamp_type);
} }
} }
} }
}
return $data; return $data;
} }