SimplePie_Parse_Date::date_rfc2822 PHP Method

date_rfc2822() public method

Parse RFC2822's date format
public date_rfc2822 ( $date ) : integer
return integer Timestamp
    public function date_rfc2822($date)
    {
        static $pcre;
        if (!$pcre) {
            $wsp = '[\\x09\\x20]';
            $fws = '(?:' . $wsp . '+|' . $wsp . '*(?:\\x0D\\x0A' . $wsp . '+)+)';
            $optional_fws = $fws . '?';
            $day_name = $this->day_pcre;
            $month = $this->month_pcre;
            $day = '([0-9]{1,2})';
            $hour = $minute = $second = '([0-9]{2})';
            $year = '([0-9]{2,4})';
            $num_zone = '([+\\-])([0-9]{2})([0-9]{2})';
            $character_zone = '([A-Z]{1,5})';
            $zone = '(?:' . $num_zone . '|' . $character_zone . ')';
            $pcre = '/(?:' . $optional_fws . $day_name . $optional_fws . ',)?' . $optional_fws . $day . $fws . $month . $fws . $year . $fws . $hour . $optional_fws . ':' . $optional_fws . $minute . '(?:' . $optional_fws . ':' . $optional_fws . $second . ')?' . $fws . $zone . '/i';
        }
        if (preg_match($pcre, $this->remove_rfc2822_comments($date), $match)) {
            /*
            Capturing subpatterns:
            1: Day name
            2: Day
            3: Month
            4: Year
            5: Hour
            6: Minute
            7: Second
            8: Timezone ±
            9: Timezone hours
            10: Timezone minutes
            11: Alphabetic timezone
            */
            // Find the month number
            $month = $this->month[strtolower($match[3])];
            // Numeric timezone
            if ($match[8] !== '') {
                $timezone = $match[9] * 3600;
                $timezone += $match[10] * 60;
                if ($match[8] === '-') {
                    $timezone = 0 - $timezone;
                }
            } elseif (isset($this->timezone[strtoupper($match[11])])) {
                $timezone = $this->timezone[strtoupper($match[11])];
            } else {
                $timezone = 0;
            }
            // Deal with 2/3 digit years
            if ($match[4] < 50) {
                $match[4] += 2000;
            } elseif ($match[4] < 1000) {
                $match[4] += 1900;
            }
            // Second is optional, if it is empty set it to zero
            if ($match[7] !== '') {
                $second = $match[7];
            } else {
                $second = 0;
            }
            return gmmktime($match[5], $match[6], $second, $month, $match[2], $match[4]) - $timezone;
        } else {
            return false;
        }
    }