1572dd708SAndreas Gohr<?php 2572dd708SAndreas Gohr 3572dd708SAndreas Gohr/** 4572dd708SAndreas Gohr * FeedDate is an internal class that stores a date for a feed or feed item. 5572dd708SAndreas Gohr * Usually, you won't need to use this. 6572dd708SAndreas Gohr */ 7572dd708SAndreas Gohrclass FeedDate 8572dd708SAndreas Gohr{ 9572dd708SAndreas Gohr protected $unix; 10572dd708SAndreas Gohr 11572dd708SAndreas Gohr /** 12572dd708SAndreas Gohr * Creates a new instance of FeedDate representing a given date. 13*64d8abdbSAndreas Gohr * Accepts RFC 822, ISO 8601 date formats (or anything that PHP's DateTime 14*64d8abdbSAndreas Gohr * can parse, really) as well as unix time stamps. 15572dd708SAndreas Gohr * 16572dd708SAndreas Gohr * @param mixed $dateString optional the date this FeedDate will represent. If not specified, the current date and 17572dd708SAndreas Gohr * time is used. 18572dd708SAndreas Gohr */ 19572dd708SAndreas Gohr public function __construct($dateString = "") 20572dd708SAndreas Gohr { 21572dd708SAndreas Gohr if ($dateString == "") { 22572dd708SAndreas Gohr $dateString = date("r"); 23572dd708SAndreas Gohr } 24572dd708SAndreas Gohr 25572dd708SAndreas Gohr if (is_integer($dateString)) { 26572dd708SAndreas Gohr $this->unix = $dateString; 27572dd708SAndreas Gohr } else { 28*64d8abdbSAndreas Gohr try { 29*64d8abdbSAndreas Gohr $this->unix = (int) (new Datetime($dateString))->format('U'); 30*64d8abdbSAndreas Gohr } catch (Exception $e) { 31572dd708SAndreas Gohr $this->unix = 0; 32572dd708SAndreas Gohr } 33*64d8abdbSAndreas Gohr } 34*64d8abdbSAndreas Gohr } 35572dd708SAndreas Gohr 36572dd708SAndreas Gohr /** 37572dd708SAndreas Gohr * Gets the date stored in this FeedDate as an RFC 822 date. 38572dd708SAndreas Gohr * 39572dd708SAndreas Gohr * @return string a date in RFC 822 format 40572dd708SAndreas Gohr */ 41572dd708SAndreas Gohr public function rfc822() 42572dd708SAndreas Gohr { 43572dd708SAndreas Gohr //return gmdate("r",$this->unix); 44572dd708SAndreas Gohr $date = gmdate("D, d M Y H:i:s O", $this->unix); 45572dd708SAndreas Gohr 46572dd708SAndreas Gohr return $date; 47572dd708SAndreas Gohr } 48572dd708SAndreas Gohr 49572dd708SAndreas Gohr /** 50572dd708SAndreas Gohr * Gets the date stored in this FeedDate as an ISO 8601 date. 51572dd708SAndreas Gohr * 52572dd708SAndreas Gohr * @return string a date in ISO 8601 format 53572dd708SAndreas Gohr */ 54572dd708SAndreas Gohr public function iso8601() 55572dd708SAndreas Gohr { 56e43cd7e1SAndreas Gohr $date = gmdate("Y-m-d\TH:i:sP", $this->unix); 57572dd708SAndreas Gohr 58572dd708SAndreas Gohr return $date; 59572dd708SAndreas Gohr } 60572dd708SAndreas Gohr 61572dd708SAndreas Gohr /** 62572dd708SAndreas Gohr * Gets the date stored in this FeedDate as unix time stamp. 63572dd708SAndreas Gohr * 64572dd708SAndreas Gohr * @return int a date as a unix time stamp 65572dd708SAndreas Gohr */ 66572dd708SAndreas Gohr public function unix() 67572dd708SAndreas Gohr { 68572dd708SAndreas Gohr return $this->unix; 69572dd708SAndreas Gohr } 70572dd708SAndreas Gohr} 71