Lines
100.00%
1 / 1
Functions and Methods
100.00%
1 / 1
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| PostgresValueCodec | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | 100.00% | 1 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace BlueprintAU\Radiant\Database\ValueCodecs; | |
| 6 | ||
| 7 | ||
| 8 | /** | |
| 9 | * The Postgres value codec — formats `DateTimeInterface` values with | |
| 10 | * microsecond precision. | |
| 11 | * | |
| 12 | * Postgres' native `timestamp` type stores microsecond precision, so on the | |
| 13 | * write path datetimes must be formatted as `Y-m-d H:i:s.u`. On the read | |
| 14 | * path pdo_pgsql returns `timestamp` columns as strings in the same format, | |
| 15 | * and PostgreSQL casts numeric/bool columns to PHP native types itself, so | |
| 16 | * the inherited identity `decode()` is correct. | |
| 17 | */ | |
| 18 | final class PostgresValueCodec extends DefaultValueCodec | |
| 19 | { | |
| 20 | /** | |
| 21 | * @param string $timezone | |
| 22 | */ | |
| 23 | public function __construct(string $timezone = 'UTC') | |
| 24 | { | |
| 25 | parent::__construct('Y-m-d H:i:s.u', $timezone); | |
| 26 | } | |
| 27 | } |