Skip to content

FLW-857: Fix age format display across all modules#342

Open
umaseershika45 wants to merge 2 commits intoPSMRI:release-2.8from
umaseershika45:feature/FLW-857-age-formatting
Open

FLW-857: Fix age format display across all modules#342
umaseershika45 wants to merge 2 commits intoPSMRI:release-2.8from
umaseershika45:feature/FLW-857-age-formatting

Conversation

@umaseershika45
Copy link
Copy Markdown
Contributor

@umaseershika45 umaseershika45 commented Mar 30, 2026

📋 Description

JIRA ID: FLW-857

Please provide a summary of the change and the motivation behind it. Include relevant context and details.
Implemented age display logic for beneficiary cards as per requirement.

For beneficiaries below 6 years, age is displayed in Years, Months, and Days.
For beneficiaries 6 years and above, age is displayed in Years only.

This change ensures proper and consistent age representation across all modules.


✅ Type of Change

  • 🐞 Bug fix (non-breaking change which resolves an issue)
  • New feature (non-breaking change which adds functionality)
  • 🔥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 🛠 Refactor (change that is neither a fix nor a new feature)
  • ⚙️ Config change (configuration file or build script updates)
  • 📚 Documentation (updates to docs or readme)
  • 🧪 Tests (adding new or updating existing tests)
  • 🎨 UI/UX (changes that affect the user interface)
  • 🚀 Performance (improves performance)
  • 🧹 Chore (miscellaneous changes that don't modify src or test files)

ℹ️ Additional Information

Please describe how the changes were tested, and include any relevant screenshots, logs, or other information that provides additional context.
Updated getAgeDisplayString(dob) method in Ben.kt.
Verified changes in beneficiary list screens.
No UI changes involved, only logic update.
Ensured age is displayed correctly for both below and above 6 years cases.

Summary by CodeRabbit

Bug Fixes

  • Updated age display calculation to provide consistent formatting across different age groups, showing detailed breakdowns (years, months, days) for younger users and simplified format for older users.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 30, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 328e38ff-bb14-4de3-b7e4-acb49b062aec

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Modified the getAgeDisplayString() function in Ben.kt to replace day-based age formatting with unified calendar-delta computation, calculating years, months, and days separately and adjusting for negative offsets, with output format varying by age threshold.

Changes

Cohort / File(s) Summary
Age Display Logic Refactoring
app/src/main/java/org/piramalswasthya/sakhi/model/Ben.kt
Removed early return path for ages under 31 days; replaced with unified calendar-delta computation that always calculates years/months/days, adjusts via decrement operators for negative offsets, and returns composite format for ages under 6 years or years-only for ages 6+.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 The age display hops along so free,
No more day-counting, just one decree,
Years and months in harmony dance,
Calendar deltas get their chance,
Cleaner logic, simpler to see!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: updating age format display logic in the getAgeDisplayString function to fix and standardize age representation across modules.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@NikhilFegade
Copy link
Copy Markdown
Member

@CodeRabbit review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 3, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
app/src/main/java/org/piramalswasthya/sakhi/model/Ben.kt (1)

795-819: ⚠️ Potential issue | 🟠 Major

The month-end borrow can still produce negative day counts.

With a DOB on January 31 and a current date of March 1, this path leaves days == -2, so the UI can render 0 Years 1 Months -2 Days. Please switch this to elapsed-date calculation instead of subtracting calendar fields directly, and add a regression test for month-end/leap-year cases.

🐛 Proposed fix
 fun getAgeDisplayString(dob: Long): String {
-    val calDob = Calendar.getInstance().apply { timeInMillis = dob }
-    val calNow = Calendar.getInstance()
-
-    var years = calNow.get(Calendar.YEAR) - calDob.get(Calendar.YEAR)
-    var months = calNow.get(Calendar.MONTH) - calDob.get(Calendar.MONTH)
-    var days = calNow.get(Calendar.DAY_OF_MONTH) - calDob.get(Calendar.DAY_OF_MONTH)
-
-    if (days < 0) {
-        months--
-        val tempCal = calNow.clone() as Calendar
-        tempCal.add(Calendar.MONTH, -1)
-        days += tempCal.getActualMaximum(Calendar.DAY_OF_MONTH)
-    }
-
-    if (months < 0) {
-        years--
-        months += 12
-    }
+    val calDob = Calendar.getInstance().apply {
+        timeInMillis = dob
+        set(Calendar.HOUR_OF_DAY, 0)
+        set(Calendar.MINUTE, 0)
+        set(Calendar.SECOND, 0)
+        set(Calendar.MILLISECOND, 0)
+    }
+    val calNow = Calendar.getInstance().apply {
+        set(Calendar.HOUR_OF_DAY, 0)
+        set(Calendar.MINUTE, 0)
+        set(Calendar.SECOND, 0)
+        set(Calendar.MILLISECOND, 0)
+    }
+    if (calDob.after(calNow)) return "0 Years 0 Months 0 Days"
+
+    val cursor = calDob.clone() as Calendar
+    var years = 0
+    while (true) {
+        val next = cursor.clone() as Calendar
+        next.add(Calendar.YEAR, 1)
+        if (next.after(calNow)) break
+        cursor.add(Calendar.YEAR, 1)
+        years++
+    }
+
+    var months = 0
+    while (true) {
+        val next = cursor.clone() as Calendar
+        next.add(Calendar.MONTH, 1)
+        if (next.after(calNow)) break
+        cursor.add(Calendar.MONTH, 1)
+        months++
+    }
+
+    var days = 0
+    while (true) {
+        val next = cursor.clone() as Calendar
+        next.add(Calendar.DAY_OF_MONTH, 1)
+        if (next.after(calNow)) break
+        cursor.add(Calendar.DAY_OF_MONTH, 1)
+        days++
+    }
 
     return if (years < 6) {
         "$years Years $months Months $days Days"
     } else {
         "$years Years"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/src/main/java/org/piramalswasthya/sakhi/model/Ben.kt` around lines 795 -
819, The current getAgeDisplayString(dob: Long) computes years/months/days by
subtracting Calendar fields which can yield negative day results for month-end
dates; replace that logic with an elapsed-date calculation using
java.time.LocalDate and java.time.Period (convert dob millis to
Instant->ZoneId.systemDefault()->LocalDate), then derive years/months/days from
Period to guarantee non-negative day/month components; update the function
getAgeDisplayString to return "Y Years M Months D Days" for ages <6 and "Y
Years" otherwise, and add regression tests covering cases like DOB=Jan 31 to
current=Mar 1 and leap-year boundaries to assert no negative days are produced.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@app/src/main/java/org/piramalswasthya/sakhi/model/Ben.kt`:
- Around line 815-818: BenBasicDomainForForm.age is still returning the legacy
"$ageInt $ageUnit" string while BenBasicDomain.age uses
getAgeDisplayString(dob), so form-backed models are inconsistent; update the age
getter/logic in BenBasicDomainForForm (and any similar form model) to call
getAgeDisplayString(dob) (or reuse the same helper) instead of building "$ageInt
$ageUnit" so the form modules use the same display format (including the years<6
months/days behavior) as BenBasicDomain.

---

Outside diff comments:
In `@app/src/main/java/org/piramalswasthya/sakhi/model/Ben.kt`:
- Around line 795-819: The current getAgeDisplayString(dob: Long) computes
years/months/days by subtracting Calendar fields which can yield negative day
results for month-end dates; replace that logic with an elapsed-date calculation
using java.time.LocalDate and java.time.Period (convert dob millis to
Instant->ZoneId.systemDefault()->LocalDate), then derive years/months/days from
Period to guarantee non-negative day/month components; update the function
getAgeDisplayString to return "Y Years M Months D Days" for ages <6 and "Y
Years" otherwise, and add regression tests covering cases like DOB=Jan 31 to
current=Mar 1 and leap-year boundaries to assert no negative days are produced.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 64eaceea-3b26-4093-91f0-f4e9a637cf47

📥 Commits

Reviewing files that changed from the base of the PR and between 0103f3b and e0991e7.

📒 Files selected for processing (1)
  • app/src/main/java/org/piramalswasthya/sakhi/model/Ben.kt

@NikhilFegade
Copy link
Copy Markdown
Member

@umaseershika45 please fix coderabbit suggestion also do unit testing

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 3, 2026

@umaseershika45
Copy link
Copy Markdown
Contributor Author

umaseershika45 commented Apr 3, 2026

@umaseershika45 please fix coderabbit suggestion also do unit testing

Sure sir, I have fixed the CodeRabbit suggestion by updating the form models also. I have verified the changes and completed unit testing as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants