Automattic\WooCommerce\Admin\API\Reports

TimeInterval::next_week_start()public staticWC 1.0

Returns DateTime object representing the next week start, or previous week end if reversed.

The next week start is the first day of the next week at 00:00:00. The previous week end is the last day of the previous week at 23:59:59. The start day is determined by the "start_of_week" wp_option.

Method of the class: TimeInterval{}

No Hooks.

Return

DateTime.

Usage

$result = TimeInterval::next_week_start( $datetime, $reversed );
$datetime(DateTime) (required)
Date and time.
$reversed(true|false)
Going backwards in time instead of forward.
Default: false

TimeInterval::next_week_start() code WC 7.3.0

public static function next_week_start( $datetime, $reversed = false ) {
	$seven_days = new \DateInterval( 'P7D' );
	// Default timezone set in wp-settings.php.
	$default_timezone = date_default_timezone_get();
	// Timezone that the WP site uses in Settings > General.
	$original_timezone = $datetime->getTimezone();
	// @codingStandardsIgnoreStart
	date_default_timezone_set( 'UTC' );
	$start_end_timestamp  = get_weekstartend( $datetime->format( 'Y-m-d' ) );
	date_default_timezone_set( $default_timezone );
	// @codingStandardsIgnoreEnd
	if ( $reversed ) {
		$result = \DateTime::createFromFormat( 'U', $start_end_timestamp['end'] )->sub( $seven_days );
	} else {
		$result = \DateTime::createFromFormat( 'U', $start_end_timestamp['start'] )->add( $seven_days );
	}
	return \DateTime::createFromFormat( 'Y-m-d H:i:s', $result->format( 'Y-m-d H:i:s' ), $original_timezone );
}