Example #1
0
        private static long GetTimeToNextStepInTicks(UnixTime unixTime, StepDurationInfo currentStepInfo)
        {
            var timeFromTransition          = unixTime.MillisecondsLong - currentStepInfo.TransitionTimestampMilliseconds;
            var timeAlreadyPassedToNextStep = timeFromTransition % currentStepInfo.StepDurationMilliseconds;

            return((currentStepInfo.StepDurationMilliseconds - timeAlreadyPassedToNextStep) * TimeSpan.TicksPerMillisecond);
        }
Example #2
0
        private IList <StepDurationInfo> CreateStepDurations(IDictionary <long, long> stepDurations)
        {
            StepDurationInfo[]        result    = new StepDurationInfo[stepDurations.Count];
            KeyValuePair <long, long> firstStep = stepDurations.First();
            int index        = 0;
            var previousStep = result[index++] = new StepDurationInfo(0, firstStep.Key, firstStep.Value);

            foreach (var currentStep in stepDurations.Skip(1))
            {
                var previousStepLength         = currentStep.Key - previousStep.TransitionTimestamp;
                var previousStepCount          = previousStepLength / previousStep.StepDuration + (previousStepLength % previousStep.StepDuration > 0 ? 1 : 0);
                var currentTransitionStep      = previousStep.TransitionStep + previousStepCount;
                var currentTransitionTimestamp = previousStep.TransitionTimestamp + previousStepCount * previousStep.StepDuration;
                previousStep = result[index++] = new StepDurationInfo(currentTransitionStep, currentTransitionTimestamp, currentStep.Value);
            }
            return(result);
        }