Automattic\WooCommerce\Admin\API\Reports

DataStore::normalize_timezones()protectedWC 1.0

Converts input datetime parameters to local timezone. If there are no inputs from the user in query_args, uses default from $defaults.

Method of the class: DataStore{}

No Hooks.

Return

null. Nothing (null).

Usage

// protected - for code of main (parent) or child class
$result = $this->normalize_timezones( $query_args, $defaults );
$query_args(array) (required) (passed by reference — &)
Array of query arguments.
$defaults(array) (required)
Array of default values.

DataStore::normalize_timezones() code WC 8.7.0

protected function normalize_timezones( &$query_args, $defaults ) {
	$local_tz = new \DateTimeZone( wc_timezone_string() );
	foreach ( array( 'before', 'after' ) as $query_arg_key ) {
		if ( isset( $query_args[ $query_arg_key ] ) && is_string( $query_args[ $query_arg_key ] ) ) {
			// Assume that unspecified timezone is a local timezone.
			$datetime = new \DateTime( $query_args[ $query_arg_key ], $local_tz );
			// In case timezone was forced by using +HH:MM, convert to local timezone.
			$datetime->setTimezone( $local_tz );
			$query_args[ $query_arg_key ] = $datetime;
		} elseif ( isset( $query_args[ $query_arg_key ] ) && is_a( $query_args[ $query_arg_key ], 'DateTime' ) ) {
			// In case timezone is in other timezone, convert to local timezone.
			$query_args[ $query_arg_key ]->setTimezone( $local_tz );
		} else {
			$query_args[ $query_arg_key ] = isset( $defaults[ $query_arg_key ] ) ? $defaults[ $query_arg_key ] : null;
		}
	}
}