ActionScheduler_TimezoneHelper::set_local_timezone()public staticWC 2.1.0

Set a DateTime's timezone to the WordPress site's timezone, or a UTC offset if no timezone string is available.

Method of the class: ActionScheduler_TimezoneHelper{}

No Hooks.

Return

ActionScheduler_DateTime.

Usage

$result = ActionScheduler_TimezoneHelper::set_local_timezone( $date );
$date(DateTime) (required)
-

Changelog

Since 2.1.0 Introduced.

ActionScheduler_TimezoneHelper::set_local_timezone() code WC 9.3.3

public static function set_local_timezone( DateTime $date ) {

	// Accept a DateTime for easier backward compatibility, even though we require methods on ActionScheduler_DateTime
	if ( ! is_a( $date, 'ActionScheduler_DateTime' ) ) {
		$date = as_get_datetime_object( $date->format( 'U' ) );
	}

	if ( get_option( 'timezone_string' ) ) {
		$date->setTimezone( new DateTimeZone( self::get_local_timezone_string() ) );
	} else {
		$date->setUtcOffset( self::get_local_timezone_offset() );
	}

	return $date;
}