Skip to content
Snippets Groups Projects

Ptps controller 6

Merged Адлан Шамавов requested to merge PTPS_Controller_6 into main
3 files
+ 20
6
Compare changes
  • Side-by-side
  • Inline
Files
3
+ 20
0
@@ -6,6 +6,9 @@ namespace App\Action;
use Exception;
use DateTimeImmutable;
use DateTime;
use DatePeriod;
use DateInterval;
class Functions
{
@@ -100,4 +103,21 @@ class Functions
$dateInterval = date_diff(new DateTimeImmutable($endYear), $date);
return (int)$dateInterval->format("%a") + 1;
}
/**
* Вернет все пятницы 13 в году
* @param int $year год, в котором необходимо произвести расчет
* @return DateTimeImmutable[]
* @throws Exception
*/
public function countFriday13(int $year): iterable
{
$startDate = new DateTime("$year-01-01 Friday");
++$year;
$endDate = new DateTime("$year-01-01");
$interval = new DateInterval('P7D');
foreach (new DatePeriod($startDate, $interval, $endDate) as $day) {
yield new DateTimeImmutable($day->format("Y-m-d"));
}
}
}
\ No newline at end of file
Loading