Automattic\WooCommerce\Admin\API\Reports

DataStore::create_interval_subtotals()protectedWC 1.0

Change structure of intervals to form a correct response.

Also converts local datetimes to GMT and adds them to the intervals.

Method of the class: DataStore{}

No Hooks.

Return

null. Nothing (null).

Usage

// protected - for code of main (parent) or child class
$result = $this->create_interval_subtotals( $intervals );
$intervals(array) (required) (passed by reference — &)
Time interval, e.g. day, week, month.

DataStore::create_interval_subtotals() code WC 8.6.1

protected function create_interval_subtotals( &$intervals ) {
	foreach ( $intervals as $key => $interval ) {
		$start_gmt = TimeInterval::convert_local_datetime_to_gmt( $interval['date_start'] );
		$end_gmt   = TimeInterval::convert_local_datetime_to_gmt( $interval['date_end'] );
		// Move intervals result to subtotals object.
		$intervals[ $key ] = array(
			'interval'       => $interval['time_interval'],
			'date_start'     => $interval['date_start'],
			'date_start_gmt' => $start_gmt->format( TimeInterval::$sql_datetime_format ),
			'date_end'       => $interval['date_end'],
			'date_end_gmt'   => $end_gmt->format( TimeInterval::$sql_datetime_format ),
		);

		unset( $interval['interval'] );
		unset( $interval['date_start'] );
		unset( $interval['date_end'] );
		unset( $interval['datetime_anchor'] );
		unset( $interval['time_interval'] );
		$intervals[ $key ]['subtotals'] = (object) $this->cast_numbers( $interval );
	}
}