Automattic\WooCommerce\Internal\DataStores\Orders

OrdersTableQuery::date_to_date_query_arg()privateWC 1.0

Generates a WP_Date_Query compatible query from a given date. YYYY-MM-DD queries have 'day' precision for backwards compatibility.

Method of the class: OrdersTableQuery{}

No Hooks.

Return

Array. An array with keys 'year', 'month', 'day' and possibly 'hour', 'minute' and 'second'.

Usage

// private - for code of main (parent) class only
$result = $this->date_to_date_query_arg( $date ): array;
$date(mixed) (required)
The date. Can be a WC_DateTime{}, a timestamp or a string.

OrdersTableQuery::date_to_date_query_arg() code WC 7.1.0

private function date_to_date_query_arg( $date ): array {
	$result    = array(
		'year'  => '',
		'month' => '',
		'day'   => '',
	);
	$precision = 'second';

	if ( is_numeric( $date ) ) {
		$date = new \WC_DateTime( "@{$date}", new \DateTimeZone( 'UTC' ) );
	} elseif ( ! is_a( $date, 'WC_DateTime' ) ) {
		// YYYY-MM-DD queries have 'day' precision for backwards compat.
		$date      = wc_string_to_datetime( $date );
		$precision = 'day';
	}

	$result['year']  = $date->date( 'Y' );
	$result['month'] = $date->date( 'm' );
	$result['day']   = $date->date( 'd' );

	if ( 'second' === $precision ) {
		$result['hour']   = $date->date( 'H' );
		$result['minute'] = $date->date( 'i' );
		$result['second'] = $date->date( 's' );
	}

	return $result;
}