GraphQL Create datetime type #2644
parent
1fde6cc054
commit
1b45923bf3
@ -0,0 +1,6 @@ |
||||
DateTime: |
||||
type: custom-scalar |
||||
config: |
||||
serialize: ["Chamilo\\ApiBundle\\GraphQL\\Type\\DateTimeType", "serialize"] |
||||
parseValue: ["Chamilo\\ApiBundle\\GraphQL\\Type\\DateTimeType", "parseValue"] |
||||
parseLiteral: ["Chamilo\\ApiBundle\\GraphQL\\Type\\DateTimeType", "parseLiteral"] |
@ -0,0 +1,44 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\ApiBundle\GraphQL\Type; |
||||
|
||||
use GraphQL\Language\AST\Node; |
||||
|
||||
/** |
||||
* Class DateTimeType |
||||
* |
||||
* @package Chamilo\ApiBundle\GraphQL\Type |
||||
*/ |
||||
class DateTimeType |
||||
{ |
||||
/** |
||||
* @param \DateTime $value |
||||
* |
||||
* @return string |
||||
*/ |
||||
public static function serialize(\DateTime $value) |
||||
{ |
||||
return $value->format(\DateTime::ATOM); |
||||
} |
||||
|
||||
/** |
||||
* @param string $value |
||||
* |
||||
* @return \DateTime |
||||
*/ |
||||
public static function parseValue(string $value) |
||||
{ |
||||
return new \DateTime($value, new \DateTimeZone('UTC')); |
||||
} |
||||
|
||||
/** |
||||
* @param Node $valueNode |
||||
* |
||||
* @return \DateTime |
||||
*/ |
||||
public static function parseLiteral(Node $valueNode) |
||||
{ |
||||
return new \DateTime($valueNode->value, new \DateTimeZone('UTC')); |
||||
} |
||||
} |
Loading…
Reference in new issue