|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AlgoWeb\xsdTypes; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* The type xsd:yearMonthDuration represents a duration of time expressed as a number of years and months. The format |
|
7
|
|
|
* of xsd:yearMonthDuration is PnYnM, where P is a literal value that starts the expression, nY is the number of years |
|
8
|
|
|
* followed by a literal Y, nM is the number of months followed by a literal M. The following rules apply to |
|
9
|
|
|
* xsd:yearMonthDuration values: |
|
10
|
|
|
* |
|
11
|
|
|
* - Either of these numbers and corresponding designators may be absent if they are equal to 0, but at least |
|
12
|
|
|
* one number and designator must appear. |
|
13
|
|
|
* - The numbers may be any unsigned integer. |
|
14
|
|
|
* - A minus sign may appear before the P to specify a negative duration. |
|
15
|
|
|
* Note that this type was added to the XML Schema namespace as a result of XPath 2.0. It was not in the original XML |
|
16
|
|
|
* Schema 1.0 specification and is therefore not supported for use in XML Schema 1.0 schemas. |
|
17
|
|
|
* @package AlgoWeb\xsdTypes |
|
18
|
|
|
*/ |
|
19
|
|
View Code Duplication |
class xsYearMonthDuration extends xsDurationextends |
|
|
|
|
|
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* Construct |
|
23
|
|
|
* |
|
24
|
|
|
* @param string $value |
|
25
|
|
|
*/ |
|
26
|
|
|
public function __construct($value) |
|
27
|
|
|
{ |
|
28
|
|
|
parent::__construct($value); |
|
29
|
|
|
$this->setWhiteSpaceFacet("collapse"); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function fixValue() |
|
33
|
|
|
{ |
|
34
|
|
|
parent::fixValue(); |
|
35
|
|
|
$v = new \DateInterval($this->value); |
|
36
|
|
|
$this->value = $this->format($v); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
//TODO: TechDebt.this needs to be more specific fo the type. |
|
40
|
|
|
protected function format(\DateInterval $tint) |
|
41
|
|
|
{ |
|
42
|
|
|
$sReturn = 'P'; |
|
43
|
|
|
|
|
44
|
|
|
if ($this->y) { |
|
45
|
|
|
$sReturn .= $tint->y . 'Y'; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
if ($this->m) { |
|
49
|
|
|
$sReturn .= $tint->m . 'M'; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
if ($this->d) { |
|
53
|
|
|
$sReturn .= $tint->d . 'D'; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
if ($tint->h || $tint->i || $tint->s) { |
|
57
|
|
|
$sReturn .= 'T'; |
|
58
|
|
|
|
|
59
|
|
|
if ($this->h) { |
|
60
|
|
|
$sReturn .= $tint->h . 'H'; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
if ($this->i) { |
|
64
|
|
|
$sReturn .= $tint->i . 'M'; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
if ($this->s) { |
|
68
|
|
|
$sReturn .= $tint->s . 'S'; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
return $sReturn; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
protected function isOK() |
|
76
|
|
|
{ |
|
77
|
|
|
$this->CheckMinMax(new \DateInterval($this->value)); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.