Automattic\WooCommerce\Internal\Admin\Reports
HposLegacyOrderReportQueryBuilder::hpos_local_date_expr
Build a MySQL expression that converts orders.date_created_gmt into site-local time.
For sites configured with a named timezone (e.g. Europe/Berlin) the conversion is done per row with CONVERT_TZ() so DST is honoured and rows near midnight bucket into the correct day/month. CONVERT_TZ() returns NULL when the server's timezone tables are not loaded, so it falls back to {@see self::build_transition_fallback_expr()}. Sites using a manual UTC offset have no DST, so a fixed-offset shift is exact and is used directly.
Method of the class: HposLegacyOrderReportQueryBuilder{}
No Hooks.
Returns
string. SQL fragment that produces a local DATETIME.
Usage
// private - for code of main (parent) class only $result = $this->hpos_local_date_expr(): string;
HposLegacyOrderReportQueryBuilder::hpos_local_date_expr() HposLegacyOrderReportQueryBuilder::hpos local date expr code WC 11.1.2
private function hpos_local_date_expr(): string {
$timezone_string = get_option( 'timezone_string' );
if ( '' === $timezone_string ) {
$schema = $this->get_report_schema();
return "DATE_ADD(orders.date_created_gmt, INTERVAL {$schema['gmt_offset']} SECOND)";
}
global $wpdb;
$convert = $wpdb->prepare( 'CONVERT_TZ(orders.date_created_gmt, %s, %s)', '+00:00', $timezone_string );
return "IFNULL({$convert}, {$this->build_transition_fallback_expr()})";
}