Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
iqdevTranningProgram
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Адлан Шамавов
iqdevTranningProgram
Commits
36458228
Commit
36458228
authored
11 months ago
by
Адлан Шамавов
Browse files
Options
Downloads
Patches
Plain Diff
add diffDays
parent
84bd1fab
No related branches found
Branches containing commit
No related tags found
1 merge request
!7
Ptps controller 7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Controller/HomeController.php
+6
-16
6 additions, 16 deletions
src/Controller/HomeController.php
templates/home.html.twig
+1
-4
1 addition, 4 deletions
templates/home.html.twig
with
7 additions
and
20 deletions
src/Controller/HomeController.php
+
6
−
16
View file @
36458228
...
...
@@ -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
]);
}
}
This diff is collapsed.
Click to expand it.
templates/home.html.twig
+
1
−
4
View file @
36458228
{%
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment