1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AlgoWeb\xsdTypes; |
4
|
|
|
|
5
|
|
|
use AlgoWeb\xsdTypes\Facets\MinMaxTrait; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* The type xsd:dateTime represents a specific date and time in the format CCYY-MM-DDThh:mm:ss.sss, which is a |
9
|
|
|
* concatenation of the date and time forms, separated by a literal letter "T". All of the same rules that apply to |
10
|
|
|
* the date and time types are applicable to xsd:dateTime as well. |
11
|
|
|
* |
12
|
|
|
* An optional time zone expression may be added at the end of the value. The letter Z is used to indicate Coordinated |
13
|
|
|
* Universal Time (UTC). All other time zones are represented by their difference from Coordinated Universal Time |
14
|
|
|
* in the format +hh:mm, or -hh:mm. These values may range from -14:00 to 14:00. For example, US Eastern Standard Time, |
15
|
|
|
* which is five hours behind UTC, is represented as -05:00. If no time zone value is present, it is considered |
16
|
|
|
* unknown; it is not assumed to be UTC. |
17
|
|
|
* @package AlgoWeb\xsdTypes |
18
|
|
|
*/ |
19
|
|
|
class xsDateTime extends xsAnySimpleType |
20
|
|
|
{ |
21
|
|
|
use MinMaxTrait; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Construct. |
25
|
|
|
* |
26
|
|
|
* @param string $value |
27
|
|
|
*/ |
28
|
|
|
public function __construct($value) |
29
|
|
|
{ |
30
|
|
|
parent::__construct($value); |
31
|
|
|
$this->setWhiteSpaceFacet('collapse'); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function fixValue() |
35
|
|
|
{ |
36
|
|
|
parent::fixValue(); |
37
|
|
|
$v = new \DateTime($this->value); |
38
|
|
|
$this->value = $v->format("Y-m-d\TH:i:s") . $this->fixFractionOfSecond($v) . $v->format("P"); |
|
|
|
|
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
private function fixFractionOfSecond(\DateTime $v) |
42
|
|
|
{ |
43
|
|
|
if (0 != (int)$v->format("u")) { |
|
|
|
|
44
|
|
|
return "." . $v->format("u") / 100000; |
|
|
|
|
45
|
|
|
} |
46
|
|
|
return ""; |
|
|
|
|
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
protected function isOK() |
50
|
|
|
{ |
51
|
|
|
$this->CheckMinMax(new \DateTime($this->value)); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
PHP provides two ways to mark string literals. Either with single quotes
'literal'
or with double quotes"literal"
. The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (
\'
) and the backslash (\\
). Every other character is displayed as is.Double quoted string literals may contain other variables or more complex escape sequences.
will print an indented:
Single is Value
If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.
For more information on PHP string literals and available escape sequences see the PHP core documentation.