Represents a timespan equivalent to TimeSpan.
Esempio n. 1
0
        private object EvaluateBinaryExpression(ScriptBinaryExpression expression, ScriptTimeSpan left,
                                                ScriptTimeSpan right)
        {
            switch (expression.Operator)
            {
            case ScriptBinaryOperator.Add:
                return(new ScriptTimeSpan(left.value + right.value));

            case ScriptBinaryOperator.Substract:
                return(new ScriptTimeSpan(left.value - right.value));

            case ScriptBinaryOperator.CompareEqual:
                return(left.value == right.value);

            case ScriptBinaryOperator.CompareNotEqual:
                return(left.value != right.value);

            case ScriptBinaryOperator.CompareLess:
                return(left.value < right.value);

            case ScriptBinaryOperator.CompareLessOrEqual:
                return(left.value <= right.value);

            case ScriptBinaryOperator.CompareGreater:
                return(left.value > right.value);

            case ScriptBinaryOperator.CompareGreaterOrEqual:
                return(left.value >= right.value);
            }

            throw new ScriptRuntimeException(expression.Span, $"Operator [{expression.Operator}] is not supported for timespan");
        }
Esempio n. 2
0
        private object EvaluateBinaryExpression(ScriptBinaryExpression expression, ScriptDate left,
                                                ScriptTimeSpan right)
        {
            switch (expression.Operator)
            {
            case ScriptBinaryOperator.Add:
                return(new ScriptDate((DateTime)left + right));
            }

            throw new ScriptRuntimeException(expression.Span, $"Operator [{expression.Operator}] is not supported for between <date> and <timespan>");
        }
Esempio n. 3
0
        /// <summary>
        /// Registers all scriban builtins to the specified <see cref="ScriptObject"/>.
        /// </summary>
        /// <param name="builtins">The builtins object.</param>
        /// <exception cref="System.ArgumentNullException">If builtins is null</exception>
        public static void Register(ScriptObject builtins)
        {
            if (builtins == null)
            {
                throw new ArgumentNullException(nameof(builtins));
            }

            IncludeFunction.Register(builtins);
            ObjectFunctions.Register(builtins);
            ScriptDate.Register(builtins);
            ScriptTimeSpan.Register(builtins);
            ArrayFunctions.Register(builtins);
            StringFunctions.Register(builtins);
            MathFunctions.Register(builtins);
        }
Esempio n. 4
0
        private object EvaluateBinaryExpression(ScriptBinaryExpression expression, ScriptDate left,
            ScriptTimeSpan right)
        {
            switch (expression.Operator)
            {
                case ScriptBinaryOperator.Add:
                    return new ScriptDate((DateTime)left + right);
            }

            throw new ScriptRuntimeException(expression.Span, $"Operator [{expression.Operator}] is not supported for between <date> and <timespan>");
        }
Esempio n. 5
0
        private object EvaluateBinaryExpression(ScriptBinaryExpression expression, ScriptTimeSpan left,
            ScriptTimeSpan right)
        {
            switch (expression.Operator)
            {
                case ScriptBinaryOperator.Add:
                    return new ScriptTimeSpan(left.value + right.value);
                case ScriptBinaryOperator.Substract:
                    return new ScriptTimeSpan(left.value - right.value);
                case ScriptBinaryOperator.CompareEqual:
                    return left.value == right.value;
                case ScriptBinaryOperator.CompareNotEqual:
                    return left.value != right.value;
                case ScriptBinaryOperator.CompareLess:
                    return left.value < right.value;
                case ScriptBinaryOperator.CompareLessOrEqual:
                    return left.value <= right.value;
                case ScriptBinaryOperator.CompareGreater:
                    return left.value > right.value;
                case ScriptBinaryOperator.CompareGreaterOrEqual:
                    return left.value >= right.value;
            }

            throw new ScriptRuntimeException(expression.Span, $"Operator [{expression.Operator}] is not supported for timespan");
        }