Commit 0dfdb4fc authored by Akex's avatar Akex
Browse files

add func countind days to NY

parent 2a7f91b8
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
<?php

namespace App\Actions;

use DateTimeImmutable;

class HowDaysToNYAction
{
    /**
     * Функция рассчитывает кол-во дней до нового года
     * @param DateTime $date дата от которой, необходимо рассчитать кол-во дней
     * @return int
     */
    public static function count(DateTimeImmutable $date): int
    {
        $dateOfNY = $date->modify('first day of Jan +1 year');

        return (int) $dateOfNY->diff($date)->format('%a');
    }
}
 No newline at end of file
+2 −1
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

require_once __DIR__ . '/../vendor/autoload.php';

use App\Actions /*placeholder for a class */;
use App\Actions\HowDaysToNYAction;
use App\TestData\TestData;

echo "Дней до нового года (в днях): ". HowDaysToNYAction::count(new DateTimeImmutable());
 No newline at end of file