From ec1a1ec5b9b8b0a450777bee97ecb01fb01f03d6 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Mon, 15 Feb 2010 21:16:18 +0100 Subject: [PATCH] DibiRow::asDateTime() added $format parameter --- dibi/libs/DibiRow.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/dibi/libs/DibiRow.php b/dibi/libs/DibiRow.php index 1940f7f2..fecc6fe6 100644 --- a/dibi/libs/DibiRow.php +++ b/dibi/libs/DibiRow.php @@ -34,14 +34,17 @@ class DibiRow extends ArrayObject /** * Converts value to DateTime object. * @param string key + * @param string format * @return DateTime */ - public function asDateTime($key) + public function asDateTime($key, $format = NULL) { $time = $this[$key]; - return (int) $time === 0 // '', NULL, FALSE, '0000-00-00', ... - ? NULL - : new DateTime53(is_numeric($time) ? date('Y-m-d H:i:s', $time) : $time); + if ((int) $time === 0) { // '', NULL, FALSE, '0000-00-00', ... + return NULL; + } + $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) { return $this->asTimestamp($key); - } elseif ($format === TRUE) { - return $this->asDateTime($key); } else { - return $this->asDateTime($key)->format($format); + return $this->asDateTime($key, $format === TRUE ? NULL : $format); } }