Use DateTime.UtcNow in more places and fix TimeUtils.Shorten for negative timespans.

This commit is contained in:
UnknownShadow200 2016-07-13 09:19:34 +10:00
parent b98ffc5bf5
commit 8631316201
4 changed files with 9 additions and 6 deletions

View File

@ -52,7 +52,7 @@ namespace MCGalaxy.Gui {
static bool useConsole, useHighQualityGui; static bool useConsole, useHighQualityGui;
[STAThread] [STAThread]
public static void Main(string[] args) { public static void Main(string[] args) {
DateTime startTime = DateTime.Now; DateTime startTime = DateTime.UtcNow;
Process[] duplicates = Process.GetProcessesByName("MCGalaxy"); Process[] duplicates = Process.GetProcessesByName("MCGalaxy");
if (duplicates.Length != 1) { if (duplicates.Length != 1) {
Process proc = Process.GetCurrentProcess(); Process proc = Process.GetCurrentProcess();
@ -94,7 +94,7 @@ namespace MCGalaxy.Gui {
App.updateTimer.Elapsed += delegate { App.UpdateCheck(); }; App.updateTimer.Start(); App.updateTimer.Elapsed += delegate { App.UpdateCheck(); }; App.updateTimer.Start();
Application.Run(new Window()); 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); } catch (Exception e) { Server.ErrorLog(e); }
} }

View File

@ -235,7 +235,7 @@ namespace MCGalaxy {
public int fallCount = 0, drownCount = 0; public int fallCount = 0, drownCount = 0;
//Games //Games
public DateTime lastDeath = DateTime.Now; public DateTime lastDeath = DateTime.UtcNow;
public byte modeType; public byte modeType;
public byte[] bindings = new byte[128]; public byte[] bindings = new byte[128];

View File

@ -826,7 +826,7 @@ return;
if ( Server.lava.active && Server.lava.HasPlayer(this) && Server.lava.IsPlayerDead(this) ) if ( Server.lava.active && Server.lava.HasPlayer(this) && Server.lava.IsPlayerDead(this) )
return; return;
if ( immediate || lastDeath.AddSeconds(2) < DateTime.Now ) { if ( immediate || lastDeath.AddSeconds(2) < DateTime.UtcNow ) {
if ( level.Killer && !invincible && !hidden ) { if ( level.Killer && !invincible && !hidden ) {
@ -890,7 +890,7 @@ return;
if (Server.deathcount && (overallDeath > 0 && overallDeath % 10 == 0)) if (Server.deathcount && (overallDeath > 0 && overallDeath % 10 == 0))
Chat.GlobalChatLevel(this, ColoredName + " %Shas died &3" + overallDeath + " times", false); Chat.GlobalChatLevel(this, ColoredName + " %Shas died &3" + overallDeath + " times", false);
} }
lastDeath = DateTime.Now; lastDeath = DateTime.UtcNow;
} }
} }

View File

@ -23,13 +23,16 @@ namespace MCGalaxy {
public static string Shorten(this TimeSpan value, bool seconds = false) { public static string Shorten(this TimeSpan value, bool seconds = false) {
string time = ""; string time = "";
bool negate = value.TotalSeconds < 0;
if (negate) value = -value;
Add(ref time, value.Days, 'd'); Add(ref time, value.Days, 'd');
Add(ref time, value.Hours, 'h'); Add(ref time, value.Hours, 'h');
Add(ref time, value.Minutes, 'm'); Add(ref time, value.Minutes, 'm');
if (seconds) Add(ref time, value.Seconds, 's'); if (seconds) Add(ref time, value.Seconds, 's');
if (time == "") time = seconds ? "0s" : "0m"; if (time == "") time = seconds ? "0s" : "0m";
return time; return negate ? "-" + time : time;
} }
public static TimeSpan ParseShort(this string value, char defUnit) { public static TimeSpan ParseShort(this string value, char defUnit) {