PluginProbe ʕ •ᴥ•ʔ
WP Mail SMTP by WPForms – The Most Popular SMTP and Email Log Plugin / 3.11.0
WP Mail SMTP by WPForms – The Most Popular SMTP and Email Log Plugin v3.11.0
4.9.0 0.9.6 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.6.0 1.6.2 1.7.0 1.7.1 1.8.0 1.8.1 1.9.0 2.0.0 2.0.1 2.1.1 2.2.1 2.3.1 2.4.0 2.5.0 2.5.1 2.6.0 2.7.0 2.8.0 2.9.0 3.0.1 3.0.2 3.0.3 3.1.0 3.10.0 3.11.0 3.11.1 3.2.0 3.2.1 3.3.0 3.4.0 3.5.0 3.5.1 3.5.2 3.6.1 3.7.0 3.8.0 3.8.2 3.9.0 4.0.1 4.1.0 4.1.1 4.2.0 4.3.0 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.8.0 trunk 0.10.0 0.10.1 0.11.1 0.11.2 0.3.1 0.3.2 0.4 0.4.1 0.4.2 0.5.0 0.5.1 0.5.2 0.6 0.7 0.8 0.8.2 0.8.3 0.8.4 0.8.5 0.8.6 0.8.7 0.9.0 0.9.1 0.9.2 0.9.3 0.9.4 0.9.5
wp-mail-smtp / vendor / woocommerce / action-scheduler / classes / abstracts / ActionScheduler_TimezoneHelper.php
wp-mail-smtp / vendor / woocommerce / action-scheduler / classes / abstracts Last commit date
ActionScheduler.php 2 years ago ActionScheduler_Abstract_ListTable.php 2 years ago ActionScheduler_Abstract_QueueRunner.php 2 years ago ActionScheduler_Abstract_RecurringSchedule.php 2 years ago ActionScheduler_Abstract_Schedule.php 2 years ago ActionScheduler_Abstract_Schema.php 2 years ago ActionScheduler_Lock.php 2 years ago ActionScheduler_Logger.php 2 years ago ActionScheduler_Store.php 2 years ago ActionScheduler_TimezoneHelper.php 2 years ago
ActionScheduler_TimezoneHelper.php
153 lines
1 <?php
2
3 /**
4 * Class ActionScheduler_TimezoneHelper
5 */
6 abstract class ActionScheduler_TimezoneHelper {
7 private static $local_timezone = NULL;
8
9 /**
10 * Set a DateTime's timezone to the WordPress site's timezone, or a UTC offset
11 * if no timezone string is available.
12 *
13 * @since 2.1.0
14 *
15 * @param DateTime $date
16 * @return ActionScheduler_DateTime
17 */
18 public static function set_local_timezone( DateTime $date ) {
19
20 // Accept a DateTime for easier backward compatibility, even though we require methods on ActionScheduler_DateTime
21 if ( ! is_a( $date, 'ActionScheduler_DateTime' ) ) {
22 $date = as_get_datetime_object( $date->format( 'U' ) );
23 }
24
25 if ( get_option( 'timezone_string' ) ) {
26 $date->setTimezone( new DateTimeZone( self::get_local_timezone_string() ) );
27 } else {
28 $date->setUtcOffset( self::get_local_timezone_offset() );
29 }
30
31 return $date;
32 }
33
34 /**
35 * Helper to retrieve the timezone string for a site until a WP core method exists
36 * (see https://core.trac.wordpress.org/ticket/24730).
37 *
38 * Adapted from wc_timezone_string() and https://secure.php.net/manual/en/function.timezone-name-from-abbr.php#89155.
39 *
40 * If no timezone string is set, and its not possible to match the UTC offset set for the site to a timezone
41 * string, then an empty string will be returned, and the UTC offset should be used to set a DateTime's
42 * timezone.
43 *
44 * @since 2.1.0
45 * @return string PHP timezone string for the site or empty if no timezone string is available.
46 */
47 protected static function get_local_timezone_string( $reset = false ) {
48 // If site timezone string exists, return it.
49 $timezone = get_option( 'timezone_string' );
50 if ( $timezone ) {
51 return $timezone;
52 }
53
54 // Get UTC offset, if it isn't set then return UTC.
55 $utc_offset = intval( get_option( 'gmt_offset', 0 ) );
56 if ( 0 === $utc_offset ) {
57 return 'UTC';
58 }
59
60 // Adjust UTC offset from hours to seconds.
61 $utc_offset *= 3600;
62
63 // Attempt to guess the timezone string from the UTC offset.
64 $timezone = timezone_name_from_abbr( '', $utc_offset );
65 if ( $timezone ) {
66 return $timezone;
67 }
68
69 // Last try, guess timezone string manually.
70 foreach ( timezone_abbreviations_list() as $abbr ) {
71 foreach ( $abbr as $city ) {
72 if ( (bool) date( 'I' ) === (bool) $city['dst'] && $city['timezone_id'] && intval( $city['offset'] ) === $utc_offset ) {
73 return $city['timezone_id'];
74 }
75 }
76 }
77
78 // No timezone string
79 return '';
80 }
81
82 /**
83 * Get timezone offset in seconds.
84 *
85 * @since 2.1.0
86 * @return float
87 */
88 protected static function get_local_timezone_offset() {
89 $timezone = get_option( 'timezone_string' );
90
91 if ( $timezone ) {
92 $timezone_object = new DateTimeZone( $timezone );
93 return $timezone_object->getOffset( new DateTime( 'now' ) );
94 } else {
95 return floatval( get_option( 'gmt_offset', 0 ) ) * HOUR_IN_SECONDS;
96 }
97 }
98
99 /**
100 * @deprecated 2.1.0
101 */
102 public static function get_local_timezone( $reset = FALSE ) {
103 _deprecated_function( __FUNCTION__, '2.1.0', 'ActionScheduler_TimezoneHelper::set_local_timezone()' );
104 if ( $reset ) {
105 self::$local_timezone = NULL;
106 }
107 if ( !isset(self::$local_timezone) ) {
108 $tzstring = get_option('timezone_string');
109
110 if ( empty($tzstring) ) {
111 $gmt_offset = get_option('gmt_offset');
112 if ( $gmt_offset == 0 ) {
113 $tzstring = 'UTC';
114 } else {
115 $gmt_offset *= HOUR_IN_SECONDS;
116 $tzstring = timezone_name_from_abbr( '', $gmt_offset, 1 );
117
118 // If there's no timezone string, try again with no DST.
119 if ( false === $tzstring ) {
120 $tzstring = timezone_name_from_abbr( '', $gmt_offset, 0 );
121 }
122
123 // Try mapping to the first abbreviation we can find.
124 if ( false === $tzstring ) {
125 $is_dst = date( 'I' );
126 foreach ( timezone_abbreviations_list() as $abbr ) {
127 foreach ( $abbr as $city ) {
128 if ( $city['dst'] == $is_dst && $city['offset'] == $gmt_offset ) {
129 // If there's no valid timezone ID, keep looking.
130 if ( null === $city['timezone_id'] ) {
131 continue;
132 }
133
134 $tzstring = $city['timezone_id'];
135 break 2;
136 }
137 }
138 }
139 }
140
141 // If we still have no valid string, then fall back to UTC.
142 if ( false === $tzstring ) {
143 $tzstring = 'UTC';
144 }
145 }
146 }
147
148 self::$local_timezone = new DateTimeZone($tzstring);
149 }
150 return self::$local_timezone;
151 }
152 }
153