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

DateTime{}WC 1.0

No Hooks.

Usage

$DateTime = new DateTime();
// use class methods

Methods

  1. public static get()
  2. public fn( $value ) => DateTimeScalar::serialize( $value )
  3. ERROR: no method name found on line `}`

DateTime{} code WC 10.8.1

class DateTime {
	private static ?CustomScalarType $instance = null;

	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\Internal\Api\Schema\Error( $e->getMessage() );
						}
					},
					'parseLiteral' => function ( $value_node, ?array $variables = null ) {
						if ( $value_node instanceof \Automattic\WooCommerce\Internal\Api\Schema\AST\StringValueNode ) {
							try {
								return DateTimeScalar::parse( $value_node->value );
							} catch ( \InvalidArgumentException $e ) {
								throw new \Automattic\WooCommerce\Internal\Api\Schema\Error( $e->getMessage() );
							}
						}
						throw new \Automattic\WooCommerce\Internal\Api\Schema\Error(
							'DateTime must be a string, got: ' . $value_node->kind
						);
					},
				)
			);
		}
		return self::$instance;
	}
}