Merge pull request #59 from itwtx/master
Merge pull request #59 from itwtx/master

Optimized time formatting

--- a/KerbalEngineer/Flight/Readouts/ReadoutLibrary.cs
+++ b/KerbalEngineer/Flight/Readouts/ReadoutLibrary.cs
@@ -120,6 +120,7 @@
                 readouts.Add(new ImpactBiome());
 
                 // Vessel
+                readouts.Add(new Name());
                 readouts.Add(new DeltaVStaged());
                 readouts.Add(new DeltaVCurrent());
                 readouts.Add(new DeltaVTotal());

--- /dev/null
+++ b/KerbalEngineer/Flight/Readouts/Vessel/Name.cs
@@ -1,1 +1,55 @@
+// 
+//     Kerbal Engineer Redux
+// 
+//     Copyright (C) 2014 CYBUTEK
+// 
+//     This program is free software: you can redistribute it and/or modify
+//     it under the terms of the GNU General Public License as published by
+//     the Free Software Foundation, either version 3 of the License, or
+//     (at your option) any later version.
+// 
+//     This program is distributed in the hope that it will be useful,
+//     but WITHOUT ANY WARRANTY; without even the implied warranty of
+//     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//     GNU General Public License for more details.
+// 
+//     You should have received a copy of the GNU General Public License
+//     along with this program.  If not, see <http://www.gnu.org/licenses/>.
+// 
 
+#region Using Directives
+
+using KerbalEngineer.Flight.Sections;
+using KerbalEngineer.Helpers;
+
+#endregion
+
+namespace KerbalEngineer.Flight.Readouts.Vessel
+{
+    public class Name : ReadoutModule
+    {
+        #region Constructors
+
+        public Name()
+        {
+            Name = "Name";
+            Category = ReadoutCategory.GetCategory("Vessel");
+            HelpString = "Displays the name of the current vessel.";
+            IsDefault = true;
+        }
+
+        #endregion
+
+        #region Methods: public
+
+        public override void Draw(SectionModule section)
+        {
+            if (SimulationProcessor.ShowDetails)
+            {
+                DrawLine(FlightGlobals.ActiveVessel.vesselName);
+            }
+        }
+
+        #endregion
+    }
+}

--- a/KerbalEngineer/Helpers/TimeFormatter.cs
+++ b/KerbalEngineer/Helpers/TimeFormatter.cs
@@ -58,31 +58,23 @@
         public static string ConvertToString(double seconds, string format = "F1")
         {
             var years = 0;
-            while (seconds >= SecondsPerYear)
+            var days = 0;
+            var hours = 0;
+            var minutes = 0;
+
+            if (seconds > 0)
             {
-                years++;
-                seconds -= SecondsPerYear;
-            }
+                years = (int)(seconds / SecondsPerYear);
+                seconds -= years * SecondsPerYear;
 
-            var days = 0;
-            while (seconds >= SecondsPerDay)
-            {
-                days++;
-                seconds -= SecondsPerDay;
-            }
+                days = (int)(seconds / SecondsPerDay);
+                seconds -= days * SecondsPerDay;
 
-            var hours = 0;
-            while (seconds >= SecondsPerHour)
-            {
-                hours++;
-                seconds -= SecondsPerHour;
-            }
+                hours = (int)(seconds / SecondsPerHour);
+                seconds -= hours * SecondsPerHour;
 
-            var minutes = 0;
-            while (seconds >= SecondsPerMinute)
-            {
-                minutes++;
-                seconds -= SecondsPerMinute;
+                minutes = (int)(seconds / SecondsPerMinute);
+                seconds -= minutes * SecondsPerMinute;
             }
 
             if (years > 0)

--- a/KerbalEngineer/KerbalEngineer.csproj
+++ b/KerbalEngineer/KerbalEngineer.csproj
@@ -115,6 +115,7 @@
     <Compile Include="Flight\Readouts\Thermal\HottestTemperature.cs" />
     <Compile Include="Flight\Readouts\Thermal\HottestPart.cs" />
     <Compile Include="Flight\Readouts\Thermal\ThermalProcessor.cs" />
+    <Compile Include="Flight\Readouts\Vessel\Name.cs" />
     <Compile Include="Flight\Readouts\Vessel\AttitudeProcessor.cs" />
     <Compile Include="Flight\Readouts\Vessel\DeltaVCurrentTotal.cs" />
     <Compile Include="Flight\Readouts\Vessel\PitchRate.cs" />