1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-05 05:37:39 +02:00

DibiRow: asBool(), asDate() and asTimestamp() deprecated

This commit is contained in:
David Grudl
2012-01-12 01:19:06 +01:00
parent 4c85d1d55c
commit 8c481bc128

View File

@@ -43,11 +43,13 @@ class DibiRow implements ArrayAccess, IteratorAggregate, Countable
public function asDateTime($key, $format = NULL)
{
$time = $this[$key];
if ((int) $time === 0) { // '', NULL, FALSE, '0000-00-00', ...
return NULL;
if (!$time instanceof DibiDateTime) {
if ((int) $time === 0) { // '', NULL, FALSE, '0000-00-00', ...
return NULL;
}
$time = new DibiDateTime(is_numeric($time) ? date('Y-m-d H:i:s', $time) : $time);
}
$dt = new DibiDateTime(is_numeric($time) ? date('Y-m-d H:i:s', $time) : $time);
return $format === NULL ? $dt : $dt->format($format);
return $format === NULL ? $time : $time->format($format);
}
@@ -59,6 +61,7 @@ class DibiRow implements ArrayAccess, IteratorAggregate, Countable
*/
public function asTimestamp($key)
{
trigger_error(__METHOD__ . '() is deprecated.', E_USER_WARNING);
$time = $this[$key];
return (int) $time === 0 // '', NULL, FALSE, '0000-00-00', ...
? NULL
@@ -74,13 +77,8 @@ class DibiRow implements ArrayAccess, IteratorAggregate, Countable
*/
public function asBool($key)
{
$value = $this[$key];
if ($value === NULL || $value === FALSE) {
return $value;
} else {
return ((bool) $value) && $value !== 'f' && $value !== 'F';
}
trigger_error(__METHOD__ . '() is deprecated.', E_USER_WARNING);
return $this[$key];
}
@@ -88,6 +86,7 @@ class DibiRow implements ArrayAccess, IteratorAggregate, Countable
/** @deprecated */
public function asDate($key, $format = NULL)
{
trigger_error(__METHOD__ . '() is deprecated.', E_USER_WARNING);
if ($format === NULL) {
return $this->asTimestamp($key);
} else {