Skip to content
Snippets Groups Projects
Commit 36458228 authored by Адлан Шамавов's avatar Адлан Шамавов
Browse files

add diffDays

parent 84bd1fab
No related branches found
No related tags found
1 merge request!7Ptps controller 7
......@@ -12,24 +12,14 @@ use Symfony\Component\Routing\Attribute\Route;
class HomeController extends AbstractController
{
private function countFriday13(int $year): iterable {
$stardDate = new DateTime("{$year}-01-01 Friday");
$year += 1;
$endDate = new DateTime("{$year}-01-01");
$interval = new DateInterval('P7D');
foreach(new DatePeriod($stardDate, $interval, $endDate) as $day) {
yield new DateTimeImmutable($day->format("Y-m-d"));
}
private function diffDays(DateTimeImmutable $dateStart, DateTimeImmutable $dateEnd): int {
return date_diff($dateStart, $dateEnd)->format("%a") ;
}
#[Route('/{year}', name: 'home')]
public function home(int $year): Response
#[Route('/{startDate}/{endDate}', name: 'home')] // 01-01-2024
public function home(string $startDate, string $endDate): Response
{
$fridays = array();
foreach($this->countFriday13($year) as $date) {
$fridays[] = $date->format("Y-m-d l");
}
return $this->render('home.html.twig', ['fridays' => $fridays]);
$countDays = $this->diffDays(new DateTimeImmutable($startDate), new DateTimeImmutable($endDate));
return $this->render('home.html.twig', ['count' => $countDays]);
}
}
{% 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