mirror of
https://github.com/pronamic/woocommerce-subscriptions.git
synced 2025-10-16 14:22:56 +00:00
2.4.5
This commit is contained in:

committed by
Remco Tolsma

parent
37367ac369
commit
721dda6e5c
107
includes/wcs-time-functions.php
Executable file → Normal file
107
includes/wcs-time-functions.php
Executable file → Normal 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.
|
||||
*
|
||||
|
Reference in New Issue
Block a user