forked from ccnet/CruiseControl.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCCTimeFormatter.cs
More file actions
33 lines (28 loc) · 827 Bytes
/
Copy pathCCTimeFormatter.cs
File metadata and controls
33 lines (28 loc) · 827 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System;
using System.Text;
namespace ThoughtWorks.CruiseControl.CCTrayLib
{
public class CCTimeFormatter
{
private readonly TimeSpan timeSpan;
public CCTimeFormatter(TimeSpan timeSpan)
{
this.timeSpan = timeSpan;
}
public override string ToString()
{
if (timeSpan < TimeSpan.FromMinutes(1.0))
return string.Format(System.Globalization.CultureInfo.CurrentCulture,"{0} seconds", timeSpan.Seconds);
StringBuilder sb = new StringBuilder();
AddIfNeeded(sb, timeSpan.Days, "day");
AddIfNeeded(sb, timeSpan.Hours, "hour");
AddIfNeeded(sb, timeSpan.Minutes, "minute");
return sb.ToString().Trim();
}
private void AddIfNeeded(StringBuilder sb, int value, String type)
{
if (value != 0)
sb.AppendFormat("{0} {1}{2} ", value, type, (value > 1 ? "s" : string.Empty));
}
}
}