]> git.andy128k.dev Git - ipf-template.git/commitdiff
fix date format
authorAndrey Kutejko <andy128k@gmail.com>
Mon, 16 Sep 2013 19:00:00 +0000 (22:00 +0300)
committerAndrey Kutejko <andy128k@gmail.com>
Mon, 16 Sep 2013 19:00:00 +0000 (22:00 +0300)
lib/environment.php
lib/modifier.php

index eb7834fa773622419855a1d62445c5948d05de5a..f8cec506ed7cd8d368a9560a87ce6b44a99134e8 100644 (file)
@@ -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',
index 0c837da39760f467266a222497116530bc888d38..96c444f33677ca4df455a1422f33d0d11b664087 100644 (file)
@@ -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')