PluginProbe
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution / 2.5.0
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution v2.5.0
2.5.0 2.4.0 2.3.0 2.2.5 2.2.0 2.1.2 2.1.1 trunk 1.10.0 1.10.01 1.10.02 1.5.0 1.5.01 1.5.02 1.5.1 1.5.10 1.5.20 1.5.21 1.5.22 1.5.23 1.5.24 1.5.25 1.6.0 1.7.0 1.7.1 All 34 releases
← All changes | app/Services/DateTimeHelper.php +107 -6 1.5.20 → 2.5.0 View file →
@@ -62,8 +62,19 @@
62 62
63 63 return $timeZone;
64 64 }
65 65
66 + public static function guessTimeZone()
67 + {
68 + $timeZone = self::getTimeZone();
69 +
70 + if (isset($_COOKIE['fluent_booking_user_timezone'])) {
71 + $timeZone = sanitize_text_field(wp_unslash($_COOKIE['fluent_booking_user_timezone']));
72 + }
73 +
74 + return $timeZone;
75 + }
76 +
66 77 public static function getValidatedTimeZone($requestedTimeZone)
67 78 {
68 79 static $cached = [];
69 80 if (isset($cached[$requestedTimeZone])) {
@@ -79,9 +90,8 @@
79 90 }
80 91
81 92 public static function convertToUtc($dateTime, $timezone, $format = 'Y-m-d H:i:s')
82 93 {
83 -
84 94 $timezone = self::getValidatedTimeZone($timezone);
85 95
86 96 $dateTime = new \DateTime($dateTime, new \DateTimeZone($timezone));
87 97 $dateTime->setTimezone(new \DateTimeZone('UTC'));
@@ -141,8 +151,19 @@
141 151 $dateTime->setTimezone(new \DateTimeZone($toTimeZone));
142 152 return $dateTime->format('Y-m-d H:i:s');
143 153 }
144 154
155 + public static function getIsoDurationInMinutes($duration)
156 + {
157 + if (!$duration) {
158 + return 0;
159 + }
160 +
161 + $duration = new \DateInterval($duration);
162 +
163 + return ($duration->d * 24 * 60) + ($duration->h * 60) + ($duration->i) + ($duration->s / 60);
164 + }
165 +
145 166 public static function getTimestamp($timezone = 'UTC')
146 167 {
147 168 $timezone = self::getValidatedTimeZone($timezone);
148 169 $dateTime = new \DateTime(gmdate('Y-m-d H:i:s'), new \DateTimeZone('UTC')); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
@@ -153,19 +174,29 @@
153 174
154 175 public static function formatToLocale($dateTime, $for = 'date')
155 176 {
156 177 // $for can be date | date_time | time
157 - $dateFormat = get_option('date_format');
178 + $dateFormat = (string) get_option('date_format', '');
158 179
159 180 if ($for == 'date_time') {
160 - $dateFormat .= ' ' . get_option('time_format');
181 + $dateFormat .= ' ' . (string) get_option('time_format', '');
161 182 } elseif ($for == 'time') {
162 - $dateFormat = get_option('time_format');
183 + $dateFormat = (string) get_option('time_format', '');
163 184 }
164 185
165 186 return date_i18n($dateFormat, strtotime($dateTime)); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
166 187 }
167 188
189 + public static function getFormattedDate($date, $from = '', $to = 'Y-m-d')
190 + {
191 + if (!$from) {
192 + $from = (string) get_option('date_format', '');
193 + }
194 +
195 + $date = \DateTime::createFromFormat($from, $date);
196 + return $date ? $date->format($to) : '';
197 + }
198 +
168 199 public static function getAvailableDateFormats()
169 200 {
170 201 $dateFormats = apply_filters('fluent_booking/available_date_formats', [
171 202 'm/d/Y' => 'm/d/Y - (Ex: 05/20/2024)', // USA
@@ -189,8 +220,21 @@
189 220 }
190 221 return $formatted;
191 222 }
192 223
224 + public static function getFormattedEventTime($eventTime)
225 + {
226 + $timeZone = self::guessTimeZone();
227 +
228 + $convertedTime = self::convertToTimeZone($eventTime, 'UTC', $timeZone);
229 +
230 + $eventTime = self::formatToLocale($convertedTime, 'time');
231 +
232 + $eventDate = self::formatToLocale($convertedTime, 'date');
233 +
234 + return $eventTime . ', ' . $eventDate . ' (' . $timeZone . ')';
235 + }
236 +
193 237 public static function convertPhpDateToDayJSFormay($phpFormat)
194 238 {
195 239 // Mapping PHP date format characters to Day.js format characters
196 240 $replacements = [
@@ -254,12 +298,12 @@
254 298 $char = $phpFormat[$i];
255 299
256 300 // Check if the character is escaped
257 301 if ($char === "\\") {
258 - // Add the next character to the result as is, without mapping
302 + // Day.js escapes literal text with square brackets, not backslashes
259 303 $i++;
260 304 if ($i < strlen($phpFormat)) {
261 - $dayjsFormat .= "\\" . $phpFormat[$i];
305 + $dayjsFormat .= "[" . $phpFormat[$i] . "]";
262 306 }
263 307 continue;
264 308 }
265 309
@@ -343,7 +387,64 @@
343 387 $dateTimeObject = new \DateTime($dateTime, new \DateTimeZone($timezone));
344 388
345 389 $isDstActive = $dateTimeObject->format('I');
346 390
391 + if ($timezone == 'Europe/Dublin') {
392 + return !$isDstActive;
393 + }
394 +
347 395 return $isDstActive;
396 + }
397 +
398 + public static function getI18nDateTimeConfig()
399 + {
400 + return apply_filters('fluent_booking/i18n_date_time_config', [
401 + 'weekdays' => array(
402 + 'sunday' => _x('Sunday', 'calendar day full', 'fluent-booking'),
403 + 'monday' => _x('Monday', 'calendar day full', 'fluent-booking'),
404 + 'tuesday' => _x('Tuesday', 'calendar day full', 'fluent-booking'),
405 + 'wednesday' => _x('Wednesday', 'calendar day full', 'fluent-booking'),
406 + 'thursday' => _x('Thursday', 'calendar day full', 'fluent-booking'),
407 + 'friday' => _x('Friday', 'calendar day full', 'fluent-booking'),
408 + 'saturday' => _x('Saturday', 'calendar day full', 'fluent-booking'),
409 + ),
410 + 'months' => array(
411 + 'January' => _x('January', 'calendar month name full', 'fluent-booking'),
412 + 'February' => _x('February', 'calendar month name full', 'fluent-booking'),
413 + 'March' => _x('March', 'calendar month name full', 'fluent-booking'),
414 + 'April' => _x('April', 'calendar month name full', 'fluent-booking'),
415 + 'May' => _x('May', 'calendar month name full', 'fluent-booking'),
416 + 'June' => _x('June', 'calendar month name full', 'fluent-booking'),
417 + 'July' => _x('July', 'calendar month name full', 'fluent-booking'),
418 + 'August' => _x('August', 'calendar month name full', 'fluent-booking'),
419 + 'September' => _x('September', 'calendar month name full', 'fluent-booking'),
420 + 'October' => _x('October', 'calendar month name full', 'fluent-booking'),
421 + 'November' => _x('November', 'calendar month name full', 'fluent-booking'),
422 + 'December' => _x('December', 'calendar month name full', 'fluent-booking')
423 + ),
424 + 'weekdaysShort' => array(
425 + 'sun' => _x('Sun', 'calendar day short', 'fluent-booking'),
426 + 'mon' => _x('Mon', 'calendar day short', 'fluent-booking'),
427 + 'tue' => _x('Tue', 'calendar day short', 'fluent-booking'),
428 + 'wed' => _x('Wed', 'calendar day short', 'fluent-booking'),
429 + 'thu' => _x('Thu', 'calendar day short', 'fluent-booking'),
430 + 'fri' => _x('Fri', 'calendar day short', 'fluent-booking'),
431 + 'sat' => _x('Sat', 'calendar day short', 'fluent-booking')
432 + ),
433 + 'monthsShort' => array(
434 + 'jan' => _x('Jan', 'calendar month name short', 'fluent-booking'),
435 + 'feb' => _x('Feb', 'calendar month name short', 'fluent-booking'),
436 + 'mar' => _x('Mar', 'calendar month name short', 'fluent-booking'),
437 + 'apr' => _x('Apr', 'calendar month name short', 'fluent-booking'),
438 + 'may' => _x('May', 'calendar month name short', 'fluent-booking'),
439 + 'jun' => _x('Jun', 'calendar month name short', 'fluent-booking'),
440 + 'jul' => _x('Jul', 'calendar month name short', 'fluent-booking'),
441 + 'aug' => _x('Aug', 'calendar month name short', 'fluent-booking'),
442 + 'sep' => _x('Sep', 'calendar month name short', 'fluent-booking'),
443 + 'oct' => _x('Oct', 'calendar month name short', 'fluent-booking'),
444 + 'nov' => _x('Nov', 'calendar month name short', 'fluent-booking'),
445 + 'dec' => _x('Dec', 'calendar month name short', 'fluent-booking')
446 + ),
447 + 'numericSystem' => _x('0_1_2_3_4_5_6_7_8_9', 'calendar numeric system - Sequence must need to maintained', 'fluent-booking'),
448 + ]);
348 449 }
349 450 }