Skip to content

Commit

Permalink
switch DateTime.Now usages to DateTime.UtcNow
Browse files Browse the repository at this point in the history
  • Loading branch information
Aytackydln committed Jan 30, 2024
1 parent 2b9c41a commit 5c91fe5
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 33 deletions.
6 changes: 3 additions & 3 deletions Project-Aurora/Project-Aurora/ConfigUI.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ partial class ConfigUI : INotifyPropertyChanged

private readonly AuroraControlInterface _controlInterface;

private DateTime _lastActivated = DateTime.Now;
private DateTime _lastActivated = DateTime.UtcNow;
private readonly TimeSpan _renderTimeout = TimeSpan.FromMinutes(5);
private readonly EffectColor _desktopColorScheme = new(0, 0, 0, 0);

Expand Down Expand Up @@ -146,7 +146,7 @@ public ConfigUI(Task<ChromaReader?> rzSdkManager, Task<PluginManager> pluginMana

private void KeyboardTimerCallback()
{
if (DateTime.Now - _lastActivated > _renderTimeout)
if (DateTime.UtcNow - _lastActivated > _renderTimeout)
{
return;
}
Expand Down Expand Up @@ -339,7 +339,7 @@ private async Task MinimizeApp()

private void Window_Activated(object? sender, EventArgs e)
{
_lastActivated = DateTime.Now;
_lastActivated = DateTime.UtcNow;
}

private readonly Image _profileAdd = new()
Expand Down
2 changes: 1 addition & 1 deletion Project-Aurora/Project-Aurora/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static void Initialize()
#if DEBUG
isDebug = true;
#endif
var logFile = $"{DateTime.Now:yyyy-MM-dd HH.mm.ss}.log";
var logFile = $"{DateTime.UtcNow:yyyy-MM-dd HH.mm.ss}.log";
var logPath = Path.Combine(AppDataDirectory, "Logs", logFile);
logger = new LoggerConfiguration()
.Enrich.FromLogContext()
Expand Down
14 changes: 7 additions & 7 deletions Project-Aurora/Project-Aurora/Modules/Razer/RzHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private set
}

private static DateTime _lastFetch = DateTime.UnixEpoch;
private static DateTime _lastUpdate = DateTime.Now;
private static DateTime _lastUpdate = DateTime.UtcNow;
private static string? _currentAppExecutable = string.Empty;

/// <summary>
Expand Down Expand Up @@ -87,7 +87,7 @@ public static bool IsStale()
{
return true;
}
_lastFetch = DateTime.Now;
_lastFetch = DateTime.UtcNow;
return false;
}

Expand All @@ -106,35 +106,35 @@ public static void Initialize()
{
KeyboardColors.Provider = keyboard;
KeyboardColors.IsDirty = true;
_lastUpdate = DateTime.Now;
_lastUpdate = DateTime.UtcNow;
};

sdkManager.MouseUpdated += (object? _, in ChromaMouse mouse) =>
{
MouseColors.Provider = mouse;
MouseColors.IsDirty = true;
_lastUpdate = DateTime.Now;
_lastUpdate = DateTime.UtcNow;
};

sdkManager.MousepadUpdated += (object? _, in ChromaMousepad mousepad) =>
{
MousepadColors.Provider = mousepad;
MousepadColors.IsDirty = true;
_lastUpdate = DateTime.Now;
_lastUpdate = DateTime.UtcNow;
};

sdkManager.HeadsetUpdated += (object? _, in ChromaHeadset headset) =>
{
HeadsetColors.Provider = headset;
HeadsetColors.IsDirty = true;
_lastUpdate = DateTime.Now;
_lastUpdate = DateTime.UtcNow;
};

sdkManager.ChromaLinkUpdated += (object? _, in ChromaLink link) =>
{
ChromaLinkColors.Provider = link;
ChromaLinkColors.IsDirty = true;
_lastUpdate = DateTime.Now;
_lastUpdate = DateTime.UtcNow;
};

sdkManager.AppDataUpdated += (object? _, in ChromaAppData appData) =>
Expand Down
4 changes: 2 additions & 2 deletions Project-Aurora/Project-Aurora/Nodes/CelestialData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public double SolarNoonPercentage
{
if (_invalidated)
{
Coordinate = new Coordinate(Global.Configuration.Lat, Global.Configuration.Lon, DateTime.Now, El);
Coordinate = new Coordinate(Global.Configuration.Lat, Global.Configuration.Lon, DateTime.UtcNow, El);
_invalidated = false;
}

var dateTime = DateTime.Now;
var dateTime = DateTime.UtcNow;

if (dateTime.Hour != _currentHour)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private void Window_Loaded(object? sender, RoutedEventArgs e) {
// Start a timer to update the time displays for the request
_timeDisplayTimer = new Timer(_ => Dispatcher.BeginInvoke(() => {
if (_lastRequestTime.HasValue)
CurRequestTime.Text = _lastRequestTime + " (" + (DateTime.Now - _lastRequestTime).Value.TotalSeconds.ToString("0.00") + "s ago)";
CurRequestTime.Text = _lastRequestTime + " (" + (DateTime.UtcNow - _lastRequestTime).Value.TotalSeconds.ToString("0.00") + "s ago)";
}, DispatcherPriority.DataBind), null, 0, 50);
}

Expand All @@ -91,7 +91,7 @@ private void Net_listener_NewGameState(object? sender, IGameState gamestate)
// Without this, an exception is thrown trying to update the text box.
Dispatcher.BeginInvoke(() => SetJsonText(gamestate.Json), DispatcherPriority.DataBind);
// Also record the time this request came in
_lastRequestTime = DateTime.Now;
_lastRequestTime = DateTime.UtcNow;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public class AmbilightLayerHandler : LayerHandler<AmbilightLayerHandlerPropertie
private bool _brushChanged = true;

private readonly Stopwatch _captureStopwatch = new();
private DateTime _lastProcessDetectTry = DateTime.Now;
private DateTime _lastProcessDetectTry = DateTime.UtcNow;

public IEnumerable<string> Displays => _screenCapture?.GetDisplays() ?? ImmutableList<string>.Empty;

Expand Down Expand Up @@ -299,10 +299,10 @@ public override EffectLayer Render(IGameState gamestate)
//for a frame when the user alt-tabs with the foregroundapp option selected
if (TryGetCropRegion(out var newCropRegion))
_cropRegion = newCropRegion;
else if (DateTime.Now - _lastProcessDetectTry > TimeSpan.FromSeconds(2))
else if (DateTime.UtcNow - _lastProcessDetectTry > TimeSpan.FromSeconds(2))
{
UpdateSpecificProcessHandle(Properties.SpecificProcess);
_lastProcessDetectTry = DateTime.Now;
_lastProcessDetectTry = DateTime.UtcNow;
}
//and because of that, this should never happen
if (_cropRegion.IsEmpty)
Expand Down
14 changes: 3 additions & 11 deletions Project-Aurora/Project-Aurora/Settings/Layers/TimerLayerHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private void SetTimer(double t) {

public void Reset(double t) {
SetTimer(t);
startAt = DateTime.Now;
startAt = DateTime.UtcNow;
max = t;
}

Expand All @@ -185,18 +185,10 @@ public void Extend(double t) {
}

/// <summary>Gets how many milliseconds has elapsed since starting timer.</summary>
public int Current {
get {
return (int)(DateTime.Now - startAt).TotalMilliseconds;
}
}
public int Current => (int)(DateTime.UtcNow - startAt).TotalMilliseconds;

/// <summary>Gets how far through the timer is as a value between 0 and 1 (for use with the fade animation mode).</summary>
public double InterpolationValue {
get {
return Current / max;
}
}
public double InterpolationValue => Current / max;

public void Disponse() {
timer.Dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ protected override T Execute(IGameState gameState) {
var val = Source.Evaluate(gameState);
if (!EqualityComparer<T>.Default.Equals(val, lastValue)) {
// If different, record the time it changed and (add the delay so that we don't have to keep adding when checking later)
history.Enqueue((DateTime.Now.AddSeconds(Delay), val));
history.Enqueue((DateTime.UtcNow.AddSeconds(Delay), val));
lastValue = val;
}

// Next, check if the time next item in the queue changed has passed, update the current value
// Note that we don't need to check other items since they are kept in order by the queue
if (history.Count > 0 && history.Peek().changeTime < DateTime.Now)
if (history.Count > 0 && history.Peek().changeTime < DateTime.UtcNow)
currentValue = history.Dequeue().value;

return currentValue;
Expand Down
4 changes: 2 additions & 2 deletions Project-Aurora/Project-Aurora/Utils/Time.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ namespace Aurora.Utils;
/// </summary>
public static class Time
{
private static readonly DateTime Epoch = new(1970, 1, 1);
private static readonly DateTime Epoch = DateTime.UnixEpoch;

/// <summary>
/// Gets the milliseconds since the epoch
/// </summary>
/// <returns>The time, in milliseconds, since the epoch</returns>
public static long GetMillisecondsSinceEpoch()
{
var span = DateTime.Now - Epoch;
var span = DateTime.UtcNow - Epoch;
return (long)span.TotalMilliseconds;
}

Expand Down

0 comments on commit 5c91fe5

Please sign in to comment.