Skip to content
Snippets Groups Projects
Commit 19237b0d authored by Akex's avatar Akex Committed by Александр Плохих
Browse files

make controller

parent 295a6342
No related branches found
No related tags found
1 merge request!7make controller
<?php
namespace App\Controller;
use DateTimeImmutable;
use HttpResponse;
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;
class DiffDaysController extends AbstractController
{
/**
* Контроллер вернет кол-во дней между датами
* @param Request $request
* @return Response
*/
#[Route('/diff/days', name: 'app_diff_days', methods: ['POST'])]
public function index(Request $request): Response
{
$dateStart = new DateTimeImmutable($request->toArray()['date_start']);
$dateEnd = new DateTimeImmutable($request->toArray()['date_end']);
return new JsonResponse(["interval"=>($dateStart->diff($dateEnd)->format("%a"))]
, Response::HTTP_OK);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment