Respect manual offsets in default before/after params (https://github.com/woocommerce/woocommerce-admin/pull/2042)
This commit is contained in:
parent
b134853e83
commit
dab7cf7dff
|
@ -44,8 +44,13 @@ class WC_Admin_Reports_Interval {
|
|||
* @return DateTime
|
||||
*/
|
||||
public static function default_before() {
|
||||
$datetime = new DateTime();
|
||||
$datetime->setTimezone( new DateTimeZone( wc_timezone_string() ) );
|
||||
$datetime = new WC_DateTime();
|
||||
// Set local timezone or offset.
|
||||
if ( get_option( 'timezone_string' ) ) {
|
||||
$datetime->setTimezone( new DateTimeZone( wc_timezone_string() ) );
|
||||
} else {
|
||||
$datetime->set_utc_offset( wc_timezone_offset() );
|
||||
}
|
||||
return $datetime;
|
||||
}
|
||||
|
||||
|
@ -58,9 +63,14 @@ class WC_Admin_Reports_Interval {
|
|||
$now = time();
|
||||
$week_back = $now - WEEK_IN_SECONDS;
|
||||
|
||||
$datetime = new DateTime();
|
||||
$datetime = new WC_DateTime();
|
||||
$datetime->setTimestamp( $week_back );
|
||||
$datetime->setTimezone( new DateTimeZone( wc_timezone_string() ) );
|
||||
// Set local timezone or offset.
|
||||
if ( get_option( 'timezone_string' ) ) {
|
||||
$datetime->setTimezone( new DateTimeZone( wc_timezone_string() ) );
|
||||
} else {
|
||||
$datetime->set_utc_offset( wc_timezone_offset() );
|
||||
}
|
||||
return $datetime;
|
||||
}
|
||||
|
||||
|
|
|
@ -572,13 +572,21 @@ class WC_Admin_Reports_Data_Store {
|
|||
);
|
||||
|
||||
if ( isset( $query_args['before'] ) && '' !== $query_args['before'] ) {
|
||||
$datetime_str = $query_args['before']->format( WC_Admin_Reports_Interval::$sql_datetime_format );
|
||||
if ( is_a( $query_args['before'], 'WC_DateTime' ) ) {
|
||||
$datetime_str = $query_args['before']->date( WC_Admin_Reports_Interval::$sql_datetime_format );
|
||||
} else {
|
||||
$datetime_str = $query_args['before']->format( WC_Admin_Reports_Interval::$sql_datetime_format );
|
||||
}
|
||||
$sql_query['where_time_clause'] .= " AND {$table_name}.date_created <= '$datetime_str'";
|
||||
|
||||
}
|
||||
|
||||
if ( isset( $query_args['after'] ) && '' !== $query_args['after'] ) {
|
||||
$datetime_str = $query_args['after']->format( WC_Admin_Reports_Interval::$sql_datetime_format );
|
||||
if ( is_a( $query_args['after'], 'WC_DateTime' ) ) {
|
||||
$datetime_str = $query_args['after']->date( WC_Admin_Reports_Interval::$sql_datetime_format );
|
||||
} else {
|
||||
$datetime_str = $query_args['after']->format( WC_Admin_Reports_Interval::$sql_datetime_format );
|
||||
}
|
||||
$sql_query['where_time_clause'] .= " AND {$table_name}.date_created >= '$datetime_str'";
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue