Completed
Pull Request — master (#144)
by Markus
01:01
created

Timestamp::fromCurrentTime()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the eluceo/iCal package.
5
 *
6
 * (c) 2019 Markus Poerschke <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Eluceo\iCal\Domain\ValueObject;
13
14
use DateTimeImmutable as PhpDateTimeImmutable;
15
use DateTimeInterface as PhpDateTimeInterface;
16
17
class Timestamp extends PointInTime
18
{
19
    public static function fromDateTimeInterface(PhpDateTimeInterface $dateTime): self
20
    {
21
        return new static(
22
            PhpDateTimeImmutable::createFromFormat(
23
                PhpDateTimeInterface::ATOM,
24
                $dateTime->format(PhpDateTimeInterface::ATOM), $dateTime->getTimezone()
25
            )
26
        );
27
    }
28
29
    public static function fromCurrentTime(): self
30
    {
31
        return static::fromDateTimeInterface(new PhpDateTimeImmutable());
32
    }
33
}
34