public void SetMonthWorks() { var dt = new JsDate(2000, 0, 1); dt.SetMonth(3); Assert.AreEqual(dt.GetMonth(), 3); }
public void YMDConstructorWorks() { var dt = new JsDate(2011, 7, 12); Assert.AreEqual(dt.GetFullYear(), 2011); Assert.AreEqual(dt.GetMonth(), 7); Assert.AreEqual(dt.GetDate(), 12); }
public void StringConstructorWorks() { var dt = new JsDate("Aug 12, 2012"); Assert.AreEqual(dt.GetFullYear(), 2012); Assert.AreEqual(dt.GetMonth(), 7); Assert.AreEqual(dt.GetDate(), 12); }
public void SetFullYearWithTwoParametersWorks() { var dt = new JsDate(2000, 0, 1); dt.SetFullYear(2021, 7); Assert.AreEqual(dt.GetFullYear(), 2021); Assert.AreEqual(dt.GetMonth(), 7); }
public void YMDHNConstructorWorks() { var dt = new JsDate(2011, 7, 12, 13, 42); Assert.AreEqual(dt.GetFullYear(), 2011); Assert.AreEqual(dt.GetMonth(), 7); Assert.AreEqual(dt.GetDate(), 12); Assert.AreEqual(dt.GetHours(), 13); Assert.AreEqual(dt.GetMinutes(), 42); }
public void ConvertingMutableDateToDateReturnsANewButEqualInstance() { var mdt = new JsDate(2011, 7, 12); DateTime dt = (DateTime)mdt; Assert.IsFalse((object)dt == (object)mdt); Assert.AreEqual(mdt.GetFullYear(), 2011); Assert.AreEqual(mdt.GetMonth(), 7); Assert.AreEqual(mdt.GetDate(), 12); }
public override CriteriaWithText GetCriteria() { var result = new CriteriaWithText(); switch (Operator.Key) { case FilterOperators.EQ: case FilterOperators.NE: case FilterOperators.LT: case FilterOperators.LE: case FilterOperators.GT: case FilterOperators.GE: { var text = GetEditorText(); result.DisplayText = DisplayText(Operator, text); var date = Q.ParseISODateTime((string)GetEditorValue()); date = new JsDate(date.GetFullYear(), date.GetMonth(), date.GetDate()); var next = new JsDate(date.GetFullYear(), date.GetMonth(), date.GetDate() + 1); var criteria = new Criteria(GetCriteriaField()); var dateValue = new ValueCriteria(Q.FormatDate(date, "yyyy-MM-dd")); var nextValue = new ValueCriteria(Q.FormatDate(next, "yyyy-MM-dd")); switch (Operator.Key) { case FilterOperators.EQ: result.Criteria = criteria >= dateValue & criteria < nextValue; return(result); case FilterOperators.NE: result.Criteria = ~(criteria <dateValue | criteria> nextValue); return(result); case FilterOperators.LT: result.Criteria = criteria < dateValue; return(result); case FilterOperators.LE: result.Criteria = criteria < nextValue; return(result); case FilterOperators.GT: result.Criteria = criteria >= nextValue; return(result); case FilterOperators.GE: result.Criteria = criteria >= dateValue; return(result); } } break; } return(base.GetCriteria()); }
public void ToLocalWorks() { var utc = new JsDate(2011, 7, 12, 13, 42, 56, 345); var dt = utc.ToLocalTime(); Assert.AreEqual(dt.GetUtcFullYear(), utc.GetFullYear()); Assert.AreEqual(dt.GetUtcMonth(), utc.GetMonth()); Assert.AreEqual(dt.GetUtcDate(), utc.GetDate()); Assert.AreEqual(dt.GetUtcHours(), utc.GetHours()); Assert.AreEqual(dt.GetUtcMinutes(), utc.GetMinutes()); Assert.AreEqual(dt.GetUtcSeconds(), utc.GetSeconds()); Assert.AreEqual(dt.GetUtcMilliseconds(), utc.GetMilliseconds()); }
public void GetMonthWorks() { var dt = new JsDate(2011, 7, 12, 13, 42, 56, 345); Assert.AreEqual(dt.GetMonth(), 7); }
/// <summary> /// Converts a date to string according to a specified format /// </summary> /// <param name="date">Date to format, can be null</param> /// <param name="format">Format specifier</param> /// <returns>Formatted date, or empty string if date is null</returns> public static string FormatDate(this JsDate date, string format = null) { if (date == null) { return(""); } if (format == null) { format = Q.Culture.DateFormat; } Func <int, string> pad = i => i.ToString().PadLeft(2, '0'); return(format.Replace(new Regex("dd?d?d?|MM?M?M?|yy?y?y?|hh?|HH?|mm?|ss?|tt?|fff|zz?z?|\\/", "g"), delegate(string fmt) { switch (fmt) { case "/": return Q.Culture.DateSeparator; case "hh": return pad(date.GetHours() < 13 ? date.GetHours() : (date.GetHours() - 12)); case "h": return (date.GetHours() < 13 ? date.GetHours() : (date.GetHours() - 12)).As <string>(); case "HH": return pad(date.GetHours()); case "H": return date.GetHours().As <string>(); case "mm": return pad(date.GetMinutes()); case "m": return date.GetMinutes().As <string>(); case "ss": return pad(date.GetSeconds()); case "s": return date.GetSeconds().As <string>(); case "yyyy": return date.GetFullYear().As <string>(); case "yy": return date.GetFullYear().ToString().Substring(2, 4); case "dddd": return date.As <dynamic>().GetDayName(); case "ddd": return date.As <dynamic>().GetDayName(true); case "dd": return pad(date.GetDate()); case "d": return date.GetDate().ToString(); case "MM": return pad((date.GetMonth() + 1)); case "M": return (date.GetMonth() + 1).As <string>(); case "t": return (date.GetHours() < 12 ? "A" : "P"); case "tt": return (date.GetHours() < 12 ? "AM" : "PM"); case "fff": return (date.GetMilliseconds()).ToString().PadLeft(3, '0'); case "zzz": case "zz": case "z": return ""; default: return fmt; } })); }