private void AssertCompute( long current, TimePeriod timePeriod, string reference, LongAssertion factorAssertion, string expectedTarget) { var referenceDate = DateTimeParser.ParseDefaultEx(reference); // new DateTimeEx(DateTimeParser.ParseDefault(reference), TimeZoneInfo.Local); var result = CalendarOpPlusFastAddHelper.ComputeNextDue(current, timePeriod, referenceDate); Assert.AreEqual( DateTimeParser.ParseDefault(expectedTarget), result.Scheduled, string.Format("\nExpected {0}\n" + "Received {1}\n", expectedTarget, DateTimeHelper.Print(result.Scheduled))); factorAssertion.AssertLong(result.Factor); }
private long ComputeNextSetLastScheduled(long currentTime) { // handle already-stopped if (_cachedCountRepeated == long.MaxValue) { return(-1); } // handle date-only-form: "<date>" if (_spec.OptionalRepeatCount == null && _spec.OptionalDate != null && _spec.OptionalTimePeriod == null) { _cachedCountRepeated = long.MaxValue; var anchorTimeInMillis = _anchorTime.TimeInMillis; if (anchorTimeInMillis > currentTime) { return(anchorTimeInMillis - currentTime); } return(-1); } // handle period-only-form: "P<period>" // handle partial-form-2: "<date>/<period>" (non-recurring) if (_spec.OptionalRepeatCount == null && _spec.OptionalTimePeriod != null) { _cachedCountRepeated = long.MaxValue; _cachedLastScheduled = new DateTimeEx(_anchorTime); CalendarOpPlusMinus.Action(_cachedLastScheduled, 1, _spec.OptionalTimePeriod); var cachedLastTimeInMillis = _cachedLastScheduled.TimeInMillis; if (cachedLastTimeInMillis > currentTime) { return(cachedLastTimeInMillis - currentTime); } return(-1); } // handle partial-form-1: "R<?>/<period>" // handle full form if (_cachedLastScheduled == null) { _cachedLastScheduled = new DateTimeEx(_anchorTime); if (_spec.OptionalDate != null) { _cachedCountRepeated = 1; } } if (_spec.OptionalRepeatCount == -1) { var nextDueInner = CalendarOpPlusFastAddHelper.ComputeNextDue(currentTime, _spec.OptionalTimePeriod, _cachedLastScheduled); _cachedLastScheduled.Set(nextDueInner.Scheduled); return(_cachedLastScheduled.TimeInMillis - currentTime); } var nextDue = CalendarOpPlusFastAddHelper.ComputeNextDue(currentTime, _spec.OptionalTimePeriod, _cachedLastScheduled); _cachedCountRepeated += nextDue.Factor; if (_cachedCountRepeated <= _spec.OptionalRepeatCount) { _cachedLastScheduled.Set(nextDue.Scheduled); var cachedLastTimeInMillis = _cachedLastScheduled.TimeInMillis; if (cachedLastTimeInMillis > currentTime) { return(cachedLastTimeInMillis - currentTime); } } _cachedCountRepeated = long.MaxValue; return(-1); }
private long ComputeNextSetLastScheduled( long currentTime, TimeAbacus timeAbacus) { // handle already-stopped if (cachedCountRepeated == long.MaxValue) { return -1; } // handle date-only-form: "<date>" if (spec.OptionalRepeatCount == null && spec.OptionalDate != null && spec.OptionalTimePeriod == null) { cachedCountRepeated = long.MaxValue; var computed = timeAbacus.DateTimeGet(anchorTime, anchorRemainder); if (computed > currentTime) { return computed - currentTime; } return -1; } // handle period-only-form: "P<period>" // handle partial-form-2: "<date>/<period>" (non-recurring) if (spec.OptionalRepeatCount == null && spec.OptionalTimePeriod != null) { cachedCountRepeated = long.MaxValue; cachedLastScheduled = anchorTime.Clone(); CalendarPlusMinusForgeOp.ActionCalendarPlusMinusTimePeriod( cachedLastScheduled, 1, spec.OptionalTimePeriod); var computed = timeAbacus.DateTimeGet(cachedLastScheduled, anchorRemainder); if (computed > currentTime) { return computed - currentTime; } return -1; } // handle partial-form-1: "R<?>/<period>" // handle full form if (cachedLastScheduled == null) { cachedLastScheduled = anchorTime.Clone(); if (spec.OptionalDate != null) { cachedCountRepeated = 1; } } var nextDue = CalendarOpPlusFastAddHelper.ComputeNextDue( currentTime, spec.OptionalTimePeriod, cachedLastScheduled, timeAbacus, anchorRemainder); if (spec.OptionalRepeatCount == -1) { cachedLastScheduled = nextDue.Scheduled; var computed = timeAbacus.DateTimeGet(cachedLastScheduled, anchorRemainder); return computed - currentTime; } cachedCountRepeated += nextDue.Factor; if (cachedCountRepeated <= spec.OptionalRepeatCount) { cachedLastScheduled = nextDue.Scheduled; var computed = timeAbacus.DateTimeGet(cachedLastScheduled, anchorRemainder); if (computed > currentTime) { return computed - currentTime; } } cachedCountRepeated = long.MaxValue; return -1; }
private long ComputeNextSetLastScheduled(long currentTime, TimeAbacus timeAbacus) { // handle already-stopped if (_cachedCountRepeated == Int64.MaxValue) { return(-1); } // handle date-only-form: "<date>" if (_spec.OptionalRepeatCount == null && _spec.OptionalDate != null && _spec.OptionalTimePeriod == null) { _cachedCountRepeated = Int64.MaxValue; var computed = timeAbacus.CalendarGet(_anchorTime, _anchorRemainder); if (computed > currentTime) { return(computed - currentTime); } return(-1); } // handle period-only-form: "P<period>" // handle partial-form-2: "<date>/<period>" (non-recurring) if (_spec.OptionalRepeatCount == null && _spec.OptionalTimePeriod != null) { _cachedCountRepeated = Int64.MaxValue; _cachedLastScheduled = _anchorTime.Clone(); CalendarOpPlusMinus.Action(_cachedLastScheduled, 1, _spec.OptionalTimePeriod); var computed = timeAbacus.CalendarGet(_cachedLastScheduled, _anchorRemainder); if (computed > currentTime) { return(computed - currentTime); } return(-1); } // handle partial-form-1: "R<?>/<period>" // handle full form if (_cachedLastScheduled == null) { _cachedLastScheduled = _anchorTime.Clone(); if (_spec.OptionalDate != null) { _cachedCountRepeated = 1; } } var nextDue = CalendarOpPlusFastAddHelper.ComputeNextDue( currentTime, _spec.OptionalTimePeriod, _cachedLastScheduled, timeAbacus, _anchorRemainder); if (_spec.OptionalRepeatCount == -1) { _cachedLastScheduled = nextDue.Scheduled; var computed = timeAbacus.CalendarGet(_cachedLastScheduled, _anchorRemainder); return(computed - currentTime); } _cachedCountRepeated += nextDue.Factor; if (_cachedCountRepeated <= _spec.OptionalRepeatCount) { _cachedLastScheduled = nextDue.Scheduled; var computed = timeAbacus.CalendarGet(_cachedLastScheduled, _anchorRemainder); if (computed > currentTime) { return(computed - currentTime); } } _cachedCountRepeated = Int64.MaxValue; return(-1); }