コード例 #1
0
        public override object Evaluate(object target, EvaluateParams evaluateParams)
        {
            var dtx            = DateTimeEx.GetInstance(_timeZone);
            var startRemainder = _timeAbacus.CalendarSet((long)target, dtx);

            EvaluateDtxOps(CalendarOps, dtx, evaluateParams);
            var time = _timeAbacus.CalendarGet(dtx, startRemainder);

            return(IntervalOp.Evaluate(time, time, evaluateParams));
        }
コード例 #2
0
ファイル: ReformatOpGetField.cs プロジェクト: valmac/nesper
        public Object Evaluate(long ts, EventBean[] eventsPerStream, bool newData, ExprEvaluatorContext exprEvaluatorContext)
        {
            DateTimeEx cal = DateTimeEx.GetInstance(_timeZone);

            _timeAbacus.CalendarSet(ts, cal);
            return(Action(cal));
        }
コード例 #3
0
        public override object Evaluate(object target, EvaluateParams evaluateParams)
        {
            var dtx = DateTimeEx.GetInstance(_timeZone);

            _timeAbacus.CalendarSet((long)target, dtx);
            DTLocalEvaluatorBase.EvaluateDtxOps(CalendarOps, dtx, evaluateParams);
            return(ReformatOp.Evaluate(dtx, evaluateParams.EventsPerStream, evaluateParams.IsNewData, evaluateParams.ExprEvaluatorContext));
        }
コード例 #4
0
        public object Evaluate(object target, EvaluateParams evaluateParams)
        {
            var longValue = (long)target;
            var dtx       = DateTimeEx.GetInstance(_timeZone);
            var remainder = _timeAbacus.CalendarSet(longValue, dtx);

            DTLocalEvaluatorBase.EvaluateDtxOps(CalendarOps, dtx, evaluateParams);

            return(_timeAbacus.CalendarGet(dtx, remainder));
        }
コード例 #5
0
        public Object Evaluate(
            long ts,
            EventBean[] eventsPerStream,
            bool newData,
            ExprEvaluatorContext exprEvaluatorContext)
        {
            DateTimeEx dtx = DateTimeEx.GetInstance(_timeZone);

            _timeAbacus.CalendarSet(ts, dtx);
            return(_dtxEval.Invoke(dtx));
        }
コード例 #6
0
        private long AddSubtract(long fromTime, int factor)
        {
            long remainder = _timeAbacus.CalendarSet(fromTime, _dateTime);

            for (int i = 0; i < _adders.Length; i++)
            {
                _adders[i].Add(_dateTime, factor * _added[i]);
            }
            long result = _timeAbacus.CalendarGet(_dateTime, remainder);

            if (_indexMicroseconds != -1)
            {
                result += factor * _added[_indexMicroseconds];
            }
            return(result);
        }
コード例 #7
0
            public TimerScheduleSpec Compute(
                MatchedEventConvertor convertor,
                MatchedEventMap beginState,
                ExprEvaluatorContext exprEvaluatorContext,
                TimeZoneInfo timeZone,
                TimeAbacus timeAbacus)
            {
                DateTimeEx optionalDate = null;
                long? optionalRemainder = null;
                if (_dateNode != null)
                {
                    Object param = PatternExpressionUtil.Evaluate(
                        NAME_OBSERVER, beginState, _dateNode, convertor, exprEvaluatorContext);
                    if (param is string)
                    {
                        optionalDate = TimerScheduleISO8601Parser.ParseDate((string) param);
                    }
                    else if (param.IsLong() || param.IsInt())
                    {
                        long msec = param.AsLong();
                        optionalDate = DateTimeEx.GetInstance(timeZone);
                        timeAbacus.CalendarSet(msec, optionalDate);
                        //optionalDate = new DateTimeEx(msec.AsDateTimeOffset(timeZone), timeZone);
                        optionalRemainder = timeAbacus.CalendarSet(msec, optionalDate);
                    }
                    else if (param is DateTimeOffset || param is DateTime)
                    {
                        optionalDate = new DateTimeEx(param.AsDateTimeOffset(timeZone), timeZone);
                    }
                    else if (param is DateTimeEx)
                    {
                        optionalDate = (DateTimeEx) param;
                    }
                    else if (param == null)
                    {
                        throw new EPException(
                            "Null date-time value returned from " +
                            ExprNodeUtility.ToExpressionStringMinPrecedenceSafe(_dateNode));
                    }
                    else
                    {
                        throw new EPException("Unrecognized date-time value " + param.GetType());
                    }
                }

                TimePeriod optionalTimePeriod = null;
                if (_periodNode != null)
                {
                    object param = PatternExpressionUtil.EvaluateTimePeriod(
                        NAME_OBSERVER, beginState, _periodNode, convertor, exprEvaluatorContext);
                    optionalTimePeriod = (TimePeriod) param;
                }

                long? optionalRepeatCount = null;
                if (_repetitionsNode != null)
                {
                    object param = PatternExpressionUtil.Evaluate(
                        NAME_OBSERVER, beginState, _repetitionsNode, convertor, exprEvaluatorContext);
                    if (param != null)
                    {
                        optionalRepeatCount = param.AsLong();
                    }
                }

                if (optionalDate == null && optionalTimePeriod == null)
                {
                    throw new EPException("Required date or time period are both null for " + NAME_OBSERVER);
                }

                return new TimerScheduleSpec(optionalDate, optionalRemainder, optionalRepeatCount, optionalTimePeriod);
            }
コード例 #8
0
        private static long Compute(
            ScheduleSpec spec,
            long afterTimeInMillis,
            TimeZoneInfo timeZone,
            TimeAbacus timeAbacus)
        {
            long remainderMicros = -1;

            while (true)
            {
                DateTimeEx after;

                if (spec.OptionalTimeZone != null)
                {
                    try
                    {
                        timeZone = TimeZoneHelper.GetTimeZoneInfo(spec.OptionalTimeZone);
                        after    = DateTimeEx.GetInstance(timeZone);
                    }
                    catch (TimeZoneNotFoundException)
                    {
                        // this behavior ensures we are consistent with Java, but IMO, it's bad behavior...
                        // basically, if the timezone is not found, we default to UTC.
                        timeZone = TimeZoneInfo.Utc;
                        after    = DateTimeEx.GetInstance(timeZone);
                    }
                }
                else
                {
                    after = DateTimeEx.GetInstance(timeZone);
                }

                var remainder = timeAbacus.CalendarSet(afterTimeInMillis, after);
                if (remainderMicros == -1)
                {
                    remainderMicros = remainder;
                }

                var result = new ScheduleCalendar {
                    Milliseconds = after.Millisecond
                };

                ICollection <int> minutesSet = spec.UnitValues.Get(ScheduleUnit.MINUTES);
                ICollection <int> hoursSet   = spec.UnitValues.Get(ScheduleUnit.HOURS);
                ICollection <int> monthsSet  = spec.UnitValues.Get(ScheduleUnit.MONTHS);
                ICollection <int> secondsSet = null;

                bool isSecondsSpecified = false;

                if (spec.UnitValues.ContainsKey(ScheduleUnit.SECONDS))
                {
                    isSecondsSpecified = true;
                    secondsSet         = spec.UnitValues.Get(ScheduleUnit.SECONDS);
                }

                if (isSecondsSpecified)
                {
                    result.Second = NextValue(secondsSet, after.Second);
                    if (result.Second == -1)
                    {
                        result.Second = NextValue(secondsSet, 0);
                        after.AddMinutes(1);
                    }
                }

                result.Minute = NextValue(minutesSet, after.Minute);
                if (result.Minute != after.Minute)
                {
                    result.Second = NextValue(secondsSet, 0);
                }
                if (result.Minute == -1)
                {
                    result.Minute = NextValue(minutesSet, 0);
                    after.AddHours(1);
                }

                result.Hour = NextValue(hoursSet, after.Hour);
                if (result.Hour != after.Hour)
                {
                    result.Second = NextValue(secondsSet, 0);
                    result.Minute = NextValue(minutesSet, 0);
                }
                if (result.Hour == -1)
                {
                    result.Hour = NextValue(hoursSet, 0);
                    after.AddDays(1, DateTimeMathStyle.Java);
                }

                // This call may change second, minute and/or hour parameters
                // They may be reset to minimum values if the day rolled
                result.DayOfMonth = DetermineDayOfMonth(spec, after, result);

                bool dayMatchRealDate = false;
                while (!dayMatchRealDate)
                {
                    if (CheckDayValidInMonth(timeZone, result.DayOfMonth, after.Month, after.Year))
                    {
                        dayMatchRealDate = true;
                    }
                    else
                    {
                        after.AddMonths(1, DateTimeMathStyle.Java);
                    }
                }

                int currentMonth = after.Month;
                result.Month = NextValue(monthsSet, currentMonth);
                if (result.Month != currentMonth)
                {
                    result.Second     = NextValue(secondsSet, 0);
                    result.Minute     = NextValue(minutesSet, 0);
                    result.Hour       = NextValue(hoursSet, 0);
                    result.DayOfMonth = DetermineDayOfMonth(spec, after, result);
                }
                if (result.Month == -1)
                {
                    result.Month = NextValue(monthsSet, 0);
                    after.AddYears(1);
                }

                // Perform a last valid date check, if failing, try to compute a new date based on this altered after date
                int year = after.Year;
                if (!CheckDayValidInMonth(timeZone, result.DayOfMonth, result.Month, year))
                {
                    afterTimeInMillis = timeAbacus.CalendarGet(after, remainder);
                    continue;
                }

                return(GetTime(result, after.Year, spec.OptionalTimeZone, timeZone, timeAbacus, remainder));
            }
        }