Date::fromUnixTime()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 1
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Popy\Calendar\Converter\UnixTimeConverter;
4
5
use Popy\Calendar\Converter\Conversion;
6
use Popy\Calendar\Converter\UnixTimeConverterInterface;
7
use Popy\Calendar\ValueObject\DateRepresentation\Standard;
8
9
/**
10
 * Day in the year representation
11
 *
12
 * Fragment units are, usually, named as, and used as :
13
 * 0 => months (format symbols m, etc ...)
14
 *
15
 * Transversal units are, usually, named as and used as :
16
 * 0 => ISO 8601 year (format symbol o).
17
 * 1 => ISO 8601 week number (format symbol W)
18
 * 2 => ISO 8601 day index (format symbol N)
19
 */
20
class Date implements UnixTimeConverterInterface
21
{
22
    /**
23
     * @inheritDoc
24
     */
25
    public function fromUnixTime(Conversion $conversion)
26
    {
27
        $from = $conversion->getFrom();
28
29
        $res = $conversion->getTo()
30
            ->withUnixTime($from->getUnixTime())
31
            ->withUnixMicroTime($from->getUnixMicroTime())
32
            ->withTimezone($from->getTimezone())
33
        ;
34
35
        $conversion->setTo($res);
36
    }
37
38
    /**
39
     * @inheritDoc
40
     */
41
    public function toUnixTime(Conversion $conversion)
42
    {
43
        $input = $conversion->getTo();
44
45
        if (null === $input->getUnixTime()) {
46
            $input = $input->withUnixTime($conversion->getUnixTime());
47
        }
48
49
        if (null === $input->getUnixMicroTime()) {
50
            $input = $input->withUnixMicroTime($conversion->getUnixMicroTime());
51
        }
52
53
        $conversion->setTo($input);
54
    }
55
}
56