From b0d5a421e3144b649540063d59ad04ae1ae34fbe Mon Sep 17 00:00:00 2001 From: vibhutomer Date: Tue, 12 May 2026 21:40:16 +0530 Subject: [PATCH 1/2] Fix: Update date parsing logic in VLFRepo to handle multiple ISO formats --- .../piramalswasthya/sakhi/repositories/VLFRepo.kt | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/piramalswasthya/sakhi/repositories/VLFRepo.kt b/app/src/main/java/org/piramalswasthya/sakhi/repositories/VLFRepo.kt index 2b63a41ef..c1af42dfd 100644 --- a/app/src/main/java/org/piramalswasthya/sakhi/repositories/VLFRepo.kt +++ b/app/src/main/java/org/piramalswasthya/sakhi/repositories/VLFRepo.kt @@ -1492,12 +1492,16 @@ class VLFRepo @Inject constructor( return combine(vhnd, vhnc, phc, ahd, deworming) { vhndList, vhncList, phcList, ahdList, dewormingCount -> fun isInCurrentMonth(dateStr: String?): Boolean { - return try { - val date = LocalDate.parse(dateStr, formatter) - YearMonth.from(date) == current - } catch (e: Exception) { - false + if (dateStr.isNullOrBlank()) return false + for (formatter in formats) { + try { + val date = LocalDate.parse(dateStr, formatter) + if (YearMonth.from(date) == current) return true + } catch (e: Exception) { + continue + } } + return false } mapOf( From 233af85cffce9d75e02bef702e27ef479d687cc1 Mon Sep 17 00:00:00 2001 From: vibhutomer Date: Tue, 12 May 2026 21:49:00 +0530 Subject: [PATCH 2/2] Fix: Resolve SonarCloud complexity and empty catch block issues --- .../piramalswasthya/sakhi/repositories/VLFRepo.kt | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/piramalswasthya/sakhi/repositories/VLFRepo.kt b/app/src/main/java/org/piramalswasthya/sakhi/repositories/VLFRepo.kt index c1af42dfd..7963c2e62 100644 --- a/app/src/main/java/org/piramalswasthya/sakhi/repositories/VLFRepo.kt +++ b/app/src/main/java/org/piramalswasthya/sakhi/repositories/VLFRepo.kt @@ -1493,15 +1493,16 @@ class VLFRepo @Inject constructor( fun isInCurrentMonth(dateStr: String?): Boolean { if (dateStr.isNullOrBlank()) return false - for (formatter in formats) { + val parsedDate = try { + LocalDate.parse(dateStr, formatIndian) + } catch (e: java.time.format.DateTimeParseException) { try { - val date = LocalDate.parse(dateStr, formatter) - if (YearMonth.from(date) == current) return true - } catch (e: Exception) { - continue + LocalDate.parse(dateStr, formatIso) + } catch (e2: java.time.format.DateTimeParseException) { + null } } - return false + return parsedDate != null && YearMonth.from(parsedDate) == current } mapOf(