Automattic\WooCommerce\Internal\PushNotifications\Entities

PushToken::validate_gmt_datetime │ private │ WC 1.0

Returns a GMT datetime as Y-m-d H:i:s, or null if it is not one.

Method of the class: PushToken{}

No Hooks.

Returns

string|null.

Usage

// private - for code of main (parent) class only
$result = $this->validate_gmt_datetime( ?string $datetime ): ?string;
?string $datetime(required)
.

PushToken::validate_gmt_datetime() code WC 11.3.0

private function validate_gmt_datetime( ?string $datetime ): ?string {
	$datetime = null === $datetime ? '' : trim( $datetime );

	if ( '' === $datetime || self::ZERO_DATETIME === $datetime ) {
		return null;
	}

	$normalized = str_replace( 'T', ' ', $datetime );

	if ( ! TimeUtil::is_valid_date( $normalized ) ) {
		wc_get_logger()->warning(
			'Unparseable push token timestamp.',
			array(
				'source'   => PushNotifications::FEATURE_NAME,
				'token_id' => $this->id,
				'value'    => $datetime,
			)
		);

		return null;
	}

	return $normalized;
}