public static bool TrySync([NotNull] IClock clock, Func <TimeUnit, long> remoteTimeSupplier, TimeSpan syncWithin, int maxRetryCount, out SyncedClock synced) { for (var i = maxRetryCount - 1; i >= 0; i--) { var startTicks = clock.GetTicks(); var remoteTime = remoteTimeSupplier(clock.Unit); var endTicks = clock.GetTicks(); var elapsedTicks = endTicks - startTicks; if (elapsedTicks / 2 < syncWithin.Ticks) { synced = new SyncedClock(clock, TimeUnit.Tick.ConvertTo(startTicks, clock.Unit), remoteTime, 1); return(true); } } synced = null; return(false); }
public static uint GetMinutes(this IClock clock) { return((uint)(clock.GetTicks() / clock.TicksPerSecond / 60)); }