mirror of
https://github.com/flextype/flextype.git
synced 2025-08-24 13:52:56 +02:00
fix(core): fix date formats for 0.9.4 release
This commit is contained in:
@@ -394,7 +394,7 @@ class Forms
|
||||
{
|
||||
return '
|
||||
<div class="input-group date" id="datetimepicker" data-target-input="nearest">
|
||||
<input name="' . $name . '" type="text" class="form-control datetimepicker-input" data-target="#datetimepicker" value="' . $value . '" />
|
||||
<input name="' . $name . '" type="text" class="form-control datetimepicker-input" data-target="#datetimepicker" value="' . date($this->flextype->registry->get('settings.date_format'), strtotime($value)) . '" />
|
||||
<div class="input-group-append" data-target="#datetimepicker" data-toggle="datetimepicker">
|
||||
<div class="input-group-text"><i class="far fa-calendar-alt"></i></div>
|
||||
</div>
|
||||
|
@@ -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());
|
||||
|
||||
|
106
flextype/twig/DateTwigExtension.php
Normal file
106
flextype/twig/DateTwigExtension.php
Normal file
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Flextype (http://flextype.org)
|
||||
* Founded by Sergey Romanenko and maintained by Flextype Community.
|
||||
*/
|
||||
|
||||
namespace Flextype;
|
||||
|
||||
use Twig_Extension;
|
||||
use Twig_SimpleFunction;
|
||||
|
||||
class DateTwigExtension extends Twig_Extension
|
||||
{
|
||||
/**
|
||||
* Returns a list of functions to add to the existing list.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getFunctions() : array
|
||||
{
|
||||
return [
|
||||
new Twig_SimpleFunction('dateformatToMomentJS', [$this, 'dateformatToMomentJS']),
|
||||
];
|
||||
}
|
||||
|
||||
public function dateformatToMomentJS($php_format)
|
||||
{
|
||||
$SYMBOLS_MATCHING = [
|
||||
// Day
|
||||
'd' => '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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user