/// <summary> /// Creates a date expression with symbol scope, context, script refernce set. /// The date expression can handle relative dates: 'today', 'yesterday', 'tomorrow' /// </summary> /// <param name="name"></param> /// <returns></returns> public static Expr Day(string name, string time, TokenData token) { var exp = new DayExpr(); exp.Name = name; exp.Time = time; SetupContext(exp, token); return(exp); }
/// <summary> /// Check the day expression. /// </summary> public object VisitDay(DayExpr expr) { return(null); }
/// <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); }