Ejemplo n.º 1
0
 public CodegenExpression CodegenDateTime(
     CodegenExpression dateTime,
     CodegenMethodScope codegenMethodScope,
     ExprForgeCodegenSymbol exprSymbol,
     CodegenClassScope codegenClassScope)
 {
     return CalendarPlusMinusForgeOp.CodegenDateTime(
         this,
         dateTime,
         codegenMethodScope,
         exprSymbol,
         codegenClassScope);
 }
Ejemplo n.º 2
0
        public static CalendarOpPlusFastAddResult ComputeNextDue(
            long currentTime,
            TimePeriod timePeriod,
            DateTimeEx reference,
            TimeAbacus timeAbacus,
            long remainder)
        {
            if (timeAbacus.DateTimeGet(reference, remainder) > currentTime) {
                return new CalendarOpPlusFastAddResult(0, reference);
            }

            // add one time period
            DateTimeEx work = reference.Clone();
            if (DEBUG && Log.IsDebugEnabled) {
                Log.Debug("Work date is " + work);
            }

            CalendarPlusMinusForgeOp.ActionSafeOverflow(work, 1, timePeriod);
            long inMillis = timeAbacus.DateTimeGet(work, remainder);
            if (inMillis > currentTime) {
                return new CalendarOpPlusFastAddResult(1, work);
            }

            if (DEBUG && Log.IsDebugEnabled) {
                Log.Debug("Work date is {0}", work);
            }

            long factor = 1;

            // determine multiplier
            long refTime = timeAbacus.DateTimeGet(reference, remainder);
            long deltaCurrentToStart = currentTime - refTime;
            long deltaAddedOne = timeAbacus.DateTimeGet(work, remainder) - refTime;
            double multiplierDbl = (deltaCurrentToStart / deltaAddedOne) - 1;
            var multiplierRoundedLong = (long) multiplierDbl;

            // handle integer max
            while (multiplierRoundedLong > Int32.MaxValue) {
                CalendarPlusMinusForgeOp.ActionSafeOverflow(work, Int32.MaxValue, timePeriod);
                factor += Int32.MaxValue;
                multiplierRoundedLong -= Int32.MaxValue;
                if (DEBUG && Log.IsDebugEnabled) {
                    Log.Debug("Work date is {0} factor {1}", work, factor);
                }
            }

            // add
            var multiplierRoundedInt = (int) multiplierRoundedLong;
            CalendarPlusMinusForgeOp.ActionSafeOverflow(work, multiplierRoundedInt, timePeriod);
            factor += multiplierRoundedInt;

            // if below, add more
            if (timeAbacus.DateTimeGet(work, remainder) <= currentTime) {
                while (timeAbacus.DateTimeGet(work, remainder) <= currentTime) {
                    CalendarPlusMinusForgeOp.ActionSafeOverflow(work, 1, timePeriod);
                    factor += 1;
                    if (DEBUG && Log.IsDebugEnabled) {
                        Log.Debug("Work date is {0} factor {1}", work, factor);
                    }
                }

                return new CalendarOpPlusFastAddResult(factor, work);
            }

            // we are over
            while (timeAbacus.DateTimeGet(work, remainder) > currentTime) {
                CalendarPlusMinusForgeOp.ActionSafeOverflow(work, -1, timePeriod);
                factor -= 1;
                if (DEBUG && Log.IsDebugEnabled) {
                    Log.Debug("Work date is {0} factor {1}", work, factor);
                }
            }

            CalendarPlusMinusForgeOp.ActionSafeOverflow(work, 1, timePeriod);
            if (DEBUG && Log.IsDebugEnabled) {
                Log.Debug("Work date is {0} factor {1}", work, factor);
            }

            return new CalendarOpPlusFastAddResult(factor + 1, work);
        }