diff --git a/functions.php b/functions.php index 6369ca7..ffcfda4 100644 --- a/functions.php +++ b/functions.php @@ -70,10 +70,10 @@ class LightStatus { $startTime = strtotime($this->times[$timeKey]['on']); $stopTime = strtotime($this->times[$timeKey]['off']); if ($stopTime < $startTime) { - $stopTime += (24 * 60 * 60); - if (($stopTime - $currentTime) > (24 * 60 * 60)) { - $startTime -= (24 * 60 * 60); - $stopTime -= (24 * 60 * 60); + $stopTime += (24*60*60); + if (($stopTime - $currentTime) > (24*60*60)) { + $startTime -= (24*60*60); + $stopTime -= (24*60*60); } } @@ -82,6 +82,16 @@ class LightStatus { $this->changeTime = (int)(($stopTime - $currentTime) / 60); $this->waitTime = 1; return true; + } elseif ($currentTime < $startTime || ($startTime+(24*60*60) - $currentTime) < (12*60*60) ) { + // right before the next time interval + $this->state = false; + if ($currentTime < $startTime) { + $this->changeTime = (int)( ($startTime - $currentTime) / 60 ); + } else { + $this->changeTime = (int)( (($startTime+(24*60*60)) - $currentTime) / 60 ); + } + $this->waitTime = 1; + return true; } } diff --git a/index.php b/index.php index 84bc50b..24ecaec 100644 --- a/index.php +++ b/index.php @@ -69,8 +69,8 @@ if (isset($_GET['action'])) { -
-