Passed
Push — master ( 709652...05719e )
by Pol
06:35 queued 04:41
created

DotNetTimeConverter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toDatetime() 0 5 1
A toTicks() 0 3 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
        $timestamp = (string) ((int) (((float) $ticks - self::OFFSET) / self::MULTIPLIER));
25
26 1
        return DateTimeImmutable::createFromFormat('U', $timestamp);
27
    }
28
29 1
    public function toTicks(DateTimeInterface $datetime): string
30
    {
31 1
        return (string) (int) (($datetime->getTimestamp() * self::MULTIPLIER) + self::OFFSET);
32
    }
33
}
34