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.

Метод класса: OrdersTableQuery{}

Хуков нет.

Возвращает

Массив. An array with keys 'year', 'month', 'day' and possibly 'hour', 'minute' and 'second'.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->date_to_date_query_arg( $date ): array;
$date(разное) (обязательный)
The date. Can be a WC_DateTime{}, a timestamp or a string.

Код OrdersTableQuery::date_to_date_query_arg() WC 8.7.0

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

	$precision = null;
	if ( is_numeric( $date ) ) {
		$date      = new \WC_DateTime( "@{$date}", new \DateTimeZone( 'UTC' ) );
		$precision = 'second';
	} elseif ( ! is_a( $date, 'WC_DateTime' ) ) {
		// For backwards compat (see https://github.com/woocommerce/woocommerce/wiki/wc_get_orders-and-WC_Order_Query#date)
		// only YYYY-MM-DD is considered for date values. Timestamps do support second precision.
		$date      = wc_string_to_datetime( date( 'Y-m-d', strtotime( $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;
}