private static DateTime ParseDate(IResource article, string dateValue) { DateTime date; DateTime threadDate = article.GetDateProp(NntpPlugin._propLastArticleDate); try { date = RFC822DateParser.ParseDate(dateValue); article.SetProp(Core.Props.Date, date); if (threadDate == DateTime.MinValue || threadDate < date) { article.SetProp(NntpPlugin._propLastArticleDate, date); } } catch (Exception e) { Trace.WriteLine("Failed to parse RFC-822 date " + dateValue + ": " + e.Message); date = DateTime.Now; if (!article.HasProp(Core.Props.Date)) { article.SetProp(Core.Props.Date, date); } } return(date); }
[Test] public void NoWeekdayTest() { DateTime date = RFC822DateParser.ParseDate("02 Aug 2004 11:31:17 -0700"); AssertEquals(2004, date.Year); AssertEquals(8, date.Month); AssertEquals(2, date.Day); }
[Test] public void TwoDigitYearTest() { DateTime date = RFC822DateParser.ParseDate("Fri, 20 Feb 04 11:31:17 -0700"); AssertEquals(2004, date.Year); AssertEquals(2, date.Month); AssertEquals(20, date.Day); AssertEquals(21, date.Hour); AssertEquals(31, date.Minute); }