| | |
| | | <?php |
| | | |
| | | use JVBase\base\Options; |
| | | use JVBase\base\options; |
| | | use JVBase\managers\Cache; |
| | | use JVBase\meta\Meta; |
| | | |
| | |
| | | * Format a date in relative time (e.g., "2 days ago") |
| | | * @param string $dateStr - Date string or DateTime object |
| | | * @return string - Formatted relative time |
| | | * @throws DateMalformedStringException |
| | | */ |
| | | function jvbFormatTimeAgo(string $dateStr):string |
| | | { |
| | |
| | | */ |
| | | function jvbRenderHours(int $ID, string $type = ''):string |
| | | { |
| | | $cache = Cache::for('hours_display', WEEK_IN_SECONDS)->connect('taxonomy')->connect('post')->connect('user'); |
| | | if (!$type) { |
| | | return ''; |
| | | } |
| | | $cache = Cache::for('hours_display_'.$type, $type, WEEK_IN_SECONDS); |
| | | |
| | | $cached = $cache->get($ID); |
| | | |
| | |
| | | $out = ''; |
| | | |
| | | if (!empty($hours) && jvbHasOperatingHours($hours)) { |
| | | $out = jvbGetFormattedHours($hours, true, true); |
| | | $out = jvbGetFormattedHours($hours); |
| | | } else { |
| | | $out = '<p class="no-hours">Hours not available</p>'; |
| | | } |
| | |
| | | /** |
| | | * Check if business is currently open based on stored hours |
| | | * |
| | | * @param array $hours_data Array of hours data from wp_option |
| | | * @param array|null $hours_data Array of hours data from wp_option |
| | | * @param string $timezone Timezone string (default: 'America/Edmonton') |
| | | * @return bool True if currently open, false if closed |
| | | * @throws DateInvalidTimeZoneException |
| | | * @throws DateMalformedStringException |
| | | */ |
| | | function jvbIsCurrentlyOpen(?array $hours_data = null, string $timezone = 'America/Edmonton'):bool |
| | | { |
| | | // Get hours data if not provided |
| | | if ($hours_data === null) { |
| | | $hours_data = Options::get('openingHours'); |
| | | $hours_data = options::get('openingHours'); |
| | | } |
| | | |
| | | // Return false if no hours data |
| | |
| | | * @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 |
| | | * @throws DateInvalidTimeZoneException |
| | | * @throws DateMalformedStringException |
| | | */ |
| | | function jvbIsTimeBetween(?string $start_time = null, ?string $end_time = null, string $timezone = 'America/Edmonton'):bool { |
| | | if (!$start_time && !$end_time) { |
| | | $hours = Options::get('today_hours'); |
| | | $hours = options::get('today_hours'); |
| | | $start_time = $hours['time_start']; |
| | | $end_time = $hours['time_end']; |
| | | } |
| | |
| | | * @param string $timezone Timezone string |
| | | * @return string Next opening time description or empty string if never opens |
| | | * @throws DateInvalidTimeZoneException |
| | | * @throws DateMalformedStringException |
| | | */ |
| | | function jvbGetNextOpeningTime(array $hours_data, string $timezone = 'America/Edmonton'):string { |
| | | if (!jvbHasOperatingHours($hours_data)) { |