/// <summary> /// Populates defaults and opens edit form to add new record /// GET: /Admin/News/PreLoad /// </summary> public ActionResult PreLoad(FormCollection collection) { Breadcrumbs.Current.AddBreadcrumb(3, "Add News from RSS"); var record = new Models.News(); // any default values can be set here or in partial class News.InitDefaults() string text = ""; if ((text = Request["title"]).IsNotBlank()) { record.IntroductionText = Server.UrlDecode(text); } if ((text = Request["feedname"]).IsNotBlank()) { record.Source = Server.UrlDecode(text); } if ((text = Request["link"]).IsNotBlank()) { record.LinkUrl = Server.UrlDecode(text); } if ((text = Request["description"]).IsNotBlank()) { record.BodyTextHtml = Server.UrlDecode(text); } if ((text = Request["pubDate"]).IsNotBlank()) { var dateText = Server.UrlDecode(text); // Server.UrlDecode(text) "Wed, 17 Aug 2011 21:54:44 EDT" string var simpleDate = Rfc822DateTime.Parse(dateText); record.PublishDate = simpleDate; } return(View("NewsEdit", record)); }
public void CanBeParsedWithNumericOffset() { var s = "Wed, 29 Jun 2011 11:47:00 -0500"; var rfc822Date = DateTime.MinValue; Rfc822DateTime.TryParse(s, out rfc822Date); var date = new DateTime(2011, 6, 29, 16, 47, 00); Assert.AreEqual(date, rfc822Date); }
public void CanBeParsedWithTimeZoneName() { var s = "June 21, 2011 16:54:20 PDT"; var rfc822Date = DateTime.MinValue; Rfc822DateTime.TryParse(s, out rfc822Date); var date = new DateTime(2011, 6, 21, 23, 54, 20); Assert.AreEqual(date, rfc822Date); }
protected override void When() { _exception = null; try { _date = Rfc822DateTime.Parse("Mon, 20 Mar 11 12:01:02 UT"); } catch (Exception ex) { _exception = ex; } }
protected override void When() { _exception = null; try { _date = Rfc822DateTime.Parse("fred"); } catch (Exception ex) { _exception = ex; } }
public void setDate(String st) { DateTime time; if (Rfc822DateTime.TryParse(st, out time)) { st = time.ToString("dd.MM.yy"); _dateLabel.Text = "[" + st + "]"; } else { _dateLabel.Text = "[Incorrect date]"; } }
//============================================================ // Public Methods //============================================================ #region Parse(string s) /// <summary> /// Converts the specified string representation of a date and time to its <see cref="DateTime"/> equivalent. /// </summary> /// <param name="s">A string containing a date and time to convert.</param> /// <returns> /// A <see cref="DateTime"/> equivalent to the date and time contained in <paramref name="s"/>, /// expressed as <i>Coordinated Universal Time (UTC)</i>. /// </returns> /// <remarks> /// The string <paramref name="s"/> is parsed using formatting information in the DateTimeFormatInfo.InvariantInfo object. /// </remarks> /// <exception cref="ArgumentNullException"><paramref name="s"/> is a <b>null</b> reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException"><paramref name="s"/> is an empty string.</exception> /// <exception cref="FormatException"><paramref name="s"/> does not contain a valid RFC 822 string representation of a date and time.</exception> public static DateTime Parse(string s) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ Guard.ArgumentNotNullOrEmptyString(s, "s"); DateTime result; if (Rfc822DateTime.TryParse(s, out result)) { return(result); } else { return(DateTime.MinValue); } }
//============================================================ // Public Methods //============================================================ #region Parse(string s) /// <summary> /// Converts the specified string representation of a date and time to its <see cref="DateTime"/> equivalent. /// </summary> /// <param name="s">A string containing a date and time to convert.</param> /// <returns> /// A <see cref="DateTime"/> equivalent to the date and time contained in <paramref name="s"/>, /// expressed as <i>Coordinated Universal Time (UTC)</i>. /// </returns> /// <remarks> /// The string <paramref name="s"/> is parsed using formatting information in the <see cref="DateTimeFormatInfo.InvariantInfo"/> object. /// </remarks> /// <exception cref="ArgumentNullException"><paramref name="s"/> is a <b>null</b> reference (Nothing in Visual Basic).</exception> /// <exception cref="ArgumentNullException"><paramref name="s"/> is an empty string.</exception> /// <exception cref="FormatException"><paramref name="s"/> does not contain a valid RFC 822 string representation of a date and time.</exception> public static DateTime Parse(string s) { //------------------------------------------------------------ // Validate parameter //------------------------------------------------------------ //Guard.ArgumentNotNullOrEmptyString(s, "s"); DateTime result; if (Rfc822DateTime.TryParse(s, out result)) { return(result); } else { //throw new FormatException(String.Format(null, "{0} is not a valid RFC 822 string representation of a date and time.", s)); return(DateTime.Now); } }
public void TestParseDates() { // The local timezone for tests is America/Chicago (UTC -06:00) TransformPair <string, DateTime> [] pairs = TransformPair <string, DateTime> .GetFrom( "Fri, 22 Feb 2008 16:00:00 EST", DateTime.Parse("22/02/2008 15.00.00"), "Fri, 15 Feb 2008 4:10:00 EST", DateTime.Parse("15/02/2008 3.10.00"), "Tue, 08 Apr 2008 03:37:04 -0400", DateTime.Parse("08/04/2008 2.37.04"), "Tue, 26 Feb 2008 03:28:51 -0500", DateTime.Parse("26/02/2008 2.28.51"), "Sun, 11 May 2008 01:33:26 -0400", DateTime.Parse("11/05/2008 0.33.26"), "Fri, 16 May 2008 16:09:10 -0500", DateTime.Parse("16/05/2008 16.09.10"), "Fri, 14 Mar 2008 13:44:53 -0500", DateTime.Parse("14/03/2008 13.44.53"), "Fri, 07 December 2007 17:00:00 EST", DateTime.Parse("07/12/2007 16.00.00"), "Sat, 08 Mar 2008 12:00:00 EST", DateTime.Parse("08/03/2008 11.00.00"), "Sat, 17 May 2008 20:47:57 +0000", DateTime.Parse("17/05/2008 15.47.57"), "Sat, 17 May 2008 19:33:42 +0000", DateTime.Parse("17/05/2008 14.33.42") ); AssertForEach(pairs, delegate(TransformPair <string, DateTime> pair) { Assert.AreEqual(pair.To, Rfc822DateTime.Parse(pair.From)); }); }
/// <summary> /// Converts the specified string representation of a date and time to its <see cref="DateTime"/> equivalent. /// </summary> /// <param name="s">A string containing a date and time to convert.</param> /// <param name="result"> /// When this method returns, contains the <see cref="DateTime"/> value equivalent to the date and time /// contained in <paramref name="s"/>, expressed as <i>Coordinated Universal Time (UTC)</i>, /// if the conversion succeeded, or <see cref="DateTime.MinValue">MinValue</see> if the conversion failed. /// The conversion fails if the s parameter is a <b>null</b> reference (Nothing in Visual Basic), /// or does not contain a valid string representation of a date and time. /// This parameter is passed uninitialized. /// </param> /// <returns><b>true</b> if the <paramref name="s"/> parameter was converted successfully; otherwise, <b>false</b>.</returns> /// <remarks> /// The string <paramref name="s"/> is parsed using formatting information in the <see cref="DateTimeFormatInfo.InvariantInfo"/> object. /// </remarks> public static bool TryParse(string s, out DateTime result) { //------------------------------------------------------------ // Attempt to convert string representation //------------------------------------------------------------ bool wasConverted = false; result = DateTime.MinValue; if (!String.IsNullOrEmpty(s)) { DateTime parseResult; if (DateTime.TryParseExact(Rfc822DateTime.ConvertZoneToLocalDifferential(s), Rfc822DateTime.Rfc822DateTimePatterns, DateTimeFormatInfo.InvariantInfo, DateTimeStyles.AdjustToUniversal, out parseResult)) { result = DateTime.SpecifyKind(parseResult, DateTimeKind.Utc); wasConverted = true; } } return(wasConverted); }
protected override void When() { _date = Rfc822DateTime.Parse("Fri, 04 Dec 2015 17:00:17 UTC"); }
protected override void When() { _date = Rfc822DateTime.Parse("Tue, 22 Mar 2011 12:01:02 Y"); }
protected override void When() { _date = Rfc822DateTime.Parse("Mon, 21 Mar 2011 12:01:02 +0430"); }