1 | <?php |
||
22 | final class DateTimeTypeAdapter extends TypeAdapter |
||
23 | { |
||
24 | /** |
||
25 | * @var TypeToken |
||
26 | */ |
||
27 | private $type; |
||
28 | |||
29 | /** |
||
30 | * @var string |
||
31 | */ |
||
32 | private $format; |
||
33 | |||
34 | /** |
||
35 | * Constructor |
||
36 | * |
||
37 | * @param TypeToken $type |
||
38 | * @param string $format |
||
39 | */ |
||
40 | 5 | public function __construct(TypeToken $type, string $format) |
|
45 | |||
46 | /** |
||
47 | * Read the next value, convert it to its type and return it |
||
48 | * |
||
49 | * @param JsonReadable $reader |
||
50 | * @return DateTime|null |
||
51 | * @throws \Tebru\Gson\Exception\JsonSyntaxException If the DateTime could not be created from format |
||
52 | */ |
||
53 | 3 | public function read(JsonReadable $reader): ?DateTime |
|
78 | |||
79 | /** |
||
80 | * Write the value to the writer for the type |
||
81 | * |
||
82 | * @param JsonWritable $writer |
||
83 | * @param DateTime $value |
||
84 | * @return void |
||
85 | */ |
||
86 | 2 | public function write(JsonWritable $writer, $value): void |
|
97 | } |
||
98 |