Date   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 12
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A transform() 0 8 1
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