u01jmg3 / ics-parser

Parser for iCalendar Events • PHP 8+, 7 (≥ 7.4), 5 (≥ 5.6)
MIT License
439 stars 144 forks source link

Minor phpdoc change for ICal::parseDuration() #310

Closed kktsvetkov closed 2 years ago

kktsvetkov commented 2 years ago

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");
        ...
kktsvetkov commented 2 years ago

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.

u01jmg3 commented 2 years ago

See 2c8cf55