Skip to content

Commit

Permalink
fix Turkey
Browse files Browse the repository at this point in the history
  • Loading branch information
Nielsvanpach committed Mar 21, 2024
1 parent 98a6fc5 commit 13cf381
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
32 changes: 23 additions & 9 deletions src/Calendars/IslamicCalendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,48 @@ protected function getHoliday(array $collection, int $year, int $totalDays): Car
throw InvalidYear::range($this->countryCode(), 1970, 2037);
}

$overlap = $this->getOverlapping(self::eidAlFitr, $year, $totalDays);
$overlap = $this->getOverlapping($collection, $year, $totalDays);

if ($overlap) {
$date = [$date, $overlap];
$period = $this->createPeriod($overlap, $year -1, $totalDays);

$date = [$period, $date];
}

if (! is_array($date)) {
$start = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")->startOfDay();
$end = $start->addDays($totalDays - 1)->startOfDay();

return CarbonPeriod::create($start, '1 day', $end);
return $this->createPeriod($date, $year, $totalDays);
}

// Twice a year
$periods = [];
$dates = $date;

foreach ($dates as $date) {
$start = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")->startOfDay();
$end = $start->addDays($totalDays - 1)->startOfDay();
$periods[] = CarbonPeriod::create($start, '1 day', $end);
if ($date instanceof CarbonPeriod) {
$periods[] = $date;
continue;
}

$periods[] = $this->createPeriod($date, $year, $totalDays);
}

return $periods;
}

protected function createPeriod(string $date, int $year, int $totalDays): CarbonPeriod
{
$start = CarbonImmutable::createFromFormat('Y-m-d', "{$year}-{$date}")->startOfDay();
$end = $start->addDays($totalDays -1)->startOfDay();

return CarbonPeriod::create($start, '1 day', $end);
}

protected function getOverlapping(array $collection, int $year, $totalDays): ?string
{
if ($year === 1970) {
return null;
}

try {
$date = $collection[$year - 1];
} catch (\Exception) {
Expand Down
6 changes: 6 additions & 0 deletions src/Countries/Country.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ protected function convertPeriods(
$result[$holidayName] = $day->toImmutable();
}
} else {
if ($holiday instanceof CarbonInterface) {
if ($holiday->year !== $year) {
continue;
}
}

$result[$name] = $holiday;
}
}
Expand Down

0 comments on commit 13cf381

Please sign in to comment.