FormatTimeSpan
Definition
- Namespace
- Resto.Front.PrintTemplates.Cheques.Razor
Formats an elapsed duration as total hours and minutes, optionally including seconds.
string TemplateBaseCore<T>.FormatTimeSpan(TimeSpan timeSpan, bool displaySeconds)
- Returns
string- Nullability
- Not specified
- Declared in
- Resto.Front.PrintTemplates.Cheques.Razor.TemplateBaseCore<T>
- Model purpose
- Base class for RazorEngineCore print templates. Model contains the document data of type T. Provides formatting and markup output methods.
Parameters
TimeSpan timeSpan- Duration to display; normally nonnegative.
bool displaySeconds- True for hours:minutes:seconds; false for hours:minutes rounded according to the seconds component.
Return value
Colon-separated components padded to at least two digits; hours can exceed 23.
Remarks
With seconds, subsecond ticks are discarded. Without seconds, one minute is added only when TimeSpan.Seconds >= 30. TotalHours is cast to Int32; values beyond its range are not reliably supported. Negative durations are not normalized to one leading minus: each component retains its sign, and negative seconds do not trigger rounding.
Exceptions
System.OverflowException- Adding the rounding minute would exceed TimeSpan.MaxValue.
Example
FormatTimeSpan(new TimeSpan(1, 2, 3, 30), true); // "26:03:30" FormatTimeSpan(new TimeSpan(1, 2, 3, 30), false); // "26:04"