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.

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

Хуков нет.

Возвращает

null. Ничего (null).

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->normalize_timezones( $query_args, $defaults );
$query_args(массив) (обязательный) (передается по ссылке — &)
Array of query arguments.
$defaults(массив) (обязательный)
Array of default values.

Код DataStore::normalize_timezones() WC 9.8.5

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;
		}
	}
}