DateTransformer::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Akeneo\Component\SpreadsheetParser\Xlsx;
4
5
/**
6
 * Transforms Excel dates in DateTime objects
7
 *
8
 * @author    Antoine Guigan <[email protected]>
9
 * @copyright 2014 Akeneo SAS (http://www.akeneo.com)
10
 * @license   http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
11
 */
12
class DateTransformer
13
{
14
    /**
15
     * @var \DateTime
16
     */
17
    protected $baseDate;
18
19
    /**
20
     * Constructor
21
     */
22
    public function __construct()
23
    {
24
        $this->baseDate = new \DateTime('1900-01-00 00:00:00 UTC');
25
    }
26
27
    /**
28
     * Transforms an Excel date into a DateTime object
29
     *
30
     * @param String $value
31
     *
32
     * @return \DateTime
33
     */
34
    public function transform($value)
35
    {
36
        $days = floor($value);
37
38
        $seconds = round(($value - $days) * 86400);
39
40
        $date = clone $this->baseDate;
41
        $date->modify(sprintf('+%sday +%ssecond', $days - 1, $seconds));
42
43
        return $date;
44
    }
45
}
46