public static decimal GetTotalTimeUnitsInHours(DateIncrement increment) { var hours = 0m; if (increment.type == DateIncrementTypes.Day) { hours = increment.increments * 24; } if (increment.type == DateIncrementTypes.Month) { hours = increment.increments * 24 * 30; } if (increment.type == DateIncrementTypes.Year) { hours = increment.increments * 24 * 30 * 12; } return(hours); }
/// <summary> /// Obtiene los valores de un incremento /// </summary> private (int increment, DateIncrement type) GetDateIncrement(string value) { DateIncrement type = DateIncrement.Day; // Obtiene el tipo de incremento value = value.ToUpper(); if (value.EndsWith("W")) { type = DateIncrement.Week; } else if (value.EndsWith("M")) { type = DateIncrement.Month; } else if (value.EndsWith("Y")) { type = DateIncrement.Year; } // Quita el tipo de incremento if (value.EndsWith("D") || value.EndsWith("W") || value.EndsWith("M") || value.EndsWith("Y")) { if (value.Length > 1) { value = value.Substring(0, value.Length - 1); } else { value = "1"; } } // Obtiene el incremento if (!int.TryParse(value, out int result)) { throw new NotImplementedException("The increment has no value"); } else { return(result, type); } }