/// <summary> /// Returns the time given the hours, minutes, and seconds /// Displays -- if the values exceed their limits. /// For the sake of performance, assumes all values are +ve. /// </summary> /// <param name="hours"></param> /// <param name="minutes"></param> /// <param name="secs"></param> /// <returns></returns> public static string FormatTime(int hours, int minutes, int secs) { StringFast sf = new StringFast(15); // Deal with most common scenarios first if (hours == 0) { sf.Set("00"); } else if (hours < 10) { sf.Set("0"); sf.Append(hours); } else if (hours < 99) { sf.Set(hours); } else { sf.Set("--"); } sf.Append(":"); if (minutes > 59) { sf.Append("--"); } else if (minutes > 9) { sf.Append(minutes); } else { sf.Append("0"); sf.Append(minutes); } sf.Append(":"); if (secs > 59) { sf.Append("--"); } else if (secs > 9) { sf.Append(secs); } else { sf.Append("0"); sf.Append(secs); } return(sf.ToString()); }
/// <summary> /// Returns the time given the hours and minutes /// Displays -- if the values exceed their limits. /// For the sake of performance, assumes all values are +ve. /// </summary> /// <param name="hours"></param> /// <param name="minutes"></param> /// <returns></returns> public static string FormatTime(int hours, int minutes) { StringFast sf = new StringFast(6); if (hours == 0) { sf.Set("00"); } else if (hours < 10) { sf.Set("0"); sf.Append(hours); } else if (hours < 99) { sf.Set(hours); } else { sf.Set("--"); } sf.Append(":"); if (minutes > 59) { sf.Append("--"); } else if (minutes > 9) { sf.Append(minutes); } else { sf.Append("0"); sf.Append(minutes); } return(sf.ToString()); }
/// <summary> /// Return the time given the minutes, seconds and milliseconds. /// Show msecs as tenths or hundredths of a second. /// Display -- or --- if the values exceed their limits. /// For the sake of performance, assumes all values are +ve. /// </summary> /// <param name="minutes"></param> /// <param name="secs"></param> /// <param name="msecs"></param> /// <param name="showTenths"></param> /// <returns></returns> public static string FormatTime(int minutes, int secs, int msecs, bool showTenths) { // Equivalent to: String.Format("{0:00}:{1:00}." + (showTenths ? "{2:00}" : "{2:000}"), minutes, seconds, msecs); StringFast sf = new StringFast(10); if (minutes > 59) { sf.Set("--"); } else if (minutes > 9) { sf.Set(minutes); } else { sf.Set("0"); sf.Append(minutes); } sf.Append(":"); if (secs > 59) { sf.Append("--"); } else if (secs > 9) { sf.Append(secs); } else { sf.Append("0"); sf.Append(secs); } sf.Append("."); if (showTenths) { if (msecs > 99) { sf.Append("--"); } else if (msecs > 9) { sf.Append(msecs); } else { sf.Append("0"); sf.Append(msecs); } } else { if (msecs > 999) { sf.Append("---"); } else if (msecs > 99) { sf.Append(msecs); } else if (msecs > 9) { sf.Append("0"); sf.Append(msecs); } else { sf.Append("00"); sf.Append(msecs); } } return(sf.ToString()); }
/// <summary> /// Return the time given the hours, minutes, seconds and milliseconds. /// Show msecs as tenths or hundredths of a second. /// Display -- or --- if the values exceed their limits. /// For the sake of performance, assumes all values are +ve. /// </summary> /// <param name="hours"></param> /// <param name="minutes"></param> /// <param name="secs"></param> /// <param name="msecs"></param> /// <param name="showTenths"></param> /// <returns></returns> public static string FormatTime(int hours, int minutes, int secs, int msecs, bool showTenths) { // Equivalent to: String.Format("{0:00}:{1:00}:{2:00}." + (showTenths ? "{3:00}" : "{3:000}"), hours, minutes, seconds, msecs); StringFast sf = new StringFast(15); // Deal with most common scenarios first if (hours == 0) { sf.Set("00"); } else if (hours < 10) { sf.Set("0"); sf.Append(hours); } else if (hours < 99) { sf.Set(hours); } else { sf.Set("--"); } sf.Append(":"); if (minutes > 59) { sf.Append("--"); } else if (minutes > 9) { sf.Append(minutes); } else { sf.Append("0"); sf.Append(minutes); } sf.Append(":"); if (secs > 59) { sf.Append("--"); } else if (secs > 9) { sf.Append(secs); } else { sf.Append("0"); sf.Append(secs); } sf.Append("."); if (showTenths) { if (msecs > 99) { sf.Append("--"); } else if (msecs > 9) { sf.Append(msecs); } else { sf.Append("0"); sf.Append(msecs); } } else { if (msecs > 999) { sf.Append("---"); } else if (msecs > 99) { sf.Append(msecs); } else if (msecs > 9) { sf.Append("0"); sf.Append(msecs); } else { sf.Append("00"); sf.Append(msecs); } } return(sf.ToString()); }