Automattic\WooCommerce\Admin\API\Reports

TimeInterval::normalize_between_params()public staticWC 1.0

Normalize "_between" parameters to "_min" and "_max" for numeric values and "_after" and "*_before" for date values.

Method of the class: TimeInterval{}

No Hooks.

Return

Array. Normalized query values.

Usage

$result = TimeInterval::normalize_between_params( $request, $param_names, $is_date );
$request(array) (required)
Query params from REST API request.
$param_names(string|array) (required)
One or more param names to handle. Should not include "_between" suffix.
$is_date(true|false) (required)
Boolean if the param is date is related.

TimeInterval::normalize_between_params() code WC 8.6.1

public static function normalize_between_params( $request, $param_names, $is_date ) {
	if ( ! is_array( $param_names ) ) {
		$param_names = array( $param_names );
	}

	$normalized = array();

	foreach ( $param_names as $param_name ) {
		if ( ! is_array( $request[ $param_name . '_between' ] ) ) {
			continue;
		}

		$range = $request[ $param_name . '_between' ];

		if ( 2 !== count( $range ) ) {
			continue;
		}

		$min = $is_date ? '_after' : '_min';
		$max = $is_date ? '_before' : '_max';

		if ( $range[0] < $range[1] ) {
			$normalized[ $param_name . $min ] = $range[0];
			$normalized[ $param_name . $max ] = $range[1];
		} else {
			$normalized[ $param_name . $min ] = $range[1];
			$normalized[ $param_name . $max ] = $range[0];
		}
	}

	return $normalized;
}