mirror of
https://github.com/dg/dibi.git
synced 2025-08-05 21:58:10 +02:00
DibiRow::asDateTime() added $format parameter
This commit is contained in:
@@ -34,14 +34,17 @@ class DibiRow extends ArrayObject
|
|||||||
/**
|
/**
|
||||||
* Converts value to DateTime object.
|
* Converts value to DateTime object.
|
||||||
* @param string key
|
* @param string key
|
||||||
|
* @param string format
|
||||||
* @return DateTime
|
* @return DateTime
|
||||||
*/
|
*/
|
||||||
public function asDateTime($key)
|
public function asDateTime($key, $format = NULL)
|
||||||
{
|
{
|
||||||
$time = $this[$key];
|
$time = $this[$key];
|
||||||
return (int) $time === 0 // '', NULL, FALSE, '0000-00-00', ...
|
if ((int) $time === 0) { // '', NULL, FALSE, '0000-00-00', ...
|
||||||
? NULL
|
return NULL;
|
||||||
: new DateTime53(is_numeric($time) ? date('Y-m-d H:i:s', $time) : $time);
|
}
|
||||||
|
$dt = new DateTime53(is_numeric($time) ? date('Y-m-d H:i:s', $time) : $time);
|
||||||
|
return $format === NULL ? $dt : $dt->format($format);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -95,10 +98,8 @@ class DibiRow extends ArrayObject
|
|||||||
{
|
{
|
||||||
if ($format === NULL) {
|
if ($format === NULL) {
|
||||||
return $this->asTimestamp($key);
|
return $this->asTimestamp($key);
|
||||||
} elseif ($format === TRUE) {
|
|
||||||
return $this->asDateTime($key);
|
|
||||||
} else {
|
} else {
|
||||||
return $this->asDateTime($key)->format($format);
|
return $this->asDateTime($key, $format === TRUE ? NULL : $format);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user