|
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
|
|
|
use Popy\Calendar\Parser\DateLexer\PregChoice; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Implementation of the native DateTime time formats using preg lexers. |
|
13
|
|
|
*/ |
|
14
|
|
|
class PregNativeDateTime implements SymbolParserInterface |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @inheritDoc |
|
18
|
|
|
*/ |
|
19
|
|
|
public function parseSymbol(FormatToken $token, FormatParserInterface $parser) |
|
20
|
|
|
{ |
|
21
|
|
|
if ($token->isOne('a', 'A')) { |
|
22
|
|
|
// a Lowercase Ante meridiem and Post meridiem am or pm |
|
23
|
|
|
// A Uppercase Ante meridiem and Post meridiem AM or PM |
|
24
|
|
|
return new PregChoice($token, ['am', 'pm']); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
if ($token->is('B')) { |
|
28
|
|
|
// B Swatch Internet time 000 through 999 |
|
29
|
|
|
return new PregSimple($token, '\d\d\d'); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
if ($token->isOne('g', 'G')) { |
|
33
|
|
|
// g 12-hour format of an hour without leading zeros 1 through 12 |
|
34
|
|
|
// G 24-hour format of an hour without leading zeros 0 through 23 |
|
35
|
|
|
return new PregSimple($token, '\d?\d'); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
if ($token->isOne('h', 'H')) { |
|
39
|
|
|
// h 12-hour format of an hour with leading zeros 01 through 12 |
|
40
|
|
|
// H 24-hour format of an hour with leading zeros 00 through 23 |
|
41
|
|
|
return new PregSimple($token, '\d\d'); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
if ($token->is('i')) { |
|
45
|
|
|
// i Minutes with leading zeros 00 to 59 |
|
46
|
|
|
return new PregSimple($token, '\d\d'); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
if ($token->is('s')) { |
|
50
|
|
|
// s Seconds, with leading zeros 00 through 59 |
|
51
|
|
|
return new PregSimple($token, '\d\d'); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
if ($token->is('u')) { |
|
55
|
|
|
// u Microseconds |
|
56
|
|
|
return new PregSimple($token, '\d{6}'); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
if ($token->is('v')) { |
|
60
|
|
|
// u Milliseconds |
|
61
|
|
|
return new PregSimple($token, '\d\d\d'); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
if ($token->is('µ')) { |
|
65
|
|
|
// Remaining microseconds |
|
66
|
|
|
return new PregSimple($token, '\d\d\d'); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|