My first time on StackOverflow as a poster, normally just a browser, however I have run into an issue myself this time.
I have a script that sets certain variables based on what time it is.
<?php
// Sunday
if( in_array($day, array(Sun)) ){
echo 'Conditions = Day:' . $day . ' ' . 'Time: ' . $current_time;
if (($current_time >= '06:01') && ($current_time <= '10:00')) {
$stime = '06:00';
$etime = '10:00';
$showname = 'Dimitri Jegels';
$image = 'images/placeholder/on-air.jpg';
// echo $stime . ' and' . $etime . ' & ' . $showname . ' & ' . $image;
} elseif (($current_time >= '10:01') && ($current_time <= '14:00')) {
$stime = '10:00';
$etime = '14:00';
$showname = 'Benito Vergotine';
$image = 'images/placeholder/on-air.jpg';
// echo $stime . ' and' . $etime . ' & ' . $showname . ' & ' . $image;
} elseif (($current_time >= '14:01') && ($current_time <= '18:00')) {
$stime = '14:00';
$etime = '18:00';
$showname = 'Gavin Arends';
$image = 'images/placeholder/on-air.jpg';
// echo $stime . ' and' . $etime . ' & ' . $showname . ' & ' . $image;
} elseif (($current_time >= '18:01') && ($current_time <= '22:00')) {
$stime = '18:00';
$etime = '22:00';
$showname = 'Tracy Lange';
$image = 'images/placeholder/on-air.jpg';
// echo $stime . ' and' . $etime . ' & ' . $showname . ' & ' . $image;
} elseif (($current_time >= '22:01') && ($current_time <= '02:00')) {
$stime = '22:00';
$etime = '02:00';
$showname = 'Mehboob Bawa';
$image = 'images/placeholder/on-air.jpg';
// echo $stime . ' and' . $etime . ' & ' . $showname . ' & ' . $image;
} elseif (($current_time >= '02:01') && ($current_time <= '06:00')) {
$stime = '02:00';
$etime = '06:00';
$showname = 'Training Slot';
$image = 'images/placeholder/on-air.jpg';
// echo $stime . ' and' . $etime . ' & ' . $showname . ' & ' . $image;
} else {
$stime = '??:??';
$etime = '??:??';
$showname = 'There is a barnacle!';
}
}
?>
The script works fine, when it is for example 13:00, it checks between 10:00 & 14:00.
However, when the time is 23:30 and it checks between 22:00 & 02:00 it shows the "There is a barnacle!"
What I am assuming is that the jump from 22:00 into 02:00 confuses the script as 02:00 is less than 22:00 ?
Not the tidiest code or best method, but would like to know if anyone can suggest how I can overcome this?