Test Failed
Pull Request — master (#28)
by Christopher
02:23
created

xsDateTime::fixFractionOfSecond()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
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
        $dateTimeValue = new \DateTime($this->value);
38
        $this->value = $dateTimeValue->format('Y-m-d\TH:i:s') . $this->fixFractionOfSecond($dateTimeValue) . $dateTimeValue->format('P');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 137 characters

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.

Loading history...
39
    }
40
41
    private function fixFractionOfSecond(\DateTime $dateTimeValue)
42
    {
43
        if (0 != (int)$dateTimeValue->format('u')) {
44
            return '.' . $dateTimeValue->format('u') / 100000;
45
        }
46
        return '';
47
    }
48
49
    protected function isOK()
50
    {
51
        $this->CheckMinMax(new \DateTime($this->value));
52
    }
53
}
54