Date::transform()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types = 1);
2
3
namespace Spaghetti\XLSXParser\Transformer;
4
5
use DateTimeImmutable;
6
7
use function date_create_immutable_from_format;
8
use function floor;
9
use function gmdate;
10
11
/**
12
 * @internal
13
 */
14
final class Date
15
{
16
    private const DATETIME_FORMAT = 'd-m-Y H:i:s';
17
18
    public function transform(float|int $value): DateTimeImmutable
19
    {
20
        $value = (int) floor(num: $value);
21
        /** @noinspection SummerTimeUnsafeTimeManipulationInspection */
22
        $unix = ($value - 25569) * 86400;
23
        $date = gmdate(format: self::DATETIME_FORMAT, timestamp: $unix);
24
25
        return date_create_immutable_from_format(format: '!' . self::DATETIME_FORMAT, datetime: $date);
26
    }
27
}
28