-
Notifications
You must be signed in to change notification settings - Fork 1
/
GermanPublicHolidayFilter.php
44 lines (37 loc) · 1.43 KB
/
GermanPublicHolidayFilter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
namespace Ujamii\OsmOpeningHours\Filters;
class GermanPublicHolidayFilter implements Filter
{
public function __construct(private array $openingHours = [])
{
}
public function setOpeningHours(array $openingHours = []): self
{
$this->openingHours = $openingHours;
return $this;
}
public function applyFilter(\DateTimeImmutable $date): ?array
{
$year = (int)$date->format('Y');
$easterDays = easter_days($year);
$holidays = [
new \DateTimeImmutable("$year-01-01"),
new \DateTimeImmutable("$year-03-21 +" . ($easterDays - 2) . 'days'),
new \DateTimeImmutable("$year-03-21 +" . ($easterDays + 1) . 'days'),
new \DateTimeImmutable("$year-03-21 +" . ($easterDays + 39) . 'days'),
new \DateTimeImmutable("$year-03-21 +" . ($easterDays + 50) . 'days'),
new \DateTimeImmutable("$year-05-01"),
new \DateTimeImmutable("$year-10-03"),
new \DateTimeImmutable("$year-12-25"),
new \DateTimeImmutable("$year-12-26"),
];
$dateToCheck = $date->format('m-d');
foreach ($holidays as $holiday) {
if ($dateToCheck === $holiday->format('m-d')) {
return $this->openingHours;
// Any valid exception-array can be returned here (range of hours, with or without data)
}
}
return null;
}
}