public IntervalComputerConstantCoincides(IntervalStartEndParameterPairForge pair)
 {
     start = pair.Start.OptionalConstant.GetValueOrDefault();
     end   = pair.End.OptionalConstant.GetValueOrDefault();
     if (start < 0 || end < 0)
     {
         throw new ExprValidationException(
                   "The coincides date-time method does not allow negative start and end values");
     }
 }
Exemplo n.º 2
0
 public IntervalComputerCoincidesWithDeltaExprForge(IntervalStartEndParameterPairForge pair)
 {
     start  = pair.Start.Forge;
     finish = pair.End.Forge;
 }
Exemplo n.º 3
0
 public IntervalComputerConstantBefore(IntervalStartEndParameterPairForge pair)
     : base(pair, true)
 {
 }
Exemplo n.º 4
0
        public static IntervalComputerForge Make(
            DateTimeMethodEnum method,
            IList<ExprNode> expressions,
            TimeAbacus timeAbacus)
        {
            var parameters = GetParameters(expressions, timeAbacus);

            if (method == DateTimeMethodEnum.BEFORE) {
                if (parameters.Length == 0) {
                    return new IntervalComputerBeforeNoParamForge();
                }

                var pair =
                    IntervalStartEndParameterPairForge.FromParamsWithLongMaxEnd(parameters);
                if (pair.IsConstant) {
                    return new IntervalComputerConstantBefore(pair);
                }

                return new IntervalComputerBeforeWithDeltaExprForge(pair);
            }

            if (method == DateTimeMethodEnum.AFTER) {
                if (parameters.Length == 0) {
                    return new IntervalComputerAfterNoParam();
                }

                var pair =
                    IntervalStartEndParameterPairForge.FromParamsWithLongMaxEnd(parameters);
                if (pair.IsConstant) {
                    return new IntervalComputerConstantAfter(pair);
                }

                return new IntervalComputerAfterWithDeltaExprForge(pair);
            }

            if (method == DateTimeMethodEnum.COINCIDES) {
                if (parameters.Length == 0) {
                    return new IntervalComputerCoincidesNoParam();
                }

                var pair =
                    IntervalStartEndParameterPairForge.FromParamsWithSameEnd(parameters);
                if (pair.IsConstant) {
                    return new IntervalComputerConstantCoincides(pair);
                }

                return new IntervalComputerCoincidesWithDeltaExprForge(pair);
            }

            if (method == DateTimeMethodEnum.DURING || method == DateTimeMethodEnum.INCLUDES) {
                if (parameters.Length == 0) {
                    if (method == DateTimeMethodEnum.DURING) {
                        return new IntervalComputerDuringNoParam();
                    }

                    return new IntervalComputerIncludesNoParam();
                }

                var pair =
                    IntervalStartEndParameterPairForge.FromParamsWithSameEnd(parameters);
                if (parameters.Length == 1) {
                    return new IntervalComputerDuringAndIncludesThresholdForge(
                        method == DateTimeMethodEnum.DURING,
                        pair.Start.Forge);
                }

                if (parameters.Length == 2) {
                    return new IntervalComputerDuringAndIncludesMinMax(
                        method == DateTimeMethodEnum.DURING,
                        pair.Start.Forge,
                        pair.End.Forge);
                }

                return new IntervalComputerDuringMinMaxStartEndForge(
                    method == DateTimeMethodEnum.DURING,
                    GetEvaluators(expressions, timeAbacus));
            }

            if (method == DateTimeMethodEnum.FINISHES) {
                if (parameters.Length == 0) {
                    return new IntervalComputerFinishesNoParam();
                }

                ValidateConstantThreshold("finishes", parameters[0]);
                return new IntervalComputerFinishesThresholdForge(parameters[0].Forge);
            }

            if (method == DateTimeMethodEnum.FINISHEDBY) {
                if (parameters.Length == 0) {
                    return new IntervalComputerFinishedByNoParam();
                }

                ValidateConstantThreshold("finishedby", parameters[0]);
                return new IntervalComputerFinishedByThresholdForge(parameters[0].Forge);
            }

            if (method == DateTimeMethodEnum.MEETS) {
                if (parameters.Length == 0) {
                    return new IntervalComputerMeetsNoParam();
                }

                ValidateConstantThreshold("meets", parameters[0]);
                return new IntervalComputerMeetsThresholdForge(parameters[0].Forge);
            }

            if (method == DateTimeMethodEnum.METBY) {
                if (parameters.Length == 0) {
                    return new IntervalComputerMetByNoParam();
                }

                ValidateConstantThreshold("metBy", parameters[0]);
                return new IntervalComputerMetByThresholdForge(parameters[0].Forge);
            }

            if (method == DateTimeMethodEnum.OVERLAPS || method == DateTimeMethodEnum.OVERLAPPEDBY) {
                if (parameters.Length == 0) {
                    if (method == DateTimeMethodEnum.OVERLAPS) {
                        return new IntervalComputerOverlapsNoParam();
                    }

                    return new IntervalComputerOverlappedByNoParam();
                }

                if (parameters.Length == 1) {
                    return new IntervalComputerOverlapsAndByThreshold(
                        method == DateTimeMethodEnum.OVERLAPS,
                        parameters[0].Forge);
                }

                return new IntervalComputerOverlapsAndByMinMaxForge(
                    method == DateTimeMethodEnum.OVERLAPS,
                    parameters[0].Forge,
                    parameters[1].Forge);
            }

            if (method == DateTimeMethodEnum.STARTS) {
                if (parameters.Length == 0) {
                    return new IntervalComputerStartsNoParam();
                }

                ValidateConstantThreshold("starts", parameters[0]);
                return new IntervalComputerStartsThresholdForge(parameters[0].Forge);
            }

            if (method == DateTimeMethodEnum.STARTEDBY) {
                if (parameters.Length == 0) {
                    return new IntervalComputerStartedByNoParam();
                }

                ValidateConstantThreshold("startedBy", parameters[0]);
                return new IntervalComputerStartedByThresholdForge(parameters[0].Forge);
            }

            throw new ArgumentException("Unknown datetime method '" + method + "'");
        }