Exemplo n.º 1
0
        /// <summary>
        /// Calculate the next fire.
        /// </summary>
        /// <returns>DateTimeOffset if next fire exists, otherwise false.</returns>
        public DateTimeOffset?NextFire()
        {
            if (_fireSpan == TimeSpan.MinValue)
            {
                var fire = _evaluator.NextFire();

                if (!fire.HasValue)
                {
                    return(null);
                }

                _fireSpan = _timeZone.GetUtcOffset(fire.Value);

                var offset = _timeZone.GetUtcOffset(new DateTimeOffset(fire.Value.DateTime, _fireSpan));
                if (_fireSpan != offset)
                {
                    _fireSpan = offset;
                    return(new DateTimeOffset(fire.Value.DateTime, offset));
                }

                return(new DateTimeOffset(fire.Value.DateTime, _fireSpan));
            }
            var result = _evaluator.NextFire();

            if (!result.HasValue)
            {
                return(null);
            }

            var dt      = result.Value;
            var newDate = new DateTimeOffset(dt.DateTime, _fireSpan);

            return(newDate);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Evaluate next occurence.
        /// </summary>
        /// <returns>Value if next occurence founded, otherwise null.</returns>
        public DateTimeOffset?NextFire()
        {
            var generatedTime = _evaluator.NextFire();

            if (generatedTime.HasValue)
            {
                return(TimeZoneInfo.ConvertTime(generatedTime.Value, _destinationZoneInfo));
            }
            return(null);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Calculate the next fire.
        /// </summary>
        /// <returns>DateTimeOffset if next fire exists, otherwise false.</returns>
        public DateTimeOffset?NextFire()
        {
            var calcFire = _evaluator.NextFire();

            if (!calcFire.HasValue)
            {
                return(null);
            }

            if (!_timeZone.SupportsDaylightSavingTime)
            {
                return(calcFire);
            }

            var value = calcFire.Value;

            if (_lastlyEvaluated == DateTimeOffset.MinValue)
            {
                _lastlyEvaluated = value;
            }

            var newOffset = _timeZone.GetUtcOffset(calcFire.Value);

            if (newOffset == _lastlyEvaluated.Offset)
            {
                _lastlyEvaluated = new DateTimeOffset(value.DateTime.Add(_lastDiff), newOffset);
                return(_lastlyEvaluated);
            }

            if (_timeZone.IsAmbiguousTime(calcFire.Value) || _timeZone.IsInvalidTime(calcFire.Value.DateTime))
            {
                var diff    = newOffset - _lastlyEvaluated.Offset;
                var newDate = new DateTimeOffset(value.DateTime.Add(diff), _lastlyEvaluated.Offset + diff);
                _lastDiff        = diff;
                _lastlyEvaluated = newDate;
                return(newDate);
            }

            _lastlyEvaluated = new DateTimeOffset(value.DateTime, newOffset);
            return(_lastlyEvaluated);
        }
Exemplo n.º 4
0
 public DateTimeOffset?NextFire() => _evaluator.NextFire();