added feiertage

This commit is contained in:
Tim Lappe 2025-03-23 14:37:22 +01:00
parent 0ae1bdf76b
commit 9cfbdeaa3c
2 changed files with 74 additions and 1 deletions

View File

@ -3,6 +3,7 @@
namespace App\Service;
use App\HomeAssistant\HomeAssistantClient;
use App\Service\FeiertageProvider;
use DateTimeImmutable;
use DateTimeInterface;
use DateTimeZone;
@ -17,7 +18,8 @@ final class CalendarExportService
private const OFFICE_STATE = 'CHECK24';
public function __construct(
private readonly HomeAssistantClient $homeAssistantClient
private readonly HomeAssistantClient $homeAssistantClient,
private readonly FeiertageProvider $feiertageProvider
) {
}
@ -60,6 +62,10 @@ final class CalendarExportService
$dayDate = clone $day['date'];
if ($this->feiertageProvider->isFeiertag($dayDate)) {
continue;
}
$filteredEntityHistory = array_filter($entityHistory, function (array $state) use ($dayDate) {
return new DateTimeImmutable($state['last_changed']) >= $dayDate->setTime(0, 0, 0) && new DateTimeImmutable($state['last_changed']) <= $dayDate->setTime(23, 59, 59);
});

View File

@ -0,0 +1,67 @@
<?php
namespace App\Service;
use DateTimeImmutable;
final class FeiertageProvider
{
/**
* @return array<int, array<string, DateTimeImmutable>>
*/
public function getFeiertage(): array
{
return [
2024 => [
'Neujahr' => new DateTimeImmutable('2024-01-01'),
'Karfreitag' => new DateTimeImmutable('2024-04-18'),
'Ostermontag' => new DateTimeImmutable('2024-04-21'),
'Tag der Arbeit' => new DateTimeImmutable('2024-05-01'),
'Christi Himmelfahrt' => new DateTimeImmutable('2024-05-29'),
'Pfingstmontag' => new DateTimeImmutable('2024-06-09'),
'Fronleichnam' => new DateTimeImmutable('2024-06-19'),
'Tag der Deutschen Einheit' => new DateTimeImmutable('2024-10-03'),
'Allerheiligen' => new DateTimeImmutable('2024-11-01'),
'1. Weihnachtsfeiertag' => new DateTimeImmutable('2024-12-25'),
'2. Weihnachtsfeiertag' => new DateTimeImmutable('2024-12-26'),
],
2025 => [
'Neujahr' => new DateTimeImmutable('2025-01-01'),
'Karfreitag' => new DateTimeImmutable('2025-04-18'),
'Ostermontag' => new DateTimeImmutable('2025-04-21'),
'Tag der Arbeit' => new DateTimeImmutable('2025-05-01'),
'Christi Himmelfahrt' => new DateTimeImmutable('2025-05-29'),
'Pfingstmontag' => new DateTimeImmutable('2025-06-09'),
'Fronleichnam' => new DateTimeImmutable('2025-06-19'),
'Tag der Deutschen Einheit' => new DateTimeImmutable('2025-10-03'),
'Allerheiligen' => new DateTimeImmutable('2025-11-01'),
'1. Weihnachtsfeiertag' => new DateTimeImmutable('2025-12-25'),
'2. Weihnachtsfeiertag' => new DateTimeImmutable('2025-12-26'),
],
2026 => [
'Neujahr' => new DateTimeImmutable('2026-01-01'),
'Karfreitag' => new DateTimeImmutable('2026-04-03'),
'Ostermontag' => new DateTimeImmutable('2026-04-06'),
'Tag der Arbeit' => new DateTimeImmutable('2026-05-01'),
'Christi Himmelfahrt' => new DateTimeImmutable('2026-05-14'),
'Pfingstmontag' => new DateTimeImmutable('2026-05-25'),
'Fronleichnam' => new DateTimeImmutable('2026-06-04'),
'Tag der Deutschen Einheit' => new DateTimeImmutable('2026-10-03'),
'Allerheiligen' => new DateTimeImmutable('2026-11-01'),
'1. Weihnachtsfeiertag' => new DateTimeImmutable('2026-12-25'),
'2. Weihnachtsfeiertag' => new DateTimeImmutable('2026-12-26'),
]
];
}
public function isFeiertag(DateTimeImmutable $date): bool
{
$year = (int)$date->format('Y');
$feiertage = $this->getFeiertage();
return count(array_filter($feiertage[$year], function (DateTimeImmutable $feiertag) use ($date) {
return $feiertag->format('Y-m-d') === $date->format('Y-m-d');
})) > 0;
}
}