public static double GetValue(this TimeSpan thisValue, TimeUnit unit) { unit = unit.HighestFlag(); switch (unit) { case TimeUnit.Millisecond: return(thisValue.Milliseconds); case TimeUnit.Second: return(thisValue.Seconds * 1000); case TimeUnit.Minute: return(thisValue.Minutes * 60 * 1000); case TimeUnit.Hour: return(thisValue.Hours * 60 * 60 * 1000); case TimeUnit.Day: return(thisValue.Days * 24 * 60 * 60 * 1000); default: return(0); } }
public static double GetValueAt(this TimeSpan thisValue, TimeUnit unit) { unit = unit.HighestFlag(); int max = __timeUnitValues.Value.IndexOf(unit); if (max < 0) { throw new ArgumentOutOfRangeException(nameof(unit)); } double value = 0; for (int i = 0; i <= max; i++) { value += GetValue(thisValue, __timeUnitValues.Value[i]); } return(value); }