lib/Jejik/MT940/Parser/AbstractParser.php
protected function getNearestDateTimeFromDayAndMonth(\DateTime $target, $day, $month)
    {
        $initialGuess = new \DateTime();
        $initialGuess->setDate($target->format('Y'), $month, $day);
        $initialGuess->setTime(0, 0, 0);
        $initialGuessDiff = $target->diff($initialGuess);

        $yearEarlier = clone $initialGuess;
        $yearEarlier->modify('-1 year');
        $yearEarlierDiff = $target->diff($yearEarlier);

        if ($yearEarlierDiff->days < $initialGuessDiff->days) {
            return $yearEarlier;
        }

        $yearLater = clone $initialGuess;
        $yearLater->modify('+1 year');
        $yearLaterDiff = $target->diff($yearLater);

        if ($yearLaterDiff->days < $initialGuessDiff->days) {
            return $yearLater;
        }

        return $initialGuess;
    }
protected function getNearestDateTimeFromDayAndMonth(\DateTime $target, $day, $month)
    {
        $initialGuess = new \DateTime();
        $initialGuess->setDate($target->format('Y'), $month, $day);
        $initialGuess->setTime(0, 0, 0);
        $initialGuessDiff = $target->diff($initialGuess);

        $yearEarlier = clone $initialGuess;
        $yearEarlier->modify('-1 year');
        $yearEarlierDiff = $target->diff($yearEarlier);

        if ($yearEarlierDiff->days < $initialGuessDiff->days) {
            return $yearEarlier;
        }

        $yearLater = clone $initialGuess;
        $yearLater->modify('+1 year');
        $yearLaterDiff = $target->diff($yearLater);

        if ($yearLaterDiff->days < $initialGuessDiff->days) {
            return $yearLater;
        }

        return $initialGuess;
    }
protected function getNearestDateTimeFromDayAndMonth ( \ DateTime $ target , $ day , $ month ) { $ initialGuess = new \ DateTime ( ) ; $ initialGuess -> setDate ( $ target -> format ( 'Y' ) , $ month , $ day ) ; $ initialGuess -> setTime ( 0 , 0 , 0 ) ; $ initialGuessDiff = $ target -> diff ( $ initialGuess ) ; $ yearEarlier = clone $ initialGuess ; $ yearEarlier -> modify ( '-1 year' ) ; $ yearEarlierDiff = $ target -> diff ( $ yearEarlier ) ; if ( $ yearEarlierDiff -> days < $ initialGuessDiff -> days ) { return $ yearEarlier ; } $ yearLater = clone $ initialGuess ; $ yearLater -> modify ( '+1 year' ) ; $ yearLaterDiff = $ target -> diff ( $ yearLater ) ; if ( $ yearLaterDiff -> days < $ initialGuessDiff -> days ) { return $ yearLater ; } return $ initialGuess ; }
Finds the closest \DateTime to the given target \DateTime with the set day and month.
Will try at most 3 \Datetime's, one a year before our initial guess, and one a year after.
Returns the one with the least days difference in days.

@param \DateTime $target
@param int $day
@param int $month
@return \DateTime
Finds the closest \ DateTime to the given target \ DateTime with the set day and month . Will try at most 3 \ Datetime s one a year before our initial guess and one a year after . Returns the one with the least days difference in days .