-
Notifications
You must be signed in to change notification settings - Fork 0
/
TimestampIntegerType.php
49 lines (44 loc) · 993 Bytes
/
TimestampIntegerType.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
/**
* PHP version 8.1
*
* @package Saschati\ValueObject\Types\Specials
*/
namespace Saschati\ValueObject\Types\Flats;
use DateTimeImmutable;
use DateTimeInterface;
use Exception;
use Saschati\ValueObject\Types\Flats\Interfaces\FlatInterface;
/**
* Class TimestampIntegerType
*
* Converting an integer to a DateTimeImmutable.
*
* @see DateTimeImmutable
*/
class TimestampIntegerType implements FlatInterface
{
/**
* @param integer|mixed $value
*
* @return DateTimeInterface|null
*
* @throws Exception
*/
public static function convertToPhpValue(mixed $value): ?DateTimeInterface
{
if ($value === null) {
return null;
}
return (new DateTimeImmutable())->setTimestamp($value);
}
/**
* @param DateTimeInterface|mixed $value
*
* @return integer|null
*/
public static function convertToDatabaseValue($value): ?int
{
return $value?->getTimestamp();
}
}