diff --git a/core/common/src/commonMain/kotlin/org/mifos/mobile/core/common/DateHelper.kt b/core/common/src/commonMain/kotlin/org/mifos/mobile/core/common/DateHelper.kt index 5eac4bdaf..87f6073be 100644 --- a/core/common/src/commonMain/kotlin/org/mifos/mobile/core/common/DateHelper.kt +++ b/core/common/src/commonMain/kotlin/org/mifos/mobile/core/common/DateHelper.kt @@ -350,4 +350,9 @@ object DateHelper { * "dd-MM-yyyy" is the format of the date picker. */ val formattedShortDate = currentDate.format(shortMonthFormat) + + fun getMonth(month: Int): String { + require(month in 1..12) { "Month should be between 1 and 12" } + return Month.entries[month - 1].name.lowercase().replaceFirstChar { it.uppercase() } + } } diff --git a/core/common/src/commonMain/kotlin/org/mifos/mobile/core/common/Utils.kt b/core/common/src/commonMain/kotlin/org/mifos/mobile/core/common/Utils.kt index 3090b4769..4b4837c06 100644 --- a/core/common/src/commonMain/kotlin/org/mifos/mobile/core/common/Utils.kt +++ b/core/common/src/commonMain/kotlin/org/mifos/mobile/core/common/Utils.kt @@ -18,16 +18,12 @@ object Utils { return formString.toString() } - fun formatTransactionType(type: String?): String { - val builder = StringBuilder() - try { - type?.lowercase()?.split("_")?.forEach { str -> - builder.append( - str[0].uppercaseChar() + str.substring(1), - ).append(" ") + fun formatTransactionType(type: String?): String = + type?.lowercase() + ?.split("_") + ?.joinToString(" ") { word -> + word.replaceFirstChar { it.uppercase() } } - } catch (_: Exception) { - } - return builder.toString().trim() - } + ?.trim() + ?: "" }