From: Andrey Kutejko Date: Mon, 16 Sep 2013 19:00:00 +0000 (+0300) Subject: fix date format X-Git-Url: https://git.andy128k.dev/?a=commitdiff_plain;h=698e7560bceb80313f62c787d6d7f79d645e9330;p=ipf-template.git fix date format --- diff --git a/lib/environment.php b/lib/environment.php index eb7834f..f8cec50 100644 --- a/lib/environment.php +++ b/lib/environment.php @@ -40,6 +40,7 @@ abstract class IPF_Template_Environment 'safe' => 'IPF_Template_SafeString::markSafe', 'date' => 'IPF_Template_Modifier::dateFormat', 'time' => 'IPF_Template_Modifier::timeFormat', + 'datetime' => 'IPF_Template_Modifier::datetimeFormat', 'floatformat' => 'IPF_Template_Modifier::floatFormat', 'limit_words' => 'IPF_Template_Modifier::limitWords', 'limit_chars' => 'IPF_Template_Modifier::limitCharacters', diff --git a/lib/modifier.php b/lib/modifier.php index 0c837da..96c444f 100644 --- a/lib/modifier.php +++ b/lib/modifier.php @@ -7,15 +7,29 @@ final class IPF_Template_Modifier return htmlspecialchars((string)$string, ENT_COMPAT, 'UTF-8'); } - public static function dateFormat($date, $format='%b %e, %Y') + private static function fixFormat($format) { if (substr(PHP_OS,0,3) == 'WIN') { - $_win_from = array ('%e', '%T', '%D'); - $_win_to = array ('%#d', '%H:%M:%S', '%m/%d/%y'); - $format = str_replace($_win_from, $_win_to, $format); + $_win_from = array('%e', '%T', '%D'); + $_win_to = array('%#d', '%H:%M:%S', '%m/%d/%y'); + return str_replace($_win_from, $_win_to, $format); + } else { + return $format; } - $date = date('Y-m-d H:i:s', strtotime($date.' GMT')); - return strftime($format, strtotime($date)); + } + + public static function dateFormat($date, $format='%b %e, %Y') + { + $date = date('Y-m-d', strtotime($date)); + + return strftime(self::fixFormat($format), strtotime($date)); + } + + public static function datetimeFormat($datetime, $format='%b %e, %Y') + { + $datetime = date('Y-m-d H:i:s', strtotime($datetime.' GMT')); + + return strftime(self::fixFormat($format), strtotime($datetime)); } public static function timeFormat($time, $format='Y-m-d H:i:s')