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

        return(localTime);
    }
Ejemplo n.º 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);
    }
Ejemplo n.º 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;
    }
Ejemplo n.º 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);
    }
Ejemplo n.º 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);
    }
Ejemplo n.º 6
0
 public static DateTime GetUniversalTimeFromCurrentEnvironmentTickCount(this ClockAggregateRoot clock) =>
 clock.GetUniversalTimeFromEnvironmentTickCount(Environment.TickCount);