| @@ -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 |
| @@ -278,12 +298,12 @@ | ||
| 278 | 298 | $char = $phpFormat[$i]; |
| 279 | 299 | |
| 280 | 300 | // Check if the character is escaped |
| 281 | 301 | if ($char === "\\") { |
| 282 | - // Add the next character to the result as is, without mapping | |
| 302 | + // Day.js escapes literal text with square brackets, not backslashes | |
| 283 | 303 | $i++; |
| 284 | 304 | if ($i < strlen($phpFormat)) { |
| 285 | - $dayjsFormat .= "\\" . $phpFormat[$i]; | |
| 305 | + $dayjsFormat .= "[" . $phpFormat[$i] . "]"; | |
| 286 | 306 | } |
| 287 | 307 | continue; |
| 288 | 308 | } |
| 289 | 309 | |
| @@ -367,7 +387,64 @@ | ||
| 367 | 387 | $dateTimeObject = new \DateTime($dateTime, new \DateTimeZone($timezone)); |
| 368 | 388 | |
| 369 | 389 | $isDstActive = $dateTimeObject->format('I'); |
| 370 | 390 | |
| 391 | + if ($timezone == 'Europe/Dublin') { | |
| 392 | + return !$isDstActive; | |
| 393 | + } | |
| 394 | + | |
| 371 | 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 | + ]); | |
| 372 | 449 | } |
| 373 | 450 | } |