1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AlgoWeb\xsdTypes; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* The type xsd:duration represents a duration of time expressed as a number of years, months, days, hours, minutes, |
7
|
|
|
* and seconds. The format of xsd:duration is PnYnMnDTnHnMnS, where P is a literal value that starts the expression, |
8
|
|
|
* nY is the number of years followed by a literal Y, nM is the number of months followed by a literal M, nD is the |
9
|
|
|
* number of days followed by a literal D, T is a literal value that separates the date and time, nH is the number of |
10
|
|
|
* hours followed by a literal H, nM is the number of minutes followed by a literal M, and nS is the number of seconds |
11
|
|
|
* followed by a literal S. The following rules apply to xsd:duration values:. |
12
|
|
|
* |
13
|
|
|
* - Any of these numbers and corresponding designators may be absent if they are equal to 0, but at least one number and designator must appear. |
|
|
|
|
14
|
|
|
* - The numbers may be any unsigned integer, with the exception of the number of seconds, which may be an unsigned decimal number. |
|
|
|
|
15
|
|
|
* - If a decimal point appears in the number of seconds, there must be at least one digit after the decimal point. |
16
|
|
|
* - A minus sign may appear before the P to specify a negative duration. |
17
|
|
|
* - If no time items (hour, minute, second) are present, the letter T must not appear. |
18
|
|
|
* @package AlgoWeb\xsdTypes |
19
|
|
|
*/ |
20
|
|
|
class xsDuration extends xsAnySimpleType |
21
|
|
|
{ |
22
|
|
|
use MinMaxTrait; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Construct. |
26
|
|
|
* |
27
|
|
|
* @param string $value |
28
|
|
|
*/ |
29
|
|
|
public function __construct($value) |
30
|
|
|
{ |
31
|
|
|
parent::__construct($value); |
32
|
|
|
$this->setWhiteSpaceFacet('collapse'); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function fixValue() |
36
|
|
|
{ |
37
|
|
|
parent::fixValue(); |
38
|
|
|
$v = new \DateInterval($this->value); |
|
|
|
|
39
|
|
|
$this->value = $this->format($v); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
protected function format(\DateInterval $tint, $pattern = 'PnYnMnDTnHnMnS') |
43
|
|
|
{ |
44
|
|
|
$sReturn = ''; |
45
|
|
|
for ($i = 0; $i < strlen($pattern); $i++) { |
46
|
|
|
if ($pattern[$i] == 'n') { |
47
|
|
|
$sReturn .= $tint->strtolower($pattern[$i + 1]); |
48
|
|
|
continue; |
49
|
|
|
} |
50
|
|
|
$sReturn .= $pattern[$i]; |
51
|
|
|
} |
52
|
|
|
return $sReturn; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
protected function isOK() |
56
|
|
|
{ |
57
|
|
|
$this->CheckMinMax(new \DateInterval($this->value)); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.