DotNetTimeConverter::toDatetime()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 10
1
<?php
2
3
/**
4
 * For the full copyright and license information, please view
5
 * the LICENSE file that was distributed with this source code.
6
 */
7
8
declare(strict_types=1);
9
10
namespace ChampsLibres\WopiLib\Service\Utils;
11
12
use ChampsLibres\WopiLib\Contract\Service\Utils\DotNetTimeConverterInterface;
13
use DateTimeImmutable;
14
use DateTimeInterface;
15
16
final class DotNetTimeConverter implements DotNetTimeConverterInterface
17
{
18
    private const MULTIPLIER = 1e7;
19
20
    private const OFFSET = 621355968e9;
21
22 1
    public function toDatetime(string $ticks): DateTimeInterface
23
    {
24 1
        return DateTimeImmutable::createFromFormat(
25 1
            'U',
26 1
            (string) ((int) (((float) $ticks - self::OFFSET) / self::MULTIPLIER))
27 1
        );
28
    }
29
30 1
    public function toTicks(DateTimeInterface $datetime): string
31
    {
32 1
        return (string) (int) (($datetime->getTimestamp() * self::MULTIPLIER) + self::OFFSET);
33
    }
34
}
35