This commit is contained in:
Prospress Inc
2018-12-12 14:48:11 +01:00
committed by Remco Tolsma
parent 37367ac369
commit 721dda6e5c
340 changed files with 5114 additions and 2125 deletions

107
includes/wcs-time-functions.php Executable file → Normal file
View File

@@ -705,63 +705,76 @@ function wcs_get_days_in_cycle( $period, $interval ) {
}
/**
* Get an instance of the site's timezone.
* Set a DateTime's timezone to the WordPress site's timezone, or a UTC offset
* if no timezone string is available.
*
* @return DateTimeZone Timezone object for the timezone the site is using.
* @since 2.4.2
* @param WC_DateTime $date
* @return WC_DateTime
*/
function wcs_get_sites_timezone() {
if ( class_exists( 'ActionScheduler_TimezoneHelper' ) ) {
// Use Action Scheduler's version when possible as it caches the data
$local_timezone = ActionScheduler_TimezoneHelper::get_local_timezone();
function wcs_set_local_timezone( WC_DateTime $date ) {
if ( get_option( 'timezone_string' ) ) {
$date->setTimezone( new DateTimeZone( wc_timezone_string() ) );
} else {
$tzstring = get_option( 'timezone_string' );
if ( empty( $tzstring ) ) {
$gmt_offset = get_option( 'gmt_offset' );
if ( 0 == $gmt_offset ) {
$tzstring = 'UTC';
} else {
$gmt_offset *= HOUR_IN_SECONDS;
$tzstring = timezone_name_from_abbr( '', $gmt_offset );
if ( false === $tzstring ) {
$is_dst = date( 'I' );
foreach ( timezone_abbreviations_list() as $abbr ) {
foreach ( $abbr as $city ) {
if ( $city['dst'] == $is_dst && $city['offset'] == $gmt_offset ) {
$tzstring = $city['timezone_id'];
break 2;
}
}
}
}
if ( false === $tzstring ) {
$tzstring = 'UTC';
}
}
}
$local_timezone = new DateTimeZone( $tzstring );
$date->set_utc_offset( wc_timezone_offset() );
}
return $local_timezone;
return $date;
}
/* Deprecated Functions */
/**
* Get an instance of the site's timezone.
*
* @return DateTimeZone Timezone object for the timezone the site is using.
* @deprecated 2.4.2
*/
function wcs_get_sites_timezone() {
_deprecated_function( __FUNCTION__, '2.4.2' );
$tzstring = get_option( 'timezone_string' );
if ( empty( $tzstring ) ) {
$gmt_offset = get_option( 'gmt_offset' );
if ( 0 == $gmt_offset ) {
$tzstring = 'UTC';
} else {
$gmt_offset *= HOUR_IN_SECONDS;
$tzstring = timezone_name_from_abbr( '', $gmt_offset );
if ( false === $tzstring ) {
$is_dst = date( 'I' );
foreach ( timezone_abbreviations_list() as $abbr ) {
foreach ( $abbr as $city ) {
if ( $city['dst'] == $is_dst && $city['offset'] == $gmt_offset ) {
$tzstring = $city['timezone_id'];
break 2;
}
}
}
}
if ( false === $tzstring ) {
$tzstring = 'UTC';
}
}
}
$local_timezone = new DateTimeZone( $tzstring );
return $local_timezone;
}
/**
* Returns an array of subscription lengths.
*