<?php

namespace App\Helper;

class DateHelper
{
    public static function isInRange(\DateTimeImmutable $date): bool
    {
        $today = new \DateTimeImmutable('today');
        return $date >= $today && $date <= $today->modify('+14 days');
    }

    /** @return array{\DateTimeImmutable, \DateTimeImmutable} */
    public static function getDateRange(?\DateTimeImmutable $start, ?\DateTimeImmutable $end): array
    {
        $today = new \DateTimeImmutable('today');
        $from = max($today, $start ?? $today);
        $to = min($today->modify('+14 days'), $end ?? $today->modify('+14 days'));

        return [$from, $to];
    }

    public static function getWeeksDiff(\DateTimeImmutable $start, \DateTimeImmutable $date): int
    {
        return (int) ($start->modify('monday this week')->diff($date->modify('monday this week'))->days / 7);
    }
}
