|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AlgoWeb\xsdTypes\AxillaryClasses; |
|
4
|
|
|
|
|
5
|
|
|
class CalenderFactory extends Calender |
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* @param string $day should match regex pattern ----\d\d |
|
9
|
|
|
* |
|
10
|
|
|
* @return \AlgoWeb\xsdTypes\AxillaryClasses\Calender |
|
11
|
|
|
*/ |
|
12
|
|
View Code Duplication |
public static function fromDay($day) |
|
13
|
|
|
{ |
|
14
|
|
|
$dayTimezone = '/----(0[1-9]|1[0-9]|2[0-9]|3[0-1]|[1-9])([-+][0-1]\d:[0-6]\d|Z*)/'; |
|
15
|
|
|
preg_match_all($dayTimezone, $day, $matches, PREG_SET_ORDER, 0); |
|
16
|
|
|
if (count($matches) != 1 || count($matches[0]) != 3) { |
|
17
|
|
|
throw new \InvalidArgumentException('Unable to extract day from input string'); |
|
18
|
|
|
} |
|
19
|
|
|
return new self(null, null, $matches[0][1], $matches[0][2]); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @param string $monthDay |
|
24
|
|
|
* |
|
25
|
|
|
* @return \AlgoWeb\xsdTypes\AxillaryClasses\Calender |
|
26
|
|
|
*/ |
|
27
|
|
View Code Duplication |
public static function fromMonthDay($monthDay) |
|
28
|
|
|
{ |
|
29
|
|
|
$monthDayTimezone = '/--((?:1[0-2])|(?:0[0-9]))-(0[1-9]|1[0-9]|2[0-9]|3[0-1]|[1-9])([-+][0-1]\d:[0-6]\d|Z*)/'; |
|
30
|
|
|
preg_match_all($monthDayTimezone, $monthDay, $matches, PREG_SET_ORDER, 0); |
|
31
|
|
|
if (count($matches) != 1 || count($matches[0]) != 4) { |
|
32
|
|
|
throw new \InvalidArgumentException('Unable to extract month day from input string'); |
|
33
|
|
|
} |
|
34
|
|
|
return new self(null, $matches[0][1], $matches[0][2], $matches[0][3]); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @param string $month |
|
39
|
|
|
* |
|
40
|
|
|
* @return \AlgoWeb\xsdTypes\AxillaryClasses\Calender |
|
41
|
|
|
*/ |
|
42
|
|
View Code Duplication |
public static function fromMonth($month) |
|
43
|
|
|
{ |
|
44
|
|
|
$monthTimezone = '/--((?:1[0-2])|(?:0[0-9]))([-+][0-1]\d:[0-6]\d|Z*)/'; |
|
45
|
|
|
preg_match_all($monthTimezone, $month, $matches, PREG_SET_ORDER, 0); |
|
46
|
|
|
if (count($matches) != 1 || count($matches[0]) != 3) { |
|
47
|
|
|
throw new \InvalidArgumentException('Unable to extract month from input string'); |
|
48
|
|
|
} |
|
49
|
|
|
return new self(null, $matches[0][1], null, $matches[0][2]); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param string $yearMonth |
|
54
|
|
|
* |
|
55
|
|
|
* @return \AlgoWeb\xsdTypes\AxillaryClasses\Calender |
|
56
|
|
|
*/ |
|
57
|
|
View Code Duplication |
public static function fromYearMonth($yearMonth) |
|
58
|
|
|
{ |
|
59
|
|
|
$yearMonthTimezone = '/(\d{4})-((?:1[0-2])|(?:0[0-9]))([-+][0-1]\d:[0-6]\d|Z*)/'; |
|
60
|
|
|
preg_match_all($yearMonthTimezone, $yearMonth, $matches, PREG_SET_ORDER, 0); |
|
61
|
|
|
if (count($matches) != 1 || count($matches[0]) != 4) { |
|
62
|
|
|
throw new \InvalidArgumentException('Unable to extract year month from input string'); |
|
63
|
|
|
} |
|
64
|
|
|
return new self($matches[0][1], $matches[0][2], null, $matches[0][3]); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @param string $year |
|
69
|
|
|
* |
|
70
|
|
|
* @return \AlgoWeb\xsdTypes\AxillaryClasses\Calender |
|
71
|
|
|
*/ |
|
72
|
|
View Code Duplication |
public static function fromYear($year) |
|
73
|
|
|
{ |
|
74
|
|
|
$yearTimezone = '/(\d{4})([-+][0-1]\d:[0-6]\d|Z*)/'; |
|
75
|
|
|
preg_match_all($yearTimezone, $year, $matches, PREG_SET_ORDER, 0); |
|
76
|
|
|
if (count($matches) != 1 || count($matches[0]) != 3) { |
|
77
|
|
|
throw new \InvalidArgumentException('Unable to extract month from input string'); |
|
78
|
|
|
} |
|
79
|
|
|
return new self($matches[0][1], null, null, $matches[0][2]); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|