Skip to content

Commit

Permalink
Merge pull request #86 from samsmithnz/MoreAccurateTimingFix
Browse files Browse the repository at this point in the history
Updating timing to be more accurate
  • Loading branch information
samsmithnz committed Apr 21, 2023
2 parents 055bb25 + c0949ad commit 0c299ae
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/DotNetCensus.Core/TimingHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@ public static class TimingHelper
{
public static string GetTime(TimeSpan timespan)
{
if (timespan.TotalMinutes > 1)
int mins = (int)timespan.TotalMinutes;
int secs = (int)timespan.TotalSeconds - (mins * 60);
int ms = (int)timespan.TotalMilliseconds - (secs * 1000) - (mins * 60 * 1000);
if (mins > 0)
{
return $"{timespan.TotalMinutes.ToString()}:{timespan.TotalSeconds.ToString("00")}.{timespan.TotalMilliseconds.ToString("0")} mins";
return $"{mins.ToString()}:{secs.ToString("00")}.{ms.ToString("0")} mins";
}
else if (timespan.TotalSeconds > 1)
else if (secs>0)
{
return $"{timespan.TotalSeconds.ToString("0")}.{timespan.TotalMilliseconds.ToString("0")} seconds";
return $"{secs.ToString("0")}.{ms.ToString("0")} seconds";
}
else
{
return $"{timespan.TotalMilliseconds.ToString("0")} ms";
return $"{ms.ToString("0")} ms";
}
}
}
Expand Down

0 comments on commit 0c299ae

Please sign in to comment.