public void Can_Do_Date_SetMethods() { var lsmethods = new LJSDateMethods(); lsmethods.Init(); var testdate = new DateTime(2012, 9, 15, 10, 30, 00); var l = new LDate(testdate); l.Value = testdate; Check(2013, (ld) => ld.Value.Year, l, (ldate) => lsmethods.SetFullYear(ldate, 2013, 4, 1)); l.Value = testdate; Check(4, (ld) => ld.Value.Month, l, (ldate) => lsmethods.SetFullYear(ldate, 2013, 4, 1)); l.Value = testdate; Check(1, (ld) => ld.Value.Day, l, (ldate) => lsmethods.SetFullYear(ldate, 2013, 4, 1)); l.Value = testdate; Check(4, (ld) => ld.Value.Month, l, (ldate) => lsmethods.SetMonth(ldate, 4, 1)); l.Value = testdate; Check(1, (ld) => ld.Value.Day, l, (ldate) => lsmethods.SetDate(ldate, 1)); l.Value = testdate; Check(4, (ld) => ld.Value.Hour, l, (ldate) => lsmethods.SetHours(ldate, 4, 30, 1, 150)); l.Value = testdate; Check(30, (ld) => ld.Value.Minute, l, (ldate) => lsmethods.SetMinutes(ldate, 30, 1, 150)); l.Value = testdate; Check(1, (ld) => ld.Value.Second, l, (ldate) => lsmethods.SetSeconds(ldate, 1, 150)); l.Value = testdate; Check(150, (ld) => ld.Value.Millisecond, l, (ldate) => lsmethods.SetMilliseconds(ldate, 150)); }
private void Check(int expected, Func <LDate, int> callbackForActual, LDate l, Action <LDate> callback) { callback(l); var actual = callbackForActual(l); Assert.AreEqual(expected, actual); }
/// <summary> /// Evaluates a math expression of 2 time spans. /// </summary> /// <param name="node">The AST node the evaluation is a part of.</param> /// <param name="lhs">The time on the left hand side</param> /// <param name="rhs">The time on the right hand side</param> /// <param name="op">The math operator.</param> /// <returns></returns> public static LBool CompareDates(AstNode node, LDate lhs, LDate rhs, Operator op) { var left = lhs.Value; var right = rhs.Value; var result = false; if (op == Operator.LessThan) { result = left < right; } else if (op == Operator.LessThanEqual) { result = left <= right; } else if (op == Operator.MoreThan) { result = left > right; } else if (op == Operator.MoreThanEqual) { result = left >= right; } else if (op == Operator.EqualEqual) { result = left == right; } else if (op == Operator.NotEqual) { result = left != right; } return(new LBool(result)); }
/// <summary> /// Evaluates a math expression of 2 time spans. /// </summary> /// <param name="node">The AST node the evaluation is a part of.</param> /// <param name="lhs">The time on the left hand side</param> /// <param name="rhs">The time on the right hand side</param> /// <param name="op">The math operator.</param> /// <returns></returns> public static LTime CalcDates(AstNode node, LDate lhs, LDate rhs, Operator op) { if (op != Operator.Subtract) { throw ExceptionHelper.BuildRunTimeException(node, "Can only subtract dates"); } var left = lhs.Value; var right = rhs.Value; var result = left - right; return(new LTime(result)); }
private static void SetDateTime(LDate date, DateTimeKind kind, int year = -1, int month = -1, int day = -1, int hour = -1, int minute = -1, int second = -1, int millisecond = -1) { var target = date.Value; DateTime dt = kind == DateTimeKind.Utc ? target.ToUniversalTime() : target; year = year == -1 ? dt.Year : year; month = month == -1 ? dt.Month : month; day = day == -1 ? dt.Day : day; hour = hour == -1 ? dt.Hour : hour; minute = minute == -1 ? dt.Minute : minute; second = second == -1 ? dt.Second : second; millisecond = millisecond == -1 ? dt.Millisecond : millisecond; var finalDateTime = new DateTime(year, month, day, hour, minute, second, millisecond, kind); date.Value = finalDateTime; }
public void Can_Do_Date_SetMethods_Via_Execute() { var lsmethods = new LJSDateMethods(); lsmethods.Init(); var testdate = new DateTime(2012, 9, 15, 10, 30, 00); var l = new LDate(testdate); l.Value = testdate; Check(2013, (ld) => ld.Value.Year, l, (ldate) => lsmethods.ExecuteMethod(ldate, "setFullYear", new object[] { 2013, 4, 1 })); l.Value = testdate; Check(4, (ld) => ld.Value.Month, l, (ldate) => lsmethods.ExecuteMethod(ldate, "setFullYear", new object[] { 2013, 4, 1 })); l.Value = testdate; Check(1, (ld) => ld.Value.Day, l, (ldate) => lsmethods.ExecuteMethod(ldate, "setFullYear", new object[] { 2013, 4, 1 })); l.Value = testdate; Check(4, (ld) => ld.Value.Month, l, (ldate) => lsmethods.ExecuteMethod(ldate, "setMonth", new object[] { 4, 1 })); l.Value = testdate; Check(1, (ld) => ld.Value.Day, l, (ldate) => lsmethods.ExecuteMethod(ldate, "setDate", new object[] { 1 })); l.Value = testdate; Check(4, (ld) => ld.Value.Hour, l, (ldate) => lsmethods.ExecuteMethod(ldate, "setHours", new object[] { 4, 30, 1, 150 })); l.Value = testdate; Check(30, (ld) => ld.Value.Minute, l, (ldate) => lsmethods.ExecuteMethod(ldate, "setMinutes", new object[] { 30, 1, 150 })); l.Value = testdate; Check(1, (ld) => ld.Value.Second, l, (ldate) => lsmethods.ExecuteMethod(ldate, "setSeconds", new object[] { 1, 150 })); l.Value = testdate; Check(150, (ld) => ld.Value.Millisecond, l, (ldate) => lsmethods.ExecuteMethod(ldate, "setMilliseconds", new object[] { 150 })); }
/// <summary> /// Sets the full year on the date. /// </summary> /// <param name="date">The LDateType to set</param> /// <param name="year">The year to set</param> /// <param name="month">The month to set</param> /// <param name="day">The day of the month to set</param> public void SetUtcFullYear(LDate date, int year, int month, int day) { SetDateTime(date, DateTimeKind.Utc, year, month, day); }
public string ToString (LDate target) { var date = target.Value; return date.ToString("ddd MMM dd yyyy hh mm ss"); }
public string ToLocaleDateString(LDate target) { var date = target.Value; return(date.ToLocalTime().ToString("ddd MMM dd yyyy")); }
public int GetUtcDate (LDate target) { var date = target.Value; return date.ToUniversalTime().Day; }
public int GetUtcMonth(LDate target) { var date = target.Value; return(date.ToUniversalTime().Month); }
public int GetDate (LDate target) { var date = target.Value; return date.Day; }
public int GetMilliseconds (LDate target) { var date = target.Value; return date.Millisecond; }
/// <summary> /// Sets the milliseconds on the date /// </summary> /// <param name="date">The LDateType to set</param> /// <param name="milliseconds">The milliseconds to set</param> public void SetMilliseconds(LDate date, int milliseconds) { SetDateTime(date, DateTimeKind.Local, -1, -1, -1, -1, -1, -1, milliseconds); }
/// <summary> /// Sets the month on the date. /// </summary> /// <param name="date">The LDateType to set</param> /// <param name="month">The month to set</param> /// <param name="day">The day of the month to set</param> public void SetMonth(LDate date, int month, int day) { SetDateTime(date, DateTimeKind.Local, -1, month, day); }
/// <summary> /// Sets the day of the month on the date /// </summary> /// <param name="date">The LDateType to set</param> /// <param name="day">The day of the month to set</param> public void SetDate(LDate date, int day) { SetDateTime(date, DateTimeKind.Local, -1, -1, day); }
public string ToUtcString(LDate target) { var date = target.Value; return(date.ToUniversalTime().ToString("ddd MMM dd yyyy hh mm ss")); }
public string ToTimeString(LDate target) { var date = target.Value; return(date.ToString("hh mm ss")); }
public string ToString(LDate target) { var date = target.Value; return(date.ToString("ddd MMM dd yyyy hh mm ss")); }
/// <summary> /// Sets the day of the month on the date. /// </summary> /// <param name="date">The LDateType to set</param> /// <param name="day">The day of the month to set</param> public void SetUtcDate(LDate date, int day) { SetDateTime(date, DateTimeKind.Utc, -1, -1, day); }
/// <summary> /// Sets the month on the date. /// </summary> /// <param name="date">The LDateType to set</param> /// <param name="month">The month to set</param> /// <param name="day">The day of the month to set</param> public void SetUtcMonth(LDate date, int month, int day) { SetDateTime(date, DateTimeKind.Utc, -1, month, day); }
/// <summary> /// Sets the milliseconds on the date. /// </summary> /// <param name="date">The LDateType to set</param> /// <param name="milliseconds">The milliseconds to set</param> public void SetUtcMilliseconds(LDate date, int milliseconds) { SetDateTime(date, DateTimeKind.Utc, -1, -1, -1, -1, -1, -1, milliseconds); }
public int GetFullYear (LDate target) { var date = target.Value; return date.Year; }
/// <summary> /// Sets the hours on the date. /// </summary> /// <param name="date">The LDateType to set</param> /// <param name="hours">The hours to set</param> /// <param name="minutes">The minutes to set</param> /// <param name="seconds">The seconds to set</param> /// <param name="milliseconds">The milliseconds to set</param> public void SetUtcHours(LDate date, int hours, int minutes, int seconds, int milliseconds) { SetDateTime(date, DateTimeKind.Utc, -1, -1, -1, hours, minutes, seconds, milliseconds); }
public int GetMonth (LDate target) { var date = target.Value; return date.Month; }
public int GetUtcFullYear (LDate target) { var date = target.Value; return date.ToUniversalTime().Year; }
public string ToUtcString (LDate target) { var date = target.Value; return date.ToUniversalTime().ToString("ddd MMM dd yyyy hh mm ss"); }
public string ToLocaleDateString (LDate target) { var date = target.Value; return date.ToLocalTime().ToString("ddd MMM dd yyyy"); }
public string ToTimeString (LDate target) { var date = target.Value; return date.ToString("hh mm ss"); }
public int GetUtcSeconds(LDate target) { var date = target.Value; return(date.ToUniversalTime().Second); }
public int GetDate(LDate target) { var date = target.Value; return(date.Day); }
public int GetDay(LDate target) { var date = target.Value; return((int)date.DayOfWeek); }
public int GetFullYear(LDate target) { var date = target.Value; return(date.Year); }
//Check and return fine details for one book public void FindBookFine(string BookID, out bool isBFine, out double Fine, out int Days, out DateTime iDate, out string MemID, out bool IsBlocked, out int MTi) { //Declarations string MType; DateTime LDate; MTi = 2; //Temporary Declarations isBFine = false; Fine = 0; Days = 0; iDate = DateTime.Today; MemID = "ERROR"; //Get the Lending detains from LendStatus relation string sqlLDetail = string.Format("SELECT LendDate, MemberID, Extend FROM LendStatus WHERE BookID = '{0}'", BookID); OleDbCommand cmdLDetail = new OleDbCommand(sqlLDetail, db.con); if (db.con.State.Equals(ConnectionState.Closed)) { db.con.Open(); } OleDbDataReader drLDetail = cmdLDetail.ExecuteReader(); drLDetail.Read(); MemID = drLDetail["MemberID"].ToString(); // Get MemID //Get MemberType from MemID to get number of days and get old fines in account string sqlMDetail = string.Format("SELECT MType, MStatus FROM Member WHERE MemberID = '{0}'", MemID); OleDbCommand cmdMDetail = new OleDbCommand(sqlMDetail, db.con); OleDbDataReader drMDetail = cmdMDetail.ExecuteReader(); drMDetail.Read(); //Load Status to variable if (drMDetail["MStatus"].ToString() == "Blocked") { IsBlocked = true; } else { IsBlocked = false; } //Load Type to variable MType = drMDetail["MType"].ToString(); //From MType, get number of days can be kept if (MType == "Adult") { MTi = 0; } else { MTi = 1; } LDate = DateTime.Parse(drLDetail["LendDate"].ToString()); iDate = LDate.AddDays(set.Btime[MTi]); // Find the date when the book should be returned Days = DateTime.Today.Subtract(iDate).Days; // Find the days between today and that date if (Days <= 0) { isBFine = false; } else { isBFine = true; Fine = set.Fine[MTi] * Days; // Calculate Fines from Days and fine per day Fine = double.Parse(Math.Round(decimal.Parse(Fine.ToString()), 1).ToString()); //Round to 1 decimal } }
public int GetUtcHours(LDate target) { var date = target.Value; return(date.ToUniversalTime().Hour); }
public int GetDay (LDate target) { var date = target.Value; return (int)date.DayOfWeek; }
/// <summary> /// Execute the continue. /// </summary> public object VisitDay(DayExpr expr) { var date = DateTime.Today; var dayOfweek = DayOfWeek.Monday; var isDayOfWeek = false; var isTimeSpecified = expr.Time != "0"; var dayName = expr.Name.ToLower(); // 1. Determine date/day if (dayName == "today") { date = DateTime.Today; } else if (dayName == "yesterday") { date = DateTime.Today.AddDays(-1); } else if (dayName == "tomorrow") { date = DateTime.Today.AddDays(1); } else if (dayName == "monday") { isDayOfWeek = true; dayOfweek = DayOfWeek.Monday; } else if (dayName == "tuesday") { isDayOfWeek = true; dayOfweek = DayOfWeek.Tuesday; } else if (dayName == "wednesday") { isDayOfWeek = true; dayOfweek = DayOfWeek.Wednesday; } else if (dayName == "thursday") { isDayOfWeek = true; dayOfweek = DayOfWeek.Thursday; } else if (dayName == "friday") { isDayOfWeek = true; dayOfweek = DayOfWeek.Friday; } else if (dayName == "saturday") { isDayOfWeek = true; dayOfweek = DayOfWeek.Saturday; } else if (dayName == "sunday") { isDayOfWeek = true; dayOfweek = DayOfWeek.Sunday; } // Case 1 - if (isDayOfWeek) { // Case 1a: day of week only if (!isTimeSpecified) { return(new LDayOfWeek(dayOfweek)); } // Case 1b: day of week ( with time ) var today = DateTime.Today; var count = 0; while (today.DayOfWeek != dayOfweek && count < 8) { today = today.AddDays(1); } } // 3. Finally - add the time to the day. if (expr.Time != "0") { var t = TimeSpan.Parse(expr.Time); date = date.AddMilliseconds(t.TotalMilliseconds); } var result = new LDate(date); return(result); }
public int GetHours (LDate target) { var date = target.Value; return date.Hour; }
public int GetUtcFullYear(LDate target) { var date = target.Value; return(date.ToUniversalTime().Year); }
public int GetMinutes (LDate target) { var date = target.Value; return date.Minute; }
public int GetUtcMilliseconds (LDate target) { var date = target.Value; return date.ToUniversalTime().Millisecond; }
public int GetSeconds (LDate target) { var date = target.Value; return date.Second; }
public int GetUtcDay(LDate target) { var date = target.Value; return((int)date.ToUniversalTime().DayOfWeek); }
public int GetUtcDay (LDate target) { var date = target.Value; return (int)date.ToUniversalTime().DayOfWeek; }
public int GetUtcMonth (LDate target) { var date = target.Value; return date.ToUniversalTime().Month; }
public int GetUtcHours (LDate target) { var date = target.Value; return date.ToUniversalTime().Hour; }
public int GetUtcMinutes(LDate target) { var date = target.Value; return(date.ToUniversalTime().Minute); }
public int GetUtcMinutes (LDate target) { var date = target.Value; return date.ToUniversalTime().Minute; }
public int GetUtcDate(LDate target) { var date = target.Value; return(date.ToUniversalTime().Day); }