public static TimeSpan ParseTimeSpan(string text)
{
if (text.EndsWith("ms"))
{
return TimeSpan.FromMilliseconds(
ParseDouble(text.Substring(0, text.Length - 2)));
}
char last = text[text.Length - 1];
double value = ParseDouble(text.Substring(0, text.Length - 1));
switch (last)
{
case 's': return TimeSpan.FromSeconds(value);
case 'h': return TimeSpan.FromHours(value);
case 'm': return TimeSpan.FromMinutes(value);
case 'd': return TimeSpan.FromDays(value);
}
throw new ArgumentException(text, "text");
}