Verfeinere Sichtbarkeitsfarben der Planeten
This commit is contained in:
+22
-4
@@ -58,6 +58,16 @@ if (!function_exists('intervalOverlapSeconds')) {
|
|||||||
return max(0, $end - $start);
|
return max(0, $end - $start);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!function_exists('intervalDurationSeconds')) {
|
||||||
|
function intervalDurationSeconds(?DateTimeImmutable $start, ?DateTimeImmutable $end): int
|
||||||
|
{
|
||||||
|
if ($start === null || $end === null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return max(0, $end->getTimestamp() - $start->getTimestamp());
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!function_exists('planetVisibleIntervalsForDay')) {
|
if (!function_exists('planetVisibleIntervalsForDay')) {
|
||||||
function planetVisibleIntervalsForDay(array $planet, DateTimeImmutable $dayStart, DateTimeImmutable $dayEnd): array
|
function planetVisibleIntervalsForDay(array $planet, DateTimeImmutable $dayStart, DateTimeImmutable $dayEnd): array
|
||||||
{
|
{
|
||||||
@@ -101,19 +111,27 @@ if (!function_exists('planetVisibilityClass')) {
|
|||||||
|
|
||||||
$nightSeconds = 0;
|
$nightSeconds = 0;
|
||||||
$twilightSeconds = 0;
|
$twilightSeconds = 0;
|
||||||
|
$visibleSeconds = 0;
|
||||||
|
|
||||||
foreach ($intervals as [$from, $to]) {
|
foreach ($intervals as [$from, $to]) {
|
||||||
|
$visibleSeconds += intervalDurationSeconds($from, $to);
|
||||||
$nightSeconds += intervalOverlapSeconds($from, $to, $astroDusk, $astroDawnNext);
|
$nightSeconds += intervalOverlapSeconds($from, $to, $astroDusk, $astroDawnNext);
|
||||||
$twilightSeconds += intervalOverlapSeconds($from, $to, $civilDusk, $astroDusk);
|
$twilightSeconds += intervalOverlapSeconds($from, $to, $civilDusk, $astroDusk);
|
||||||
$twilightSeconds += intervalOverlapSeconds($from, $to, $astroDawnNext, $civilDawnNext);
|
$twilightSeconds += intervalOverlapSeconds($from, $to, $astroDawnNext, $civilDawnNext);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($nightSeconds > 0) {
|
if ($visibleSeconds <= 0) {
|
||||||
return ['class' => 'planet-visibility-good', 'label' => 'nachts gut'];
|
return ['class' => 'planet-visibility-bad', 'label' => 'am Tag'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($twilightSeconds > 0) {
|
$nightRatio = $nightSeconds / $visibleSeconds;
|
||||||
return ['class' => 'planet-visibility-warn', 'label' => 'in der Daemmerung'];
|
|
||||||
|
if ($nightSeconds >= 3600 && $nightRatio >= 0.35) {
|
||||||
|
return ['class' => 'planet-visibility-good', 'label' => 'nachts gut sichtbar'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (($nightSeconds + $twilightSeconds) > 0) {
|
||||||
|
return ['class' => 'planet-visibility-warn', 'label' => 'nur teilweise nachts / in der Dämmerung'];
|
||||||
}
|
}
|
||||||
|
|
||||||
return ['class' => 'planet-visibility-bad', 'label' => 'am Tag'];
|
return ['class' => 'planet-visibility-bad', 'label' => 'am Tag'];
|
||||||
|
|||||||
Reference in New Issue
Block a user