Completed
Pull Request — master (#215)
by
unknown
03:15
created

FormatUtcDateViewHelper   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 1
dl 0
loc 25
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A render() 0 14 1
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