Loading src/Action/Functions.php +12 −0 Original line number Diff line number Diff line Loading @@ -120,4 +120,16 @@ class Functions yield new DateTimeImmutable($day->format("Y-m-d")); } } /** * Вернет кол-во дней между датами * @param DateTimeImmutable $dateStart дата начала * @param DateTimeImmutable $dateEnd дата окончания * @return int */ public function diffDays(DateTimeImmutable $dateStart, DateTimeImmutable $dateEnd): int { $dateInterval = date_diff($dateStart, $dateEnd); return (int)$dateInterval->format("%a") ; } } No newline at end of file src/Controller/HomeController.php +16 −1 Original line number Diff line number Diff line Loading @@ -9,7 +9,8 @@ use App\Requests\{ UniqElementsRequest, MenuRequest, HowDaysToNyRequest, CountFriday13Request CountFriday13Request, DiffDaysRequest }; use DateTimeImmutable; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; Loading Loading @@ -76,4 +77,18 @@ class HomeController extends AbstractController } return $this->json($fridays); } #[Route('/diffDays', name: 'diffDays')] // 01-01-2024 public function diffDays(DiffDaysRequest $request): Response { try { $result = $this->functions->diffDays( new DateTimeImmutable($request->getRequest()->get('startDate')), new DateTimeImmutable($request->getRequest()->get('endDate')), ); return $this->json(["The difference of days:" => $result]); } catch (\Exception $e) { return new Response($e->getMessage()); } } } src/Requests/DiffDaysRequest.php 0 → 100644 +14 −0 Original line number Diff line number Diff line <?php namespace App\Requests; use Symfony\Component\Validator\Constraints as Assert; class DiffDaysRequest extends BaseRequest { #[Assert\Type('date')] public $startDate; #[Assert\Type('date')] public $endDate; } No newline at end of file templates/home.html.twig +1 −4 Original line number Diff line number Diff line {% block body %} <h1>Кол-во пятниц 13 в году: {{ fridays|length }}</h1> {% for day in fridays %} <p>{{ day }}</p> {% endfor %} <h1>Кол-во дней между датами: {{ count }}</h1> {% endblock %} No newline at end of file Loading
src/Action/Functions.php +12 −0 Original line number Diff line number Diff line Loading @@ -120,4 +120,16 @@ class Functions yield new DateTimeImmutable($day->format("Y-m-d")); } } /** * Вернет кол-во дней между датами * @param DateTimeImmutable $dateStart дата начала * @param DateTimeImmutable $dateEnd дата окончания * @return int */ public function diffDays(DateTimeImmutable $dateStart, DateTimeImmutable $dateEnd): int { $dateInterval = date_diff($dateStart, $dateEnd); return (int)$dateInterval->format("%a") ; } } No newline at end of file
src/Controller/HomeController.php +16 −1 Original line number Diff line number Diff line Loading @@ -9,7 +9,8 @@ use App\Requests\{ UniqElementsRequest, MenuRequest, HowDaysToNyRequest, CountFriday13Request CountFriday13Request, DiffDaysRequest }; use DateTimeImmutable; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; Loading Loading @@ -76,4 +77,18 @@ class HomeController extends AbstractController } return $this->json($fridays); } #[Route('/diffDays', name: 'diffDays')] // 01-01-2024 public function diffDays(DiffDaysRequest $request): Response { try { $result = $this->functions->diffDays( new DateTimeImmutable($request->getRequest()->get('startDate')), new DateTimeImmutable($request->getRequest()->get('endDate')), ); return $this->json(["The difference of days:" => $result]); } catch (\Exception $e) { return new Response($e->getMessage()); } } }
src/Requests/DiffDaysRequest.php 0 → 100644 +14 −0 Original line number Diff line number Diff line <?php namespace App\Requests; use Symfony\Component\Validator\Constraints as Assert; class DiffDaysRequest extends BaseRequest { #[Assert\Type('date')] public $startDate; #[Assert\Type('date')] public $endDate; } No newline at end of file
templates/home.html.twig +1 −4 Original line number Diff line number Diff line {% block body %} <h1>Кол-во пятниц 13 в году: {{ fridays|length }}</h1> {% for day in fridays %} <p>{{ day }}</p> {% endfor %} <h1>Кол-во дней между датами: {{ count }}</h1> {% endblock %} No newline at end of file