What are the best practices for handling shop opening hours that extend past midnight in PHP?

When handling shop opening hours that extend past midnight in PHP, it is important to account for the change in date when comparing the current time to the opening and closing hours. This can be achieved by checking if the closing hour is before the opening hour, and if so, adjusting the comparison accordingly.

// Example code snippet for handling shop opening hours that extend past midnight

$current_time = date('H:i');
$opening_time = '20:00'; // Shop opens at 8:00 PM
$closing_time = '02:00'; // Shop closes at 2:00 AM

if ($closing_time < $opening_time) {
    if ($current_time >= $opening_time || $current_time < $closing_time) {
        echo "Shop is open";
    } else {
        echo "Shop is closed";
    }
} else {
    if ($current_time >= $opening_time && $current_time < $closing_time) {
        echo "Shop is open";
    } else {
        echo "Shop is closed";
    }
}