StandardDate   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 53
rs 10
c 0
b 0
f 0
wmc 10

1 Method

Rating   Name   Duplication   Size   Complexity  
C formatSymbol() 0 48 10
1
<?php
2
3
namespace Popy\Calendar\Formatter\SymbolFormatter;
4
5
use Popy\Calendar\FormatterInterface;
6
use Popy\Calendar\Parser\FormatToken;
7
use Popy\Calendar\Formatter\SymbolFormatterInterface;
8
use Popy\Calendar\ValueObject\DateRepresentationInterface;
9
10
/**
11
 * Standard format, handling DateRepresentationInterface.
12
 */
13
class StandardDate implements SymbolFormatterInterface
14
{
15
    /**
16
     * @inheritDoc
17
     */
18
    public function formatSymbol(DateRepresentationInterface $input, FormatToken $token, FormatterInterface $formatter)
19
    {
20
        if ($token->is('U')) {
21
            // U   Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)
22
            return $input->getUnixTime();
23
        }
24
25
        if ($token->is('u')) {
26
            // u   Microseconds
27
            return sprintf('%06d', $input->getUnixMicroTime());
28
        }
29
30
        if ($token->is('e')) {
31
            // e   Timezone identifier
32
            return $input->getTimezone()->getName();
33
        }
34
35
        if ($token->is('I')) {
36
            // I (capital i) Whether or not the date is in daylight saving time
37
            return (int)$input->getOffset()->isDst();
38
        }
39
40
        if ($token->isOne('O', 'P')) {
41
            // O   Difference to Greenwich time (GMT) in hours
42
            // P   Difference to Greenwich time (GMT) with colon
43
            $f = '%s%02d%02d';
44
            if ($token->is('P')) {
45
                $f = '%s%02d:%02d';
46
            }
47
48
            $value = intval($input->getOffset()->getValue() / 60);
49
50
            return sprintf(
51
                $f,
52
                $value < 0 ? '-' : '+',
53
                intval(abs($value) / 60),
54
                intval(abs($value) % 60)
55
            );
56
        }
57
58
        if ($token->is('T')) {
59
            // T   Timezone abbreviation
60
            return $input->getOffset()->getAbbreviation();
61
        }
62
63
        if ($token->is('Z')) {
64
            // Z   Timezone offset in seconds.
65
            return (int)$input->getOffset()->getValue();
66
        }
67
    }
68
}
69