diff --git a/flextype/core/Forms.php b/flextype/core/Forms.php index 6ca87d20..f069a73e 100644 --- a/flextype/core/Forms.php +++ b/flextype/core/Forms.php @@ -394,7 +394,7 @@ class Forms { return '
- +
diff --git a/flextype/dependencies.php b/flextype/dependencies.php index 2e5da2d2..7eda8f0f 100644 --- a/flextype/dependencies.php +++ b/flextype/dependencies.php @@ -253,6 +253,9 @@ $flextype['view'] = static function ($container) { // Add Filesystem Twig Extension $view->addExtension(new FilesystemTwigExtension()); + // Add Date Twig Extension + $view->addExtension(new DateTwigExtension()); + // Add Assets Twig Extension $view->addExtension(new AssetsTwigExtension()); diff --git a/flextype/twig/DateTwigExtension.php b/flextype/twig/DateTwigExtension.php new file mode 100644 index 00000000..3fbe83b5 --- /dev/null +++ b/flextype/twig/DateTwigExtension.php @@ -0,0 +1,106 @@ + 'DD', + 'D' => 'ddd', + 'j' => 'D', + 'l' => 'dddd', + 'N' => 'E', + 'S' => 'Do', + 'w' => 'd', + 'z' => 'DDD', + // Week + 'W' => 'W', + // Month + 'F' => 'MMMM', + 'm' => 'MM', + 'M' => 'MMM', + 'n' => 'M', + 't' => '', + // Year + 'L' => '', + 'o' => 'GGGG', + 'Y' => 'YYYY', + 'y' => 'yy', + // Time + 'a' => 'a', + 'A' => 'A', + 'B' => 'SSS', + 'g' => 'h', + 'G' => 'H', + 'h' => 'hh', + 'H' => 'HH', + 'i' => 'mm', + 's' => 'ss', + 'u' => '', + // Timezone + 'e' => '', + 'I' => '', + 'O' => 'ZZ', + 'P' => 'Z', + 'T' => 'z', + 'Z' => '', + // Full Date/Time + 'c' => '', + 'r' => 'llll ZZ', + 'U' => 'X' + ]; + $js_format = ''; + $escaping = false; + $len = strlen($php_format); + for ($i = 0; $i < $len; $i++) { + $char = $php_format[$i]; + if ($char === '\\') // PHP date format escaping character + { + $i++; + if ($escaping) { + $js_format .= $php_format[$i]; + } else { + $js_format .= '\'' . $php_format[$i]; + } + $escaping = true; + } else { + if ($escaping) { + $js_format .= "'"; + $escaping = false; + } + if (isset($SYMBOLS_MATCHING[$char])) { + $js_format .= $SYMBOLS_MATCHING[$char]; + } else { + $js_format .= $char; + } + } + } + + return $js_format; + } +}