public void CanParseShouldHandleValid24HourPatterns() { var parser = new TimeStringParser(); Assert.IsTrue(parser.CanParse("10:12:55"), "Could not parse 10:12:55"); Assert.IsTrue(parser.CanParse("22:12:55"), "Could not parse 13:12:55"); Assert.IsTrue(parser.CanParse("13"), "Could not parse 13"); Assert.IsTrue(parser.CanParse("13:12"), "Could not parse 13:12"); }
public void CanParseShouldHandleValid12HourPatterns() { var parser = new TimeStringParser(); Assert.IsTrue(parser.CanParse("10:12:55 AM"), "Could not parse 10:12:55 AM"); Assert.IsTrue(parser.CanParse("9:12:55 PM"), "Could not parse 9:12:55 PM"); Assert.IsTrue(parser.CanParse("7 AM"), "Could not parse 7 AM"); Assert.IsTrue(parser.CanParse("4:12 PM"), "Could not parse 4:12 PM"); }
public override CompileResult Execute(IEnumerable <FunctionArgument> arguments, ParsingContext context) { ValidateArguments(arguments, 1); var firstArg = arguments.ElementAt(0).Value.ToString(); if (arguments.Count() == 1 && TimeStringParser.CanParse(firstArg)) { var result = TimeStringParser.Parse(firstArg); return(CreateResult(GetSecondFromSerialNumber(result), DataType.Integer)); } ValidateAndInitSerialNumber(arguments); return(CreateResult(GetSecondFromSerialNumber(SerialNumber), DataType.Integer)); }
public override CompileResult Execute(IEnumerable<FunctionArgument> arguments, ParsingContext context) { ValidateArguments(arguments, 1); var firstArg = arguments.ElementAt(0).Value.ToString(); if (arguments.Count() == 1 && TimeStringParser.CanParse(firstArg)) { var result = TimeStringParser.Parse(firstArg); return new CompileResult(result, DataType.Time); } ValidateArguments(arguments, 3); var hour = ArgToInt(arguments, 0); var min = ArgToInt(arguments, 1); var sec = ArgToInt(arguments, 2); ThrowArgumentExceptionIf(() => sec < 0 || sec > 59, "Invalid second: " + sec); ThrowArgumentExceptionIf(() => min < 0 || min > 59, "Invalid minute: " + min); ThrowArgumentExceptionIf(() => min < 0 || hour > 23, "Invalid hour: " + hour); var secondsOfThisTime = (double)(hour * 60 * 60 + min * 60 + sec); return CreateResult(GetTimeSerialNumber(secondsOfThisTime), DataType.Time); }