/
githubmirror
/
ydb-php-sdk
Обзор
Документация
Войти
/
githubmirror
/
ydb-php-sdk
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Types/DateType.php
68 строк
1 KB
Alexei Shabalin
namespace updated
20 дек 2022, 15:20
20 дек 2022, 15:20
e4410bc
Код
Авторство
О чём код?
<?php namespace YdbPlatform\Ydb\Types; use DateTime; use Exception; class DateType extends AbstractType { /** * @var string */ protected static $date_format = 'Y-m-d'; /** * @inherit */ protected $ydb_key_name = 'uint32_value'; /** * @inherit */ protected $ydb_type = 'DATE'; /** * @inherit * @throws Exception */ protected function normalizeValue($value) { if (is_a($value, DateTime::class)) { $value = $value->format(static::$date_format); } else if (is_int($value)) { $value = date(static::$date_format, $value); } else if (is_string($value)) { $value = new DateTime($value); $value = $value->format(static::$date_format); } else { throw new Exception('YDB Casting failed for date value'); } return $value; } /** * @inherit */ protected function getYqlString() { return 'Date(' . $this->quoteString($this->value) . ')'; } /** * @inherit */ protected function getYdbValue() { $value = new DateTime($this->value); return $value->getTimestamp() / 86400; } }