| @@ 12-35 (lines=24) @@ | ||
| 9 | namespace Youshido\GraphQL\Type\Scalar; |
|
| 10 | ||
| 11 | ||
| 12 | class DateTimeType extends AbstractScalarType |
|
| 13 | { |
|
| 14 | ||
| 15 | /** |
|
| 16 | * @param $value \DateTime |
|
| 17 | * @return null|string |
|
| 18 | */ |
|
| 19 | public function serialize($value) |
|
| 20 | { |
|
| 21 | if ($value === null) { |
|
| 22 | return null; |
|
| 23 | } |
|
| 24 | ||
| 25 | return $value->format('Y-m-d H:i:s'); |
|
| 26 | } |
|
| 27 | ||
| 28 | public function isValidValue($value) |
|
| 29 | { |
|
| 30 | $d = \DateTime::createFromFormat('Y-m-d H:i:s', $value); |
|
| 31 | ||
| 32 | return $d && $d->format('Y-m-d H:i:s') == $value; |
|
| 33 | } |
|
| 34 | ||
| 35 | } |
|
| @@ 12-35 (lines=24) @@ | ||
| 9 | namespace Youshido\GraphQL\Type\Scalar; |
|
| 10 | ||
| 11 | ||
| 12 | class DateType extends AbstractScalarType |
|
| 13 | { |
|
| 14 | ||
| 15 | /** |
|
| 16 | * @param $value \DateTime |
|
| 17 | * @return null|string |
|
| 18 | */ |
|
| 19 | public function serialize($value) |
|
| 20 | { |
|
| 21 | if ($value === null) { |
|
| 22 | return null; |
|
| 23 | } |
|
| 24 | ||
| 25 | return $value->format('Y-m-d'); |
|
| 26 | } |
|
| 27 | ||
| 28 | public function isValidValue($value) |
|
| 29 | { |
|
| 30 | $d = \DateTime::createFromFormat('Y-m-d', $value); |
|
| 31 | ||
| 32 | return $d && $d->format('Y-m-d') == $value; |
|
| 33 | } |
|
| 34 | ||
| 35 | } |
|