1<?php
2
3/**
4 * FeedDate is an internal class that stores a date for a feed or feed item.
5 * Usually, you won't need to use this.
6 */
7class FeedDate
8{
9    protected $unix;
10
11    /**
12     * Creates a new instance of FeedDate representing a given date.
13     * Accepts RFC 822, ISO 8601 date formats (or anything that PHP's DateTime
14     * can parse, really) as well as unix time stamps.
15     *
16     * @param mixed $dateString optional the date this FeedDate will represent. If not specified, the current date and
17     *                          time is used.
18     */
19    public function __construct($dateString = "")
20    {
21        if ($dateString == "") {
22            $dateString = date("r");
23        }
24
25        if (is_integer($dateString)) {
26            $this->unix = $dateString;
27        } else {
28            try {
29                $this->unix = (int) (new Datetime($dateString))->format('U');
30            }  catch (Exception $e) {
31                $this->unix = 0;
32            }
33        }
34    }
35
36    /**
37     * Gets the date stored in this FeedDate as an RFC 822 date.
38     *
39     * @return string a date in RFC 822 format
40     */
41    public function rfc822()
42    {
43        //return gmdate("r",$this->unix);
44        $date = gmdate("D, d M Y H:i:s O", $this->unix);
45
46        return $date;
47    }
48
49    /**
50     * Gets the date stored in this FeedDate as an ISO 8601 date.
51     *
52     * @return string a date in ISO 8601 format
53     */
54    public function iso8601()
55    {
56        $date = gmdate("Y-m-d\TH:i:sP", $this->unix);
57
58        return $date;
59    }
60
61    /**
62     * Gets the date stored in this FeedDate as unix time stamp.
63     *
64     * @return int a date as a unix time stamp
65     */
66    public function unix()
67    {
68        return $this->unix;
69    }
70}
71