protected static string DurationToDisplayString(double duration)
{
if(duration < 60)
return string.Format("{0:F1}s", duration);
else if(duration < 3600)
{
int minutes = (int) Math.Floor(duration / 60);
double remainder = duration - minutes * 60;
if(remainder > 1)
return string.Format("{0}m {1}", minutes, DurationToDisplayString(remainder));
else
return string.Format("{0}m", minutes);
}
else if(duration < 21600)
{
int hours = (int) Math.Floor(duration / 3600);
double remainder = duration - hours * 3600;
if(remainder > 1)
return string.Format("{0}h {1}", hours, DurationToDisplayString(remainder));
else
return string.Format("{0}h", hours);
}
else
{
int days = (int) Math.Floor(duration / 21600);
double remainder = duration - days * 21600;
if(remainder > 1)
return string.Format("{0}d {1}", days, DurationToDisplayString(remainder));
else
return string.Format("{0}d", days);
}
}