PregNativeDate   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
D parseSymbol() 0 40 9
1
<?php
2
3
namespace Popy\Calendar\Parser\SymbolParser;
4
5
use Popy\Calendar\Parser\FormatToken;
6
use Popy\Calendar\Parser\SymbolParserInterface;
7
use Popy\Calendar\Parser\FormatParserInterface;
8
use Popy\Calendar\Parser\DateLexer\PregSimple;
9
10
/**
11
 * Implementation of the native DateTime timestamp/timezones formats using preg
12
 * lexers.
13
 */
14
class PregNativeDate implements SymbolParserInterface
15
{
16
    /**
17
     * @inheritDoc
18
     */
19
    public function parseSymbol(FormatToken $token, FormatParserInterface $parser)
20
    {
21
        if ($token->is('U')) {
22
            // U   Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)  See also time()
23
            return new PregSimple($token, '-?\d+');
24
        }
25
26
        if ($token->is('u')) {
27
            // u   Microseconds
28
            return new PregSimple($token, '\d{6}');
29
        }
30
31
        if ($token->is('e')) {
32
            // e   Timezone identifier (added in PHP 5.1.0)    Examples: UTC, GMT, Atlantic/Azores
33
            return new PregSimple($token, '\S.*?');
34
        }
35
36
        if ($token->is('I')) {
37
            // I (capital i)   Whether or not the date is in daylight saving time  1 if Daylight Saving Time, 0 otherwise.
38
            return new PregSimple($token, '\d');
39
        }
40
41
        if ($token->is('O')) {
42
            // O   Difference to Greenwich time (GMT) in hours Example: +0200
43
            return new PregSimple($token, '[+\-]\d{4}');
44
        }
45
46
        if ($token->is('P')) {
47
            // P   Difference to Greenwich time (GMT) with colon between hours and minutes (added in PHP 5.1.3)    Example: +02:00
48
            return new PregSimple($token, '[+\-]\d\d:\d\d');
49
        }
50
51
        if ($token->is('T')) {
52
            // T   Timezone abbreviation   Examples: EST, MDT ...
53
            return new PregSimple($token, '[A-Z]{1,4}');
54
        }
55
56
        if ($token->is('Z')) {
57
            // Z   Timezone offset in seconds. The offset for timezones west of UTC is always negative, and for those east of UTC is always positive.  -43200 through 50400
58
            return new PregSimple($token, '-?\d{1,5}');
59
        }
60
    }
61
}
62