Loading src/Controller/HowDaysToNYController.php 0 → 100644 +30 −0 Original line number Diff line number Diff line <?php namespace App\Controller; use DateTimeImmutable; 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\howDaysToNy; class HowDaysToNYController extends AbstractController { /** * Контролер рассчитывает кол-во дней до нового года используюя howDaysToNy * @param Request $request * @return Response * @throws \Exception */ #[Route('/howdaystony', name: 'app_how_days_to_n_y')] public function index(Request $request): Response { $date = $request->toArray()['date']; $return = howDaysToNy(new DateTimeImmutable($date, null)); return new JsonResponse($return, Response::HTTP_OK); } } src/Repository/HowDaysToNYRepository.php 0 → 100644 +19 −0 Original line number Diff line number Diff line <?php namespace App\Repository; use DateTime; use DateTimeImmutable; /** * Функция рассчитывает кол-во дней до нового года * @param DateTimeImmutable $date дата от которой, необходимо рассчитать кол-во дней * @return int */ function howDaysToNy(DateTimeImmutable $date): int { $nextYear = (int)$date->format('Y') + 1; $dateOfNY = (new DateTime()) ->setDate($nextYear, 01, 01); return $dateOfNY->diff($date)->format('%a'); } Loading
src/Controller/HowDaysToNYController.php 0 → 100644 +30 −0 Original line number Diff line number Diff line <?php namespace App\Controller; use DateTimeImmutable; 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\howDaysToNy; class HowDaysToNYController extends AbstractController { /** * Контролер рассчитывает кол-во дней до нового года используюя howDaysToNy * @param Request $request * @return Response * @throws \Exception */ #[Route('/howdaystony', name: 'app_how_days_to_n_y')] public function index(Request $request): Response { $date = $request->toArray()['date']; $return = howDaysToNy(new DateTimeImmutable($date, null)); return new JsonResponse($return, Response::HTTP_OK); } }
src/Repository/HowDaysToNYRepository.php 0 → 100644 +19 −0 Original line number Diff line number Diff line <?php namespace App\Repository; use DateTime; use DateTimeImmutable; /** * Функция рассчитывает кол-во дней до нового года * @param DateTimeImmutable $date дата от которой, необходимо рассчитать кол-во дней * @return int */ function howDaysToNy(DateTimeImmutable $date): int { $nextYear = (int)$date->format('Y') + 1; $dateOfNY = (new DateTime()) ->setDate($nextYear, 01, 01); return $dateOfNY->diff($date)->format('%a'); }