public static DateTime Evaluate(string value) { DateTime result; if (DateMath.TryEvaluate(value, out result)) { return(result); } throw new FormatException("Invalid format: '" + value + "'."); }
public static bool TryParse(string value, out DateTimeWindow result) { if (string.IsNullOrEmpty(value)) { throw new ArgumentNullException("value"); } var match = StringFormatExpression.Match(value); if (!match.Success) { result = null; return(false); } var startExpr = match.Groups["start"].Value; DateTime?start = null; if (startExpr != "*" && !DateMath.TryEvaluate(startExpr, out start)) { result = null; return(false); } var endExpr = match.Groups["end"].Value; DateTime?end = null; if (endExpr != "*" && !DateMath.TryEvaluate(endExpr, out end)) { result = null; return(false); } result = new DateTimeWindow(start, end); return(true); }