private static (object value, string error) Evaluator(Expression expression, IMemory state, Options options) { TimexProperty parsed = null; string value = null; string error = null; IReadOnlyList <object> args; (args, error) = FunctionUtils.EvaluateChildren(expression, state, options); if (error == null) { (parsed, error) = FunctionUtils.ParseTimexProperty(args[0]); } // if the parsed TimexProperty has no types, then it cannot be resolved if (error == null && parsed.Types.Count == 0) { error = $"The parsed TimexProperty of {args[0]} in {expression} has no types. It can't be resolved to a string value."; } if (error == null) { var formatedTimex = TimexFormat.Format(parsed); try { var resolvedValues = TimexResolver.Resolve(new string[] { formatedTimex }); value = resolvedValues.Values[0].Value; } catch (ArgumentException err) { error = $"{args[0]} in {expression} is not a valid argument. {err.Message}"; } } return(value, error); }
public void DataTypes_Creator_Today() { var d = System.DateTime.Now; var expected = TimexFormat.Format(new TimexProperty { Year = d.Year, Month = d.Month, DayOfMonth = d.Day }); Assert.AreEqual(expected, TimexCreator.Today()); }
public void DataTypes_Creator_WeekBackFromToday() { var d = System.DateTime.Now; d = d.AddDays(-7); var expected = TimexFormat.Format(new TimexProperty { Year = d.Year, Month = d.Month, DayOfMonth = d.Day, Days = 7 }); Assert.AreEqual(expected, TimexCreator.WeekBackFromToday()); }