From 70bb48bbd4e00aa87bd323a5b8b9dd977c3551a1 Mon Sep 17 00:00:00 2001 From: Ferdy Rodriguez Date: Mon, 27 May 2024 16:23:55 +0200 Subject: [PATCH] correctly display correct formatted schedule or overdue date label --- .../test/java/org/dhis2/bindings/DateExtensionsTest.kt | 2 +- .../main/java/org/dhis2/commons/date/DateExtensions.kt | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/src/test/java/org/dhis2/bindings/DateExtensionsTest.kt b/app/src/test/java/org/dhis2/bindings/DateExtensionsTest.kt index 29ca4bf6b1..dc5d84de1c 100644 --- a/app/src/test/java/org/dhis2/bindings/DateExtensionsTest.kt +++ b/app/src/test/java/org/dhis2/bindings/DateExtensionsTest.kt @@ -205,7 +205,7 @@ class DateExtensionsTest { } @Test - fun `Should return 'In x days', when the scheduled date is same day but more than 3 month and same year`() { + fun `Should return 'In x days', when the scheduled date is same day but different month and same year`() { val currentDate = currentCalendar().time val date: Date? = currentCalendar().apply { add(Calendar.MONTH, 1) diff --git a/commons/src/main/java/org/dhis2/commons/date/DateExtensions.kt b/commons/src/main/java/org/dhis2/commons/date/DateExtensions.kt index 1896d4fca8..17b532a446 100644 --- a/commons/src/main/java/org/dhis2/commons/date/DateExtensions.kt +++ b/commons/src/main/java/org/dhis2/commons/date/DateExtensions.kt @@ -104,6 +104,9 @@ fun Date?.toOverdueOrScheduledUiText( }.toPeriod(PeriodType.yearMonthDayTime()) return when { + period.days == 0 && period.months == 0 && period.years == 0 -> { + resourceManager.getString(R.string.overdue_today) + } period.years >= 1 -> { getString( resourceManager, @@ -113,7 +116,6 @@ fun Date?.toOverdueOrScheduledUiText( isOverdue, ) } - period.months >= 3 && period.years < 1 -> { getString( resourceManager, @@ -123,8 +125,7 @@ fun Date?.toOverdueOrScheduledUiText( isOverdue, ) } - - period.days in 0..89 && period.months in 1..3 -> { + period.days in 0..89 && period.months in 0..2 -> { val intervalDays = if (this.time > currentDay.time) { Interval(currentDay.time, this.time) } else { @@ -133,8 +134,6 @@ fun Date?.toOverdueOrScheduledUiText( getOverdueDaysString(intervalDays, isOverdue) } - - period.days == 0 -> resourceManager.getString(R.string.overdue_today) else -> { getOverdueDaysString(period.days, isOverdue) }