u01jmg3 / ics-parser

Parser for iCalendar Events • PHP 8+, 7 (≥ 7.4), 5 (≥ 5.6)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Minor phpdoc change for ICal::parseDuration()

kktsvetkov opened this issue · comments

Hi, the phpdoc for ICal::parseDuration() might be off as it states $duration is string, while looking at the code it seems to be a DateInterval object as its properties are being used such as $duration->y:

    /**
     * Parses a duration and applies it to a date
     *
     * @param  string $date
     * @param  string $duration
     * @param  string $format
     * @return integer|\DateTime
     */
    protected function parseDuration($date, $duration, $format = self::UNIX_FORMAT)
    {
        $dateTime = date_create($date);
        $dateTime->modify("{$duration->y} year");
        $dateTime->modify("{$duration->m} month");
        $dateTime->modify("{$duration->d} day");
        $dateTime->modify("{$duration->h} hour");
        $dateTime->modify("{$duration->i} minute");
        $dateTime->modify("{$duration->s} second");
        ...

Also, it seems the last argument for ICal::parseDuration() is never used. It is $format but the only place where ICal::parseDuration() is called, it is null. Perhaps that last argument can be dropped, as the returned output is a DateTime and once you receive that object you can format it as you like.