PluginProbe
Booktics – Appointment Booking Calendar for Service Businesses / 1.0.27
Booktics – Appointment Booking Calendar for Service Businesses v1.0.27
1.0.29 1.0.28 1.0.27 1.0.26 1.0.25 1.0.24 1.0.23 1.0.22 1.0.21 1.0.20 1.0.19 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.2 1.0.3 All 31 releases
← All changes | base/services/time-zone-handler.php +28 -0 1.0.3 → 1.0.27 View file →
@@ -18,8 +18,13 @@
18 18 *
19 19 * @return array Array containing converted 'time' and 'date'
20 20 */
21 21 public static function convert_to_utc( string $time, string $date, string $timezone ) {
22 + // If date already contains timezone information, use it directly
23 + if (strpos($date, 'T') !== false) {
24 + $date = substr($date, 0, strpos($date, 'T')); // Extract just the date part (before the 'T')
25 + }
26 +
22 27 $datetime = new DateTime( "$date $time", new DateTimeZone( $timezone ) );
23 28 $datetime->setTimezone( new DateTimeZone( 'UTC' ) );
24 29
25 30 return array(
@@ -61,6 +66,29 @@
61 66 * @return bool
62 67 */
63 68 public static function validate_time_zone( string $timezone ) {
64 69 return in_array( $timezone, DateTimeZone::listIdentifiers() );
70 + }
71 +
72 + /**
73 + * Handles timezone string to DateTimeZone object conversion
74 + * In case the timezone string is invalid, returns default timezone
75 + * If timezone is already a DateTimeZone object, returns it as it is
76 + *
77 + * @param string|DateTimeZone $timezone Timezone string
78 + *
79 + * @return DateTimeZone
80 + */
81 + public static function get_timezone_from_string( $timezone ) {
82 + // If timezone is already a DateTimeZone object, return as it is
83 + if ( $timezone instanceof DateTimeZone ) {
84 + return $timezone;
85 + }
86 + // Incase of invalid timezone string, return default timezone
87 + if ( ! is_string( $timezone ) ) {
88 + return wp_timezone();
89 + }
90 +
91 + // Validate and return a DateTimeZone object
92 + return self::validate_time_zone( $timezone ) ? new DateTimeZone($timezone) : wp_timezone();
65 93 }
66 94 }