Slim API deployment - composer install + full CRUD endpoints

This commit is contained in:
Hermes Agent
2026-05-20 14:36:05 +02:00
parent 48bf9c7088
commit 8ab4e532fd
1727 changed files with 7746 additions and 7 deletions

View File

@@ -0,0 +1,55 @@
<?php
declare(strict_types=1);
namespace App\Services;
use DateInterval;
use DateTimeImmutable;
use DateTimeZone;
final class SunTimesService
{
public function forRange(array $tenant, string $from, string $to): array
{
$latitude = isset($tenant['latitude']) ? (float) $tenant['latitude'] : null;
$longitude = isset($tenant['longitude']) ? (float) $tenant['longitude'] : null;
$timezoneName = (string) ($tenant['timezone'] ?? 'Europe/Berlin');
if ($latitude === null || $longitude === null || $latitude === 0.0 && $longitude === 0.0) {
return [];
}
$timezone = new DateTimeZone($timezoneName);
$start = new DateTimeImmutable($from, new DateTimeZone('UTC'));
$end = new DateTimeImmutable($to, new DateTimeZone('UTC'));
$day = $start->setTimezone($timezone)->setTime(0, 0);
$lastDay = $end->setTimezone($timezone)->setTime(0, 0);
$result = [];
while ($day < $lastDay) {
$solar = date_sun_info($day->setTime(12, 0)->getTimestamp(), $latitude, $longitude);
$key = $day->format('Y-m-d');
$result[$key] = [
'sunrise' => $this->formatSolarTimestamp($solar['sunrise'] ?? false, $timezone),
'sunset' => $this->formatSolarTimestamp($solar['sunset'] ?? false, $timezone),
];
$day = $day->add(new DateInterval('P1D'));
}
return $result;
}
private function formatSolarTimestamp(int|float|bool $timestamp, DateTimeZone $timezone): ?string
{
if (!is_int($timestamp) && !is_float($timestamp)) {
return null;
}
return (new DateTimeImmutable('@' . (string) (int) $timestamp))
->setTimezone($timezone)
->format('H:i');
}
}