diff --git a/src/Controller/CountFriday13Controller.php b/src/Controller/CountFriday13Controller.php new file mode 100644 index 0000000000000000000000000000000000000000..88e200c568b45e97e1493785f5da7b6406e3632b --- /dev/null +++ b/src/Controller/CountFriday13Controller.php @@ -0,0 +1,28 @@ +<?php + +namespace App\Controller; + +use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\HttpFoundation\JsonResponse; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Routing\Attribute\Route; +use function App\Repository\countFriday13; + +class CountFriday13Controller extends AbstractController +{ + /** + * git Контроллер вернет вÑе пÑтницы 13 в году иÑÐ¿Ð¾Ð»ÑŒÐ·ÑƒÑ countFriday13 функцию + * @param Request $request + * @return Response + */ + #[Route('/count/friday13', name: 'app_count_friday13')] + public function index(Request $request): Response + { + $year = $request->toArray()['year']; + + $returnableArray = countFriday13($year); + + return new JsonResponse($returnableArray, Response::HTTP_OK); + } +} diff --git a/src/Repository/CountFriday13Repository.php b/src/Repository/CountFriday13Repository.php new file mode 100644 index 0000000000000000000000000000000000000000..8d3e0d788950577c47d72cb4da443d468d535ad5 --- /dev/null +++ b/src/Repository/CountFriday13Repository.php @@ -0,0 +1,23 @@ +<?php + +namespace App\Repository; +use DateTimeImmutable; + +/** + * Вернет вÑе пÑтницы 13 в году + * @param int $yaer год, в котором необходимо произвеÑти раÑчет + * @return DateTimeImmutable[] + */ +function countFriday13(int $year): iterable { + $date = new DateTimeImmutable(); + $AllFri13 = []; + + for ($i = 1; $i<=12; $i++ ){ + $next13 = $date->setDate($year, $i, 13); + + if ($next13->format("D") === 'Fri'){ + $AllFri13[] = $next13; + } + } + return $AllFri13; +}