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 +80 -15 1.6.0 → 2.5.0 View file →
@@ -67,9 +67,9 @@
67 67 {
68 68 $timeZone = self::getTimeZone();
69 69
70 70 if (isset($_COOKIE['fluent_booking_user_timezone'])) {
71 - $timeZone = $_COOKIE['fluent_booking_user_timezone'];
71 + $timeZone = sanitize_text_field(wp_unslash($_COOKIE['fluent_booking_user_timezone']));
72 72 }
73 73
74 74 return $timeZone;
75 75 }
@@ -90,9 +90,8 @@
90 90 }
91 91
92 92 public static function convertToUtc($dateTime, $timezone, $format = 'Y-m-d H:i:s')
93 93 {
94 -
95 94 $timezone = self::getValidatedTimeZone($timezone);
96 95
97 96 $dateTime = new \DateTime($dateTime, new \DateTimeZone($timezone));
98 97 $dateTime->setTimezone(new \DateTimeZone('UTC'));
@@ -152,8 +151,19 @@
152 151 $dateTime->setTimezone(new \DateTimeZone($toTimeZone));
153 152 return $dateTime->format('Y-m-d H:i:s');
154 153 }
155 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 +
156 166 public static function getTimestamp($timezone = 'UTC')
157 167 {
158 168 $timezone = self::getValidatedTimeZone($timezone);
159 169 $dateTime = new \DateTime(gmdate('Y-m-d H:i:s'), new \DateTimeZone('UTC')); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
@@ -164,19 +174,29 @@
164 174
165 175 public static function formatToLocale($dateTime, $for = 'date')
166 176 {
167 177 // $for can be date | date_time | time
168 - $dateFormat = get_option('date_format');
178 + $dateFormat = (string) get_option('date_format', '');
169 179
170 180 if ($for == 'date_time') {
171 - $dateFormat .= ' ' . get_option('time_format');
181 + $dateFormat .= ' ' . (string) get_option('time_format', '');
172 182 } elseif ($for == 'time') {
173 - $dateFormat = get_option('time_format');
183 + $dateFormat = (string) get_option('time_format', '');
174 184 }
175 185
176 186 return date_i18n($dateFormat, strtotime($dateTime)); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
177 187 }
178 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 +
179 199 public static function getAvailableDateFormats()
180 200 {
181 201 $dateFormats = apply_filters('fluent_booking/available_date_formats', [
182 202 'm/d/Y' => 'm/d/Y - (Ex: 05/20/2024)', // USA
@@ -276,22 +296,14 @@
276 296
277 297 for ($i = 0; $i < strlen($phpFormat); $i++) {
278 298 $char = $phpFormat[$i];
279 299
280 - // Special handling for G\hi pattern
281 - if ($char === 'G' && $i + 2 < strlen($phpFormat) &&
282 - $phpFormat[$i + 1] === '\\' && $phpFormat[$i + 2] === 'h') {
283 - $dayjsFormat .= 'H[h]';
284 - $i += 2;
285 - continue;
286 - }
287 -
288 300 // Check if the character is escaped
289 301 if ($char === "\\") {
290 - // Add the next character to the result as is, without mapping
302 + // Day.js escapes literal text with square brackets, not backslashes
291 303 $i++;
292 304 if ($i < strlen($phpFormat)) {
293 - $dayjsFormat .= "\\" . $phpFormat[$i];
305 + $dayjsFormat .= "[" . $phpFormat[$i] . "]";
294 306 }
295 307 continue;
296 308 }
297 309
@@ -380,6 +392,59 @@
380 392 return !$isDstActive;
381 393 }
382 394
383 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 + ]);
384 449 }
385 450 }