Automattic\WooCommerce\Admin

ReportExporter::format_date_range_bound │ private static │ WC 1.0

Format one end of a report's date range for display.

Method of the class: ReportExporter{}

No Hooks.

Returns

string. The date in the store's date format, or an empty string when it cannot be read.

Usage

$result = ReportExporter::format_date_range_bound( $date );
$date(string) (required)
Date as Y-m-d.

ReportExporter::format_date_range_bound() code WC 11.3.0

private static function format_date_range_bound( $date ) {
	// Read in the store's own timezone, so the date reads back as the merchant picked it and a
	// date format that names the timezone names theirs rather than UTC. Midday is a safe anchor.
	$parsed = \DateTimeImmutable::createFromFormat( 'Y-m-d H:i:s', $date . ' 12:00:00', wp_timezone() );

	if ( false === $parsed ) {
		return '';
	}

	return (string) wp_date( wc_date_format(), $parsed->getTimestamp() );
}