Automattic\WooCommerce\Internal\Admin\Reports
HposLegacyOrderReportQueryBuilder::build_gmt_date_predicate
Build a sargable predicate on orders.date_created_gmt for a plain post_date row.
Translating post_date the column in the per-row local-time expression, which stops MySQL from using the date index. For the common shape — a bare post_date a scalar comparison operator and a date/datetime value (e.g. the sales sparkline's only date bound, post_date > 'Y-m-d') — the boundary is converted to UTC in PHP instead and compared against the raw GMT column, matching what {@see self::build_filter_range_where_clause()} does for filter_range bounds.
Method of the class: HposLegacyOrderReportQueryBuilder{}
No Hooks.
Returns
string|null. Predicate SQL, or null when the row is not a plain post_date comparison.
Usage
// private - for code of main (parent) class only $result = $this->build_gmt_date_predicate( $value ): ?string;
- $value(array) (required)
- A
whererow.
HposLegacyOrderReportQueryBuilder::build_gmt_date_predicate() HposLegacyOrderReportQueryBuilder::build gmt date predicate code WC 11.1.2
private function build_gmt_date_predicate( array $value ): ?string {
$key = trim( (string) ( $value['key'] ?? '' ) );
if ( 'post_date' !== $key && 'posts.post_date' !== $key ) {
return null;
}
$rhs = $value['value'] ?? '';
if ( ! in_array( $value['operator'], array( '=', '!=', '<', '<=', '>', '>=' ), true ) || ! is_string( $rhs ) ) {
return null;
}
$gmt = $this->local_datetime_to_gmt( $rhs );
if ( null === $gmt ) {
return null;
}
global $wpdb;
return "orders.date_created_gmt {$value['operator']} " . $wpdb->prepare( '%s', $gmt );
}