FeedWriter\Feed::setDate PHP Method

setDate() public method

This adds the 'updated' element to the feed. The value of the date parameter can be either an instance of the DateTime class, an integer containing a UNIX timestamp or a string which is parseable by PHP's 'strtotime' function. Not supported in RSS1 feeds.
public setDate ( $date ) : self
return self
    public function setDate($date)
    {
        if ($this->version == Feed::RSS1) {
            throw new InvalidOperationException('The publication date is not supported in RSS1 feeds.');
        }
        // The feeds have different date formats.
        $format = $this->version == Feed::ATOM ? \DATE_ATOM : \DATE_RSS;
        if ($date instanceof DateTime) {
            $date = $date->format($format);
        } else {
            if (is_numeric($date) && $date >= 0) {
                $date = date($format, $date);
            } else {
                if (is_string($date)) {
                    $timestamp = strtotime($date);
                    if ($timestamp === FALSE) {
                        throw new \InvalidArgumentException('The given date was not parseable.');
                    }
                    $date = date($format, $timestamp);
                } else {
                    throw new \InvalidArgumentException('The given date is not an instance of DateTime, a UNIX timestamp or a date string.');
                }
            }
        }
        if ($this->version == Feed::ATOM) {
            $this->setChannelElement('updated', $date);
        } else {
            $this->setChannelElement('lastBuildDate', $date);
        }
        return $this;
    }