public void TestSmartDateConstructors() { DateTime now = DateTime.Now; Csla.SmartDate d = new Csla.SmartDate(now); Assert.AreEqual(now, d.Date); d = new Csla.SmartDate(true); Assert.IsTrue(d.EmptyIsMin); d = new Csla.SmartDate(false); Assert.IsFalse(d.EmptyIsMin); d = new Csla.SmartDate("1/1/2005"); Assert.AreEqual("1/1/2005", d.ToString()); d = new Csla.SmartDate("Jan/1/2005"); Assert.AreEqual("1/1/2005", d.ToString()); d = new Csla.SmartDate("January-1-2005"); Assert.AreEqual("1/1/2005", d.ToString()); d = new Csla.SmartDate("1-1-2005"); Assert.AreEqual("1/1/2005", d.ToString()); d = new Csla.SmartDate(""); Assert.AreEqual("", d.ToString()); Assert.IsTrue(d.IsEmpty); d = new Csla.SmartDate("1/1/2005", true); Assert.AreEqual("1/1/2005", d.ToString()); Assert.IsTrue(d.EmptyIsMin); d = new Csla.SmartDate("1/1/2005", false); Assert.AreEqual("1/1/2005", d.ToString()); Assert.IsFalse(d.EmptyIsMin); d = new Csla.SmartDate("", true); Assert.AreEqual(DateTime.MinValue, d.Date); Assert.AreEqual("", d.ToString()); d = new Csla.SmartDate("", false); Assert.AreEqual(DateTime.MaxValue, d.Date); Assert.AreEqual("", d.ToString()); try { d = new Csla.SmartDate("Invalid Date", true); } catch (Exception ex) { Assert.IsTrue(ex is ArgumentException); } try { d = new Csla.SmartDate("Invalid Date", false); } catch (Exception ex) { Assert.IsTrue(ex is ArgumentException); } d = new Csla.SmartDate(now, true); Assert.AreEqual(now, d.Date); Assert.IsTrue(d.EmptyIsMin); d = new Csla.SmartDate(now, false); Assert.AreEqual(now, d.Date); Assert.IsFalse(d.EmptyIsMin); }
private void SetMyValue(string text, bool updateBaseValue) { var tempdate = new SmartDate(true); if (SmartDate.TryParse(text, SmartDate.EmptyValue.MinDate, ref tempdate)) { if (tempdate.CompareTo(_mySmartDate) != 0) { _mySmartDate.Text = tempdate.ToString(_customFormat); } } UpdateMyTextBox(); if (updateBaseValue) { SetBaseValue(); } }