diff --git a/config.ini-example b/config.ini-example index 91977a7..cedbdd5 100644 --- a/config.ini-example +++ b/config.ini-example @@ -30,3 +30,4 @@ theme = "default" ; set the timezone [date] ; timezone = UTC +; format = 'd/m/Y H:i:s' diff --git a/src/GitList/Application.php b/src/GitList/Application.php index 3e3d9cb..dd5acc2 100644 --- a/src/GitList/Application.php +++ b/src/GitList/Application.php @@ -30,6 +30,7 @@ class Application extends SilexApplication $this->path = realpath($root); $this['debug'] = $config->get('app', 'debug'); + $this['date.format'] = $config->get('date', 'format') ? $config->get('date', 'format') : 'd/m/Y H:i:s'; $this['theme'] = $config->get('app', 'theme') ? $config->get('app', 'theme') : 'default'; $this['filetypes'] = $config->getSection('filetypes'); $this['cache.archives'] = $this->getCachePath() . 'archives'; @@ -59,8 +60,9 @@ class Application extends SilexApplication $this->register(new RoutingUtilServiceProvider()); $this['twig'] = $this->share($this->extend('twig', function ($twig, $app) { - $twig->addFilter('htmlentities', new \Twig_Filter_Function('htmlentities')); - $twig->addFilter('md5', new \Twig_Filter_Function('md5')); + $twig->addFilter(new \Twig_SimpleFilter('htmlentities', 'htmlentities')); + $twig->addFilter(new \Twig_SimpleFilter('md5', 'md5')); + $twig->addFilter(new \Twig_SimpleFilter('format_date', array($this, 'formatDate'))); return $twig; })); @@ -77,6 +79,11 @@ class Application extends SilexApplication }); } + public function formatDate($date) + { + return $date->format($this['date.format']); + } + public function getPath() { return $this->path . DIRECTORY_SEPARATOR; diff --git a/themes/bootstrap3/twig/commit.twig b/themes/bootstrap3/twig/commit.twig index 120807c..c4386e1 100644 --- a/themes/bootstrap3/twig/commit.twig +++ b/themes/bootstrap3/twig/commit.twig @@ -18,7 +18,7 @@

{{ commit.body | nl2br }}

{% endif %} - {{ commit.author.name }} authored on {{ commit.date | date('d/m/Y \\a\\t H:i:s') }}
Showing {{ commit.changedFiles }} changed files
+ {{ commit.author.name }} authored on {{ commit.date | format_date }}
Showing {{ commit.changedFiles }} changed files
diff --git a/themes/bootstrap3/twig/commits_list.twig b/themes/bootstrap3/twig/commits_list.twig index 1919d46..6462cd8 100644 --- a/themes/bootstrap3/twig/commits_list.twig +++ b/themes/bootstrap3/twig/commits_list.twig @@ -13,7 +13,7 @@ View {{ item.shortHash }}

{{ item.message }}

- {{ item.author.name }} authored on {{ item.date | date('d/m/Y \\a\\t H:i:s') }} + {{ item.author.name }} authored on {{ item.date | format_date }} {% endfor %} diff --git a/themes/default/twig/commit.twig b/themes/default/twig/commit.twig index 8cbd3ac..3a4ce11 100644 --- a/themes/default/twig/commit.twig +++ b/themes/default/twig/commit.twig @@ -17,7 +17,7 @@

{{ commit.body | nl2br }}

{% endif %} - {{ commit.author.name }} authored on {{ commit.date | date('d/m/Y \\a\\t H:i:s') }}
Showing {{ commit.changedFiles }} changed files
+ {{ commit.author.name }} authored on {{ commit.date | format_date }}
Showing {{ commit.changedFiles }} changed files
diff --git a/themes/default/twig/commits_list.twig b/themes/default/twig/commits_list.twig index 27b1a54..37850f7 100644 --- a/themes/default/twig/commits_list.twig +++ b/themes/default/twig/commits_list.twig @@ -13,7 +13,7 @@ View {{ item.shortHash }}

{{ item.message }}

- {{ item.author.name }} authored on {{ item.date | date('d/m/Y \\a\\t H:i:s') }} + {{ item.author.name }} authored on {{ item.date | format_date }} {% endfor %} diff --git a/themes/default/twig/rss.twig b/themes/default/twig/rss.twig index 0fdc823..0596261 100644 --- a/themes/default/twig/rss.twig +++ b/themes/default/twig/rss.twig @@ -8,10 +8,10 @@ {% for commit in commits %} {{ commit.message }} - {{ commit.author.name }} authored {{ commit.shortHash }} in {{ commit.date | date('d/m/Y \\a\\t H:i:s') }} + {{ commit.author.name }} authored {{ commit.shortHash }} in {{ commit.date | format_date }} {{ url('commit', {repo: repo, commit: commit.hash}) }} {{ commit.date | date('r') }} {% endfor %} - \ No newline at end of file +