Skip to content

Commit

Permalink
Merge pull request #3 from bartv2/DateType
Browse files Browse the repository at this point in the history
Use DateTimeType for DateType implementation
  • Loading branch information
Matys333 authored May 29, 2024
2 parents b47d16d + 62a20d0 commit f0144ba
Showing 1 changed file with 5 additions and 25 deletions.
30 changes: 5 additions & 25 deletions src/Type/Scalar/DateType.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,16 @@
* Class DateType
* @package Youshido\GraphQL\Type\Scalar
*/
class DateType extends AbstractScalarType
class DateType extends DateTimeType
{

public function getName(): string
public function __construct()
{
return 'Date';
parent::__construct('Y-m-d');
}

/**
* @param $value DateTime
* @return null|string
*/
public function serialize($value): mixed
{
if ($value === null) {
return null;
}

return $value->format('Y-m-d');
}

public function isValidValue(mixed $value): bool
public function getName(): string
{
if (is_null($value) || is_object($value)) {
return true;
}

$d = DateTime::createFromFormat('Y-m-d', $value);

return $d && $d->format('Y-m-d') == $value;
return 'Date';
}

public function getDescription(): string
Expand Down

0 comments on commit f0144ba

Please sign in to comment.