Completed
Push — master ( f5604b...9d682e )
by Tim
8s
created

FormatUtcDateViewHelper::render()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 2
1
<?php
2
3
/**
4
 * Provide strftime function in UTC context.
5
 */
6
declare(strict_types=1);
7
8
namespace HDNET\Calendarize\ViewHelpers\DateTime;
9
10
use HDNET\Calendarize\ViewHelpers\AbstractViewHelper;
11
12
/**
13
 * Check if the given Index is on the given day.
14
 */
15
class FormatUtcDateViewHelper extends AbstractViewHelper
16
{
17
    /**
18
     * Format dateTime using strftime() with UTC timezone
19
     *
20
     * @param \DateTime $date
21
     * @param string     $format
22
     *
23
     * @return string
24
     */
25
    public function render(\DateTime $date, string $format = '')
26
    {
27
        // save configured timezone
28
        $timezone = date_default_timezone_get();
29
        // set timezone to UTC
30
        date_default_timezone_set('UTC');
31
32
        $result = strftime($format, (int) $date->format('U'));
33
34
        // restore timezone setting
35
        date_default_timezone_set($timezone);
36
37
        return $result;
38
    }
39
}
40