From 8631316201b8812c156766eb44a1eca801d533fe Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Wed, 13 Jul 2016 09:19:34 +1000 Subject: [PATCH] Use DateTime.UtcNow in more places and fix TimeUtils.Shorten for negative timespans. --- GUI/Program.cs | 4 ++-- Player/Player.Fields.cs | 2 +- Player/Player.Handlers.cs | 4 ++-- util/TimeUtils.cs | 5 ++++- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/GUI/Program.cs b/GUI/Program.cs index 950bbf722..f212e5bf8 100644 --- a/GUI/Program.cs +++ b/GUI/Program.cs @@ -52,7 +52,7 @@ namespace MCGalaxy.Gui { static bool useConsole, useHighQualityGui; [STAThread] public static void Main(string[] args) { - DateTime startTime = DateTime.Now; + DateTime startTime = DateTime.UtcNow; Process[] duplicates = Process.GetProcessesByName("MCGalaxy"); if (duplicates.Length != 1) { Process proc = Process.GetCurrentProcess(); @@ -94,7 +94,7 @@ namespace MCGalaxy.Gui { App.updateTimer.Elapsed += delegate { App.UpdateCheck(); }; App.updateTimer.Start(); Application.Run(new Window()); } - WriteToConsole("Completed in " + (DateTime.Now - startTime).Milliseconds + "ms"); + WriteToConsole("Completed in " + (DateTime.UtcNow - startTime).Milliseconds + "ms"); } catch (Exception e) { Server.ErrorLog(e); } } diff --git a/Player/Player.Fields.cs b/Player/Player.Fields.cs index 40797d6c9..2c0e75191 100644 --- a/Player/Player.Fields.cs +++ b/Player/Player.Fields.cs @@ -235,7 +235,7 @@ namespace MCGalaxy { public int fallCount = 0, drownCount = 0; //Games - public DateTime lastDeath = DateTime.Now; + public DateTime lastDeath = DateTime.UtcNow; public byte modeType; public byte[] bindings = new byte[128]; diff --git a/Player/Player.Handlers.cs b/Player/Player.Handlers.cs index 1b9869108..2d4760873 100644 --- a/Player/Player.Handlers.cs +++ b/Player/Player.Handlers.cs @@ -826,7 +826,7 @@ return; if ( Server.lava.active && Server.lava.HasPlayer(this) && Server.lava.IsPlayerDead(this) ) return; - if ( immediate || lastDeath.AddSeconds(2) < DateTime.Now ) { + if ( immediate || lastDeath.AddSeconds(2) < DateTime.UtcNow ) { if ( level.Killer && !invincible && !hidden ) { @@ -890,7 +890,7 @@ return; if (Server.deathcount && (overallDeath > 0 && overallDeath % 10 == 0)) Chat.GlobalChatLevel(this, ColoredName + " %Shas died &3" + overallDeath + " times", false); } - lastDeath = DateTime.Now; + lastDeath = DateTime.UtcNow; } } diff --git a/util/TimeUtils.cs b/util/TimeUtils.cs index 9eb648fc3..328f1ebc4 100644 --- a/util/TimeUtils.cs +++ b/util/TimeUtils.cs @@ -23,13 +23,16 @@ namespace MCGalaxy { public static string Shorten(this TimeSpan value, bool seconds = false) { string time = ""; + bool negate = value.TotalSeconds < 0; + if (negate) value = -value; + Add(ref time, value.Days, 'd'); Add(ref time, value.Hours, 'h'); Add(ref time, value.Minutes, 'm'); if (seconds) Add(ref time, value.Seconds, 's'); if (time == "") time = seconds ? "0s" : "0m"; - return time; + return negate ? "-" + time : time; } public static TimeSpan ParseShort(this string value, char defUnit) {