Skip to content
Snippets Groups Projects
Commit 634b261b authored by Nikita Chernykh's avatar Nikita Chernykh
Browse files

Merge branch 'PTPS_Controller_7' into 'main'

Ptps controller 7

See merge request !7
parents ca9bf67d 9e00902d
No related branches found
No related tags found
1 merge request!7Ptps controller 7
......@@ -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
......@@ -9,7 +9,8 @@ use App\Requests\{
UniqElementsRequest,
MenuRequest,
HowDaysToNyRequest,
CountFriday13Request
CountFriday13Request,
DiffDaysRequest
};
use DateTimeImmutable;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
......@@ -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());
}
}
}
<?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
{% 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
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