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;
[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); }
}

View File

@ -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];

View File

@ -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;
}
}

View File

@ -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) {