Ejemplo n.º 1
0
        public void TestComputeDelta()
        {
            ExprTimePeriod timePeriod = new ExprTimePeriodImpl(
                TimeZoneInfo.Local,
                false, true, false, false, false, false, false, false, false,
                TimeAbacusMilliseconds.INSTANCE,
                _container.LockManager());

            timePeriod.AddChildNode(new ExprConstantNodeImpl(1));
            timePeriod.Validate(null);

            ExprTimePeriodEvalDeltaConstGivenDtxAdd addMonth = (ExprTimePeriodEvalDeltaConstGivenDtxAdd)timePeriod.ConstEvaluator(null);

            Assert.AreEqual(28 * 24 * 60 * 60 * 1000L, addMonth.DeltaAdd(Parse("2002-02-15T09:00:00.000")));
            Assert.AreEqual(28 * 24 * 60 * 60 * 1000L, addMonth.DeltaSubtract(Parse("2002-03-15T09:00:00.000")));

            ExprTimePeriodEvalDeltaResult result = addMonth.DeltaAddWReference(
                Parse("2002-02-15T09:00:00.000"), Parse("2002-02-15T09:00:00.000"));

            Assert.AreEqual(Parse("2002-03-15T09:00:00.000") - Parse("2002-02-15T09:00:00.000"), result.Delta);
            Assert.AreEqual(Parse("2002-02-15T09:00:00.000"), result.LastReference);

            result = addMonth.DeltaAddWReference(
                Parse("2002-03-15T09:00:00.000"), Parse("2002-02-15T09:00:00.000"));
            Assert.AreEqual(Parse("2002-04-15T09:00:00.000") - Parse("2002-03-15T09:00:00.000"), result.Delta);
            Assert.AreEqual(Parse("2002-03-15T09:00:00.000"), result.LastReference);

            result = addMonth.DeltaAddWReference(
                Parse("2002-04-15T09:00:00.000"), Parse("2002-03-15T09:00:00.000"));
            Assert.AreEqual(Parse("2002-05-15T09:00:00.000") - Parse("2002-04-15T09:00:00.000"), result.Delta);
            Assert.AreEqual(Parse("2002-04-15T09:00:00.000"), result.LastReference);

            // try future reference
            result = addMonth.DeltaAddWReference(
                Parse("2002-02-15T09:00:00.000"), Parse("2900-03-15T09:00:00.000"));
            Assert.AreEqual(Parse("2002-03-15T09:00:00.000") - Parse("2002-02-15T09:00:00.000"), result.Delta);
            Assert.AreEqual(Parse("2002-02-15T09:00:00.000"), result.LastReference);

            // try old reference
            result = addMonth.DeltaAddWReference(
                Parse("2002-02-15T09:00:00.000"), Parse("1980-03-15T09:00:00.000"));
            Assert.AreEqual(Parse("2002-03-15T09:00:00.000") - Parse("2002-02-15T09:00:00.000"), result.Delta);
            Assert.AreEqual(Parse("2002-02-15T09:00:00.000"), result.LastReference);

            // try different-dates
            result = addMonth.DeltaAddWReference(
                Parse("2002-02-18T09:00:00.000"), Parse("1980-03-15T09:00:00.000"));
            Assert.AreEqual(Parse("2002-03-15T09:00:00.000") - Parse("2002-02-18T09:00:00.000"), result.Delta);
            Assert.AreEqual(Parse("2002-02-15T09:00:00.000"), result.LastReference);

            result = addMonth.DeltaAddWReference(
                Parse("2002-02-11T09:00:00.000"), Parse("2980-03-15T09:00:00.000"));
            Assert.AreEqual(Parse("2002-02-15T09:00:00.000") - Parse("2002-02-11T09:00:00.000"), result.Delta);
            Assert.AreEqual(Parse("2002-01-15T09:00:00.000"), result.LastReference);

            result = addMonth.DeltaAddWReference(
                Parse("2002-04-05T09:00:00.000"), Parse("2002-02-11T09:01:02.003"));
            Assert.AreEqual(Parse("2002-04-11T09:01:02.003") - Parse("2002-04-05T09:00:00.000"), result.Delta);
            Assert.AreEqual(Parse("2002-03-11T09:01:02.003"), result.LastReference);
        }
Ejemplo n.º 2
0
        public static ExprTimePeriod TimePeriodGetExprJustSeconds(EsperEPL2GrammarParser.ExpressionContext expression, IDictionary <ITree, ExprNode> astExprNodeMap, ConfigurationInformation config)
        {
            var node     = ExprCollectSubNodes(expression, 0, astExprNodeMap)[0];
            var timeNode = new ExprTimePeriodImpl(config.EngineDefaults.ExpressionConfig.TimeZone,
                                                  false, false, false, false, false, false, true, false);

            timeNode.AddChildNode(node);
            return(timeNode);
        }
Ejemplo n.º 3
0
 public static ExprTimePeriod TimePeriodGetExprJustSeconds(
     EsperEPL2GrammarParser.ExpressionContext expression,
     IDictionary<ITree, ExprNode> astExprNodeMap,
     TimeAbacus timeAbacus)
 {
     ExprNode node = ExprCollectSubNodes(expression, 0, astExprNodeMap)[0];
     ExprTimePeriod timeNode = new ExprTimePeriodImpl(false, false, false, false, false, false, true, false, false, timeAbacus);
     timeNode.AddChildNode(node);
     return timeNode;
 }
Ejemplo n.º 4
0
 public void QExprTimePeriod(ExprTimePeriodImpl exprTimePeriod)
 {
 }
Ejemplo n.º 5
0
        public static ExprTimePeriod TimePeriodGetExprAllParams(EsperEPL2GrammarParser.TimePeriodContext ctx, IDictionary <ITree, ExprNode> astExprNodeMap, VariableService variableService, StatementSpecRaw spec, ConfigurationInformation config)
        {
            var nodes = new ExprNode[8];

            for (var i = 0; i < ctx.ChildCount; i++)
            {
                var unitRoot = ctx.GetChild(i);

                ExprNode valueExpr;
                if (ASTUtil.IsTerminatedOfType(unitRoot.GetChild(0), EsperEPL2GrammarLexer.IDENT))
                {
                    var ident = unitRoot.GetChild(0).GetText();
                    valueExpr = ASTExprHelper.ResolvePropertyOrVariableIdentifier(ident, variableService, spec);
                }
                else
                {
                    var        @ref   = new Atomic <ExprNode>();
                    ExprAction action = (exprNode, astExprNodeMapX, nodeX) => {
                        astExprNodeMapX.Remove(nodeX);
                        @ref.Set(exprNode);
                    };
                    ASTExprHelper.RecursiveFindRemoveChildExprNode(unitRoot.GetChild(0), astExprNodeMap, action);
                    valueExpr = @ref.Get();
                }

                if (ASTUtil.GetRuleIndexIfProvided(unitRoot) == EsperEPL2GrammarParser.RULE_millisecondPart)
                {
                    nodes[7] = valueExpr;
                }
                if (ASTUtil.GetRuleIndexIfProvided(unitRoot) == EsperEPL2GrammarParser.RULE_secondPart)
                {
                    nodes[6] = valueExpr;
                }
                if (ASTUtil.GetRuleIndexIfProvided(unitRoot) == EsperEPL2GrammarParser.RULE_minutePart)
                {
                    nodes[5] = valueExpr;
                }
                if (ASTUtil.GetRuleIndexIfProvided(unitRoot) == EsperEPL2GrammarParser.RULE_hourPart)
                {
                    nodes[4] = valueExpr;
                }
                if (ASTUtil.GetRuleIndexIfProvided(unitRoot) == EsperEPL2GrammarParser.RULE_dayPart)
                {
                    nodes[3] = valueExpr;
                }
                if (ASTUtil.GetRuleIndexIfProvided(unitRoot) == EsperEPL2GrammarParser.RULE_weekPart)
                {
                    nodes[2] = valueExpr;
                }
                if (ASTUtil.GetRuleIndexIfProvided(unitRoot) == EsperEPL2GrammarParser.RULE_monthPart)
                {
                    nodes[1] = valueExpr;
                }
                if (ASTUtil.GetRuleIndexIfProvided(unitRoot) == EsperEPL2GrammarParser.RULE_yearPart)
                {
                    nodes[0] = valueExpr;
                }
            }

            ExprTimePeriod timeNode = new ExprTimePeriodImpl(config.EngineDefaults.ExpressionConfig.TimeZone,
                                                             nodes[0] != null, nodes[1] != null, nodes[2] != null, nodes[3] != null, nodes[4] != null, nodes[5] != null, nodes[6] != null, nodes[7] != null);

            if (nodes[0] != null)
            {
                timeNode.AddChildNode(nodes[0]);
            }
            if (nodes[1] != null)
            {
                timeNode.AddChildNode(nodes[1]);
            }
            if (nodes[2] != null)
            {
                timeNode.AddChildNode(nodes[2]);
            }
            if (nodes[3] != null)
            {
                timeNode.AddChildNode(nodes[3]);
            }
            if (nodes[4] != null)
            {
                timeNode.AddChildNode(nodes[4]);
            }
            if (nodes[5] != null)
            {
                timeNode.AddChildNode(nodes[5]);
            }
            if (nodes[6] != null)
            {
                timeNode.AddChildNode(nodes[6]);
            }
            if (nodes[7] != null)
            {
                timeNode.AddChildNode(nodes[7]);
            }
            return(timeNode);
        }
Ejemplo n.º 6
0
        public static ExprTimePeriod TimePeriodGetExprAllParams(
            EsperEPL2GrammarParser.TimePeriodContext ctx,
            IDictionary<ITree, ExprNode> astExprNodeMap,
            VariableCompileTimeResolver variableCompileTimeResolver,
            StatementSpecRaw spec,
            Configuration config,
            TimeAbacus timeAbacus)
        {
            ExprNode[] nodes = new ExprNode[9];
            for (int i = 0; i < ctx.ChildCount; i++)
            {
                IParseTree unitRoot = ctx.GetChild(i);

                ExprNode valueExpr;
                if (ASTUtil.IsTerminatedOfType(unitRoot.GetChild(0), EsperEPL2GrammarLexer.IDENT))
                {
                    string ident = unitRoot.GetChild(0).GetText();
                    valueExpr = ASTExprHelper.ResolvePropertyOrVariableIdentifier(ident, variableCompileTimeResolver, spec);
                }
                else
                {
                    AtomicReference<ExprNode> @ref = new AtomicReference<ExprNode>();
                    ExprAction action = (exprNode, astExprNodeMapX, node) => {
                        astExprNodeMapX.Remove(node);
                        @ref.Set(exprNode);
                    };
                    ASTExprHelper.RecursiveFindRemoveChildExprNode(unitRoot.GetChild(0), astExprNodeMap, action);
                    valueExpr = @ref.Get();
                }

                if (ASTUtil.GetRuleIndexIfProvided(unitRoot) == EsperEPL2GrammarParser.RULE_microsecondPart)
                {
                    nodes[8] = valueExpr;
                }

                if (ASTUtil.GetRuleIndexIfProvided(unitRoot) == EsperEPL2GrammarParser.RULE_millisecondPart)
                {
                    nodes[7] = valueExpr;
                }

                if (ASTUtil.GetRuleIndexIfProvided(unitRoot) == EsperEPL2GrammarParser.RULE_secondPart)
                {
                    nodes[6] = valueExpr;
                }

                if (ASTUtil.GetRuleIndexIfProvided(unitRoot) == EsperEPL2GrammarParser.RULE_minutePart)
                {
                    nodes[5] = valueExpr;
                }

                if (ASTUtil.GetRuleIndexIfProvided(unitRoot) == EsperEPL2GrammarParser.RULE_hourPart)
                {
                    nodes[4] = valueExpr;
                }

                if (ASTUtil.GetRuleIndexIfProvided(unitRoot) == EsperEPL2GrammarParser.RULE_dayPart)
                {
                    nodes[3] = valueExpr;
                }

                if (ASTUtil.GetRuleIndexIfProvided(unitRoot) == EsperEPL2GrammarParser.RULE_weekPart)
                {
                    nodes[2] = valueExpr;
                }

                if (ASTUtil.GetRuleIndexIfProvided(unitRoot) == EsperEPL2GrammarParser.RULE_monthPart)
                {
                    nodes[1] = valueExpr;
                }

                if (ASTUtil.GetRuleIndexIfProvided(unitRoot) == EsperEPL2GrammarParser.RULE_yearPart)
                {
                    nodes[0] = valueExpr;
                }
            }

            ExprTimePeriod timeNode = new ExprTimePeriodImpl(
                nodes[0] != null, nodes[1] != null,
                nodes[2] != null, nodes[3] != null,
                nodes[4] != null, nodes[5] != null,
                nodes[6] != null, nodes[7] != null,
                nodes[8] != null, timeAbacus);

            foreach (ExprNode node in nodes)
            {
                if (node != null)
                {
                    timeNode.AddChildNode(node);
                }
            }

            return timeNode;
        }