Automattic\WooCommerce\Admin
ReportExporter::get_export_date_range
Get the date range a report export covers.
Reports are not all limited to a period. Stock, for one, has no date range at all.
Method of the class: ReportExporter{}
No Hooks.
Returns
string[]. The range's after and before dates as Y-m-d, or an empty array when the report has no range.
Usage
$result = ReportExporter::get_export_date_range( $report_args );
- $report_args(array) (required)
- Report parameters, passed to data query.
Changelog
| Since 11.2.0 | Introduced. |
ReportExporter::get_export_date_range() ReportExporter::get export date range code WC 11.2.1
public static function get_export_date_range( $report_args ) {
if ( ! is_array( $report_args ) ) {
return array();
}
$date_range = array();
foreach ( array( 'after', 'before' ) as $bound ) {
// Report args arrive from a REST request, so they hold whatever the caller sent. Take the
// date as written rather than converting it: the report reads these as store local time.
// The shape alone is not enough, since a date like 2025-06-31 would roll over to July 1.
if (
empty( $report_args[ $bound ] ) ||
! is_string( $report_args[ $bound ] ) ||
! preg_match( '/^(\d{4}-\d{2}-\d{2})/', $report_args[ $bound ], $matches ) ||
! TimeUtil::is_valid_date( $matches[1], 'Y-m-d' )
) {
return array();
}
$date_range[ $bound ] = $matches[1];
}
return $date_range;
}