From 715e26a9eb219808d5c899d418e1d596f9318f61 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Mon, 22 Jun 2026 16:59:19 +0000
Subject: [PATCH] =Debugging and implementing the Checkout.js logic. Will be uploading to test integration with square next.
---
inc/helpers/time.php | 43 ++++++++++++++++++++++---------------------
1 files changed, 22 insertions(+), 21 deletions(-)
diff --git a/inc/helpers/time.php b/inc/helpers/time.php
index e83d48b..4c3483c 100644
--- a/inc/helpers/time.php
+++ b/inc/helpers/time.php
@@ -1,5 +1,6 @@
<?php
+use JVBase\base\Options;
use JVBase\managers\Cache;
use JVBase\meta\Meta;
@@ -163,7 +164,7 @@
return '';
}
- $hours = $meta->get('hours');
+ $hours = $meta->get('openingHours');
$byAppt = $meta->get('by_appointment');
$walkins = $meta->get('walkins');
@@ -311,10 +312,11 @@
* @param string $timezone Timezone string (default: 'America/Edmonton')
* @return bool True if currently open, false if closed
*/
-function jvbIsCurrentlyOpen($hours_data = null, $timezone = 'America/Edmonton') {
+function jvbIsCurrentlyOpen(?array $hours_data = null, string $timezone = 'America/Edmonton'):bool
+{
// Get hours data if not provided
if ($hours_data === null) {
- $hours_data = get_option(BASE.'hours', []);
+ $hours_data = Options::get('openingHours');
}
// Return false if no hours data
@@ -331,12 +333,12 @@
$today_hours = $hours_data[$current_day] ?? [];
// Return false if closed today
- if (empty($today_hours) || !($today_hours['open'] ?? false)) {
+ if (empty($today_hours) || !($today_hours['isOpen'] ?? false)) {
return false;
}
- $open_time = $today_hours['time_opens'] ?? '';
- $close_time = $today_hours['time_closes'] ?? '';
+ $open_time = $today_hours['opens'] ?? '';
+ $close_time = $today_hours['closes'] ?? '';
if (!$open_time || !$close_time) {
return false;
@@ -359,14 +361,14 @@
/**
* Check if current time is between two specified times
*
- * @param string $start_time Start time in H:i format (e.g., '10:00')
- * @param string $end_time End time in H:i format (e.g., '15:15')
+ * @param ?string $start_time Start time in H:i format (e.g., '10:00')
+ * @param ?string $end_time End time in H:i format (e.g., '15:15')
* @param string $timezone Timezone string (default: 'America/Edmonton')
* @return bool True if current time is within range, false otherwise
*/
-function jvbIsTimeBetween($start_time=null, $end_time=null, $timezone = 'America/Edmonton') {
+function jvbIsTimeBetween(?string $start_time = null, ?string $end_time = null, string $timezone = 'America/Edmonton'):bool {
if (!$start_time && !$end_time) {
- $hours = get_option(BASE.'today_hours');
+ $hours = Options::get('today_hours');
$start_time = $hours['time_start'];
$end_time = $hours['time_end'];
}
@@ -394,16 +396,15 @@
*
* @param array $hours_data Day-based hours data
* @param string $timezone Timezone string
- * @return string|null Next opening time description or null if never opens
+ * @return string Next opening time description or empty string if never opens
* @throws DateInvalidTimeZoneException
*/
-function jvbGetNextOpeningTime(array $hours_data, string $timezone = 'America/Edmonton'): ?string {
+function jvbGetNextOpeningTime(array $hours_data, string $timezone = 'America/Edmonton'):string {
if (!jvbHasOperatingHours($hours_data)) {
- return null;
+ return '';
}
$current_time = new DateTime('now', new DateTimeZone($timezone));
- $weekdays = jvbFullWeekdays();
// Check next 7 days
for ($i = 0; $i < 7; $i++) {
@@ -412,11 +413,11 @@
$day_name = strtolower($check_date->format('l'));
$day_data = $hours_data[$day_name] ?? [];
- if (empty($day_data) || !($day_data['open'] ?? false)) {
+ if (empty($day_data) || !($day_data['isOpen'] ?? false)) {
continue;
}
- $open_time = $day_data['time_opens'] ?? '';
+ $open_time = $day_data['opens'] ?? '';
if (!$open_time) {
continue;
}
@@ -437,16 +438,16 @@
// Format the result
if ($i === 0) {
- return 'Opens today at ' . jvbFormat12HourTime($open_time);
+ return ' Opens today at ' . jvbFormat12HourTime($open_time);
} elseif ($i === 1) {
- return 'Opens tomorrow at ' . jvbFormat12HourTime($open_time);
+ return ' Opens tomorrow at ' . jvbFormat12HourTime($open_time);
} else {
$day_formatted = ucfirst($day_name);
- return "Opens {$day_formatted} at " . jvbFormat12HourTime($open_time);
+ return " Opens {$day_formatted} at " . jvbFormat12HourTime($open_time);
}
}
- return null;
+ return '';
}
@@ -458,7 +459,7 @@
*/
function jvbHasOperatingHours(array $hours_data): bool {
foreach ($hours_data as $day_data) {
- if (!empty($day_data) && ($day_data['open'] ?? false)) {
+ if (!empty($day_data) && ($day_data['isOpen'] ?? false)) {
return true;
}
}
--
Gitblit v1.10.0