Passed
Push — release-3.2.0 ( 42857a...93efa8 )
by Daniel
09:12
created

format_date::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 *
4
 * @package sitemaker
5
 * @copyright (c) 2019 Daniel A. (blitze)
6
 * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7
 *
8
 */
9
10
namespace blitze\sitemaker\services\template\extensions;
11
12
class format_date extends \Twig\Extension\AbstractExtension
13
{
14
	/** @var \phpbb\user */
15
	protected $user;
16
17
	/**
18
	* Constructor
19
	*
20
	* @param \phpbb\user $user
21
	* @return \phpbb\template\twig\extension
22
	*/
23
	public function __construct(\phpbb\user $user)
24
	{
25
		$this->user = $user;
26
	}
27
28
	/**
29
	 * @inheritdoc
30
	 */
31
    public function getFilters()
32
    {
33
        return [
34
            new \Twig\TwigFilter('format_date', [$this, 'format_date_filter']),
35
        ];
36
    }
37
38
	/**
39
	* Format user date
40
	*
41
	* @param int $gmepoch unix timestamp
42
	* @param string $format date format in date() notation. | used to indicate relative dates, for example |d m Y|, h:i is translated to Today, h:i.
43
	* @param bool $forcedate force non-relative date format.
44
	*
45
	* @return mixed translated date
46
	*/
47
    public function format_date_filter($timestamp, $format = false, $forcedate = false)
48
    {
49
        return $this->user->format_date($timestamp, $format, $forcedate);
50
    }
51
}
52