Automattic\WooCommerce\Internal\Api\Autogenerated\GraphQLTypes\Scalars

DateTime::get │ public static │ WC 1.0

Method of the class: DateTime{}

No Hooks.

Returns

null. Nothing (null).

Usage

$result = DateTime::get(): CustomScalarType;

DateTime::get() code WC 11.1.2

public static function get(): CustomScalarType {
	if ( null === self::$instance ) {
		self::$instance = new CustomScalarType(
			array(
				'name'         => 'DateTime',
				'description'  => __( 'An ISO 8601 encoded date and time string.', 'woocommerce' ),
				'serialize'    => fn( $value ) => DateTimeScalar::serialize( $value ),
				'parseValue'   => function ( $value ) {
					try {
						return DateTimeScalar::parse( $value );
					} catch ( \InvalidArgumentException $e ) {
						throw new \Automattic\WooCommerce\Api\Infrastructure\Schema\Error( $e->getMessage() );
					}
				},
				'parseLiteral' => function ( $value_node, ?array $variables = null ) {
					if ( $value_node instanceof \Automattic\WooCommerce\Api\Infrastructure\Schema\AST\StringValueNode ) {
						try {
							return DateTimeScalar::parse( $value_node->value );
						} catch ( \InvalidArgumentException $e ) {
							throw new \Automattic\WooCommerce\Api\Infrastructure\Schema\Error( $e->getMessage() );
						}
					}
					throw new \Automattic\WooCommerce\Api\Infrastructure\Schema\Error(
						'DateTime must be a string, got: ' . $value_node->kind
					);
				},
			)
		);
	}
	return self::$instance;
}