Startseite verbessert
This commit is contained in:
+121
-1
@@ -31,6 +31,94 @@ if (!function_exists('formatDurationHoursMinutes')) {
|
||||
return sprintf('%d Minuten', $restMinutes);
|
||||
}
|
||||
}
|
||||
if (!function_exists('eventDateTime')) {
|
||||
function eventDateTime(array $event): ?DateTimeImmutable
|
||||
{
|
||||
if (empty($event['found']) || empty($event['local_iso'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return new DateTimeImmutable((string)$event['local_iso']);
|
||||
} catch (Exception) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!function_exists('intervalOverlapSeconds')) {
|
||||
function intervalOverlapSeconds(?DateTimeImmutable $aStart, ?DateTimeImmutable $aEnd, ?DateTimeImmutable $bStart, ?DateTimeImmutable $bEnd): int
|
||||
{
|
||||
if ($aStart === null || $aEnd === null || $bStart === null || $bEnd === null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$start = max($aStart->getTimestamp(), $bStart->getTimestamp());
|
||||
$end = min($aEnd->getTimestamp(), $bEnd->getTimestamp());
|
||||
|
||||
return max(0, $end - $start);
|
||||
}
|
||||
}
|
||||
if (!function_exists('planetVisibleIntervalsForDay')) {
|
||||
function planetVisibleIntervalsForDay(array $planet, DateTimeImmutable $dayStart, DateTimeImmutable $dayEnd): array
|
||||
{
|
||||
$rise = eventDateTime($planet['rise'] ?? []);
|
||||
$set = eventDateTime($planet['set'] ?? []);
|
||||
|
||||
if ($rise && $set) {
|
||||
if ($rise <= $set) {
|
||||
return [[$rise, $set]];
|
||||
}
|
||||
|
||||
return [
|
||||
[$dayStart, $set],
|
||||
[$rise, $dayEnd],
|
||||
];
|
||||
}
|
||||
|
||||
if ($rise) {
|
||||
return [[$rise, $dayEnd]];
|
||||
}
|
||||
|
||||
if ($set) {
|
||||
return [[$dayStart, $set]];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
if (!function_exists('planetVisibilityClass')) {
|
||||
function planetVisibilityClass(array $planet, DateTimeImmutable $dayStart, DateTimeImmutable $dayEnd, array $ev, array $evNext): array
|
||||
{
|
||||
$intervals = planetVisibleIntervalsForDay($planet, $dayStart, $dayEnd);
|
||||
if ($intervals === []) {
|
||||
return ['class' => 'planet-visibility-bad', 'label' => 'am Tag'];
|
||||
}
|
||||
|
||||
$astroDusk = eventDateTime($ev['astro_dusk'] ?? []);
|
||||
$astroDawnNext = eventDateTime($evNext['astro_dawn'] ?? []);
|
||||
$civilDusk = eventDateTime($ev['civil_dusk'] ?? []);
|
||||
$civilDawnNext = eventDateTime($evNext['civil_dawn'] ?? []);
|
||||
|
||||
$nightSeconds = 0;
|
||||
$twilightSeconds = 0;
|
||||
|
||||
foreach ($intervals as [$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 ($twilightSeconds > 0) {
|
||||
return ['class' => 'planet-visibility-warn', 'label' => 'in der Daemmerung'];
|
||||
}
|
||||
|
||||
return ['class' => 'planet-visibility-bad', 'label' => 'am Tag'];
|
||||
}
|
||||
}
|
||||
|
||||
function idx_tleChecksum(string $line): int
|
||||
{
|
||||
@@ -281,6 +369,35 @@ if ($loggedIn) {
|
||||
}
|
||||
?>
|
||||
<?php require __DIR__ . '/header.php'; ?>
|
||||
<style>
|
||||
.planet-visibility-good {
|
||||
color: #4fb36a;
|
||||
}
|
||||
|
||||
.planet-visibility-good + .riseset-val,
|
||||
.planet-visibility-good + .riseset-val + .riseset-val {
|
||||
color: #4fb36a;
|
||||
}
|
||||
|
||||
.planet-visibility-warn {
|
||||
color: #d9a441;
|
||||
}
|
||||
|
||||
.planet-visibility-warn + .riseset-val,
|
||||
.planet-visibility-warn + .riseset-val + .riseset-val {
|
||||
color: #d9a441;
|
||||
}
|
||||
|
||||
.planet-visibility-bad {
|
||||
color: #cf5a5a;
|
||||
}
|
||||
|
||||
.planet-visibility-bad + .riseset-val,
|
||||
.planet-visibility-bad + .riseset-val + .riseset-val {
|
||||
color: #cf5a5a;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
<?php if (!$loggedIn): ?>
|
||||
|
||||
@@ -310,6 +427,8 @@ if ($loggedIn) {
|
||||
<?php
|
||||
$ev = $skyData['events'] ?? [];
|
||||
$evNext = $skyDataNext['events'] ?? [];
|
||||
$dayStartLocal = new DateTimeImmutable($date . ' 00:00:00', new DateTimeZone($tz));
|
||||
$dayEndLocal = $dayStartLocal->modify('+1 day');
|
||||
$deepSkyStart = (!empty($ev['astro_dusk']['found']) && !empty($ev['astro_dusk']['local_iso']))
|
||||
? new DateTimeImmutable($ev['astro_dusk']['local_iso'])
|
||||
: null;
|
||||
@@ -348,7 +467,8 @@ if ($loggedIn) {
|
||||
<span class="riseset-sep"></span><span class="riseset-sep"></span><span class="riseset-sep"></span>
|
||||
|
||||
<?php foreach (($planetData['planets'] ?? []) as $planet): ?>
|
||||
<span class="riseset-label"><?= h($planet['name']) ?></span>
|
||||
<?php $planetVisibility = planetVisibilityClass($planet, $dayStartLocal, $dayEndLocal, $ev, $evNext); ?>
|
||||
<span class="riseset-label <?= h($planetVisibility['class']) ?>" title="<?= h($planetVisibility['label']) ?>"><?= h($planet['name']) ?></span>
|
||||
<span class="riseset-val">↑ <?= ($planet['rise']['found'] ?? false) ? h($planet['rise']['local_time']) : '—' ?></span>
|
||||
<span class="riseset-val">↓ <?= ($planet['set']['found'] ?? false) ? h($planet['set']['local_time']) : '—' ?></span>
|
||||
<?php endforeach; ?>
|
||||
|
||||
Reference in New Issue
Block a user