public static DateTime ParseRfc822DateTime(string value) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ DateTime result = DateTime.MinValue; //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ if (value == null || value.Length == 0) { return(result); } //------------------------------------------------------------ // Parse RFC-3339 formatted date //------------------------------------------------------------ if (RSSDateTimeUtility.TryParseRfc822DateTime(value, out result)) { return(result); } else { throw new FormatException(String.Format(null, "'{0}' is not a valid RFC-822 formatted date-time value.", value)); } }
private static List <NewsFeedItem> ParseFeed(string rss) { var list = new List <NewsFeedItem>(); try { var xdoc = XDocument.Parse(rss); var items = xdoc.Descendants("item"); var id = 0; foreach (var item in items) { NewsFeedItem article = new NewsFeedItem(); // Fri, 04 May 2018 15:31:44 EDT <-- district version // Wed, 02 May 2018 12:58:20 -0000 <-- RSS aggregator version string dateString = item.Element("pubDate").Value; DateTime pubDate = DateTime.MinValue; RSSDateTimeUtility.TryParseRfc822DateTime(dateString, out pubDate); if (pubDate == DateTime.MinValue) { RSSDateTimeUtility.TryParseRfc3339DateTime(dateString, out pubDate); } article.Author = ""; article.Title = item.Element("title") != null?item.Element("title").Value : ""; article.Description = item.Element("description") != null?item.Element("description").Value : ""; article.Link = item.Element("link") != null?item.Element("link").Value : ""; article.PublishDate = item.Element("pubDate") != null ? pubDate : DateTime.MinValue; article.Id = (id++).ToString(); list.Add(article); } } catch { } return(list); }