From: Jan Schneider Date: Tue, 12 May 2009 22:06:55 +0000 (+0200) Subject: Cast timestamp columns to DateTime objects. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=7d5f8c8c6fe602160ba1ac678478d7e1db78de1b;p=horde.git Cast timestamp columns to DateTime objects. --- diff --git a/framework/Db/lib/Horde/Db/Adapter/Abstract/Column.php b/framework/Db/lib/Horde/Db/Adapter/Abstract/Column.php index 38bf97e7e..bbf60e9a8 100644 --- a/framework/Db/lib/Horde/Db/Adapter/Abstract/Column.php +++ b/framework/Db/lib/Horde/Db/Adapter/Abstract/Column.php @@ -211,50 +211,50 @@ class Horde_Db_Adapter_Abstract_Column } /** - * @TODO Return a Horde_Date or DateTime object instead? + * @TODO Return a Horde_Date object instead? * * @param string $string - * @return string + * @return DateTime */ public function stringToDate($string) { - if (empty($string)) { return null; } - - // preserve '0000-00-00' (http://bugs.php.net/bug.php?id=45647) - if (preg_replace('/[^\d]/', '', $string) == 0) { - return '0000-00-00'; + if (empty($string) || + // preserve '0000-00-00' (http://bugs.php.net/bug.php?id=45647) + preg_replace('/[^\d]/', '', $string) == 0) { + return null; } - return date('Y-m-d', strtotime($string)); + return new DateTime($string); } /** - * @TODO Return a Horde_Date or DateTime object instead? + * @TODO Return a Horde_Date object instead? * * @param string $string - * @return string + * @return DateTime */ public function stringToTime($string) { - if (empty($string)) { return null; } - - // preserve '0000-00-00 00:00:00' (http://bugs.php.net/bug.php?id=45647) - if (preg_replace('/[^\d]/', '', $string) == 0) { - return '0000-00-00 00:00:00'; + if (empty($string) || + // preserve '0000-00-00 00:00:00' (http://bugs.php.net/bug.php?id=45647) + preg_replace('/[^\d]/', '', $string) == 0) { + return null; } - return date('Y-m-d H:i:s', strtotime($string)); + return new DateTime($string); } /** - * @TODO Return a Horde_Date or DateTime object instead? + * @TODO Return a Horde_Date object instead? * * @param string $string - * @return string + * @return DateTime */ public function stringToDummyTime($value) { - if (empty($string)) return null; + if (empty($string)) { + return null; + } return $this->stringToTime('2000-01-01 ' . $string); }