DotNetTimeConverter   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 17
ccs 7
cts 7
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toTicks() 0 3 1
A toDatetime() 0 5 1
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