Exemple #1
0
        public static DateTime GetLocalTimeFromCurrentEnvironmentTickCount(this ClockAggregateRoot clock)
        {
            var universalTime = clock.GetUniversalTimeFromCurrentEnvironmentTickCount();
            var localTime     = universalTime.ToLocalTime();

            return(localTime);
        }
Exemple #2
0
        private static DateTime GetUniversalTimeFromEnvironmentTickCount(this ClockAggregateRoot clock, int environmentTickCount)
        {
            Assert.IsNotNull(clock);
            var clockState    = clock.GetAggregateState();
            var milliseconds  = environmentTickCount - clockState.EnvironmentTickCount;
            var universalTime = clockState.UniversalTime.AddMilliseconds(milliseconds);

            return(universalTime);
        }
Exemple #3
0
        public static void Get(this ClockAggregateRoot clock, out long stopwatchTimestamp, out int environmentTickCount, out DateTime universalTime,
                               out DateTime localTime)
        {
            var clockState = clock.GetAggregateState();

            stopwatchTimestamp   = clockState.StopwatchTimestamp;
            environmentTickCount = clockState.EnvironmentTickCount;
            universalTime        = clockState.UniversalTime;
            localTime            = clockState.LocalTime;
        }
Exemple #4
0
        public static DateTime GetUniversalTimeFromStopwatchTimestamp(this ClockAggregateRoot clock, long stopwatchTimestamp)
        {
            Assert.IsNotNull(clock);
            var clockState          = clock.GetAggregateState();
            var stopwatchTicks      = stopwatchTimestamp - clockState.StopwatchTimestamp;
            var timeSpanTicksDouble = stopwatchTicks * StopwatchConstants.TimeSpanTicksPerStopwatchTick;
            var timeSpanTicks       = (long)Math.Round(timeSpanTicksDouble);
            var universalTime       = clockState.UniversalTime.AddTicks(timeSpanTicks);

            return(universalTime);
        }
Exemple #5
0
        public static void GetFromStopwatchTimestamp(this ClockAggregateRoot clock, long stopwatchTimestamp, out int environmentTickCount,
                                                     out DateTime universalTime)
        {
            Assert.IsNotNull(clock);
            var clockState     = clock.GetAggregateState();
            var stopwatchTicks = stopwatchTimestamp - clockState.StopwatchTimestamp;

            var environmentTicksDouble = stopwatchTicks * StopwatchConstants.MillisecondsPerTick;
            var environmentTicks       = (int)Math.Round(environmentTicksDouble);

            environmentTickCount = clockState.EnvironmentTickCount + environmentTicks;

            var timeSpanTicksDouble = stopwatchTicks * StopwatchConstants.TimeSpanTicksPerStopwatchTick;
            var timeSpanTicks       = (long)Math.Round(timeSpanTicksDouble);

            universalTime = clockState.UniversalTime.AddTicks(timeSpanTicks);
        }
Exemple #6
0
 public static DateTime GetUniversalTimeFromCurrentEnvironmentTickCount(this ClockAggregateRoot clock) =>
 clock.GetUniversalTimeFromEnvironmentTickCount(Environment.TickCount);