From df7468bf4e2aa262af69881f6deb30a033fa29bc Mon Sep 17 00:00:00 2001 From: Andrey Kutejko Date: Tue, 25 Feb 2014 21:30:58 +0200 Subject: [PATCH] extract format date utility --- ipf/admin/model.php | 4 +--- ipf/utils.php | 9 +++++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ipf/admin/model.php b/ipf/admin/model.php index ac88a3b..5eb1459 100644 --- a/ipf/admin/model.php +++ b/ipf/admin/model.php @@ -586,9 +586,7 @@ class IPF_Admin_Model $str = 'False'; break; case 'timestamp': - $date = new DateTime($str, new DateTimeZone('UTC')); - $date->setTimeZone(new DateTimeZone(IPF::get('time_zone'))); - $str = gmdate('Y-m-d H:i:s', $date->format('U') + $date->getOffset()); + $str = IPF_Utils::formatDate($str); break; } } diff --git a/ipf/utils.php b/ipf/utils.php index e459bde..b325505 100644 --- a/ipf/utils.php +++ b/ipf/utils.php @@ -106,6 +106,15 @@ class IPF_Utils return $string; } + public static function formatDate($str, $format='Y-m-d H:i:s', $tz=null) + { + if (!$tz) + $tz = IPF::get('time_zone'); + $date = new DateTime($str, new DateTimeZone('UTC')); + $date->setTimeZone(new DateTimeZone($tz)); + return gmdate($format, $date->format('U') + $date->getOffset()); + } + static function dateCompare($date1, $date2=null) { if (strlen($date1) == 10) { -- 2.49.0