Verfeinere Sichtbarkeitsfarben der Planeten

This commit is contained in:
2026-05-27 10:46:25 +02:00
parent 9fd373ed47
commit f14f31712a
+22 -4
View File
@@ -58,6 +58,16 @@ if (!function_exists('intervalOverlapSeconds')) {
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')) {
function planetVisibleIntervalsForDay(array $planet, DateTimeImmutable $dayStart, DateTimeImmutable $dayEnd): array
{
@@ -101,19 +111,27 @@ if (!function_exists('planetVisibilityClass')) {
$nightSeconds = 0;
$twilightSeconds = 0;
$visibleSeconds = 0;
foreach ($intervals as [$from, $to]) {
$visibleSeconds += intervalDurationSeconds($from, $to);
$nightSeconds += intervalOverlapSeconds($from, $to, $astroDusk, $astroDawnNext);
$twilightSeconds += intervalOverlapSeconds($from, $to, $civilDusk, $astroDusk);
$twilightSeconds += intervalOverlapSeconds($from, $to, $astroDawnNext, $civilDawnNext);
}
if ($nightSeconds > 0) {
return ['class' => 'planet-visibility-good', 'label' => 'nachts gut'];
if ($visibleSeconds <= 0) {
return ['class' => 'planet-visibility-bad', 'label' => 'am Tag'];
}
if ($twilightSeconds > 0) {
return ['class' => 'planet-visibility-warn', 'label' => 'in der Daemmerung'];
$nightRatio = $nightSeconds / $visibleSeconds;
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'];