From f5bf20c7bee866f560fc8ec09fecda1343aa53f1 Mon Sep 17 00:00:00 2001 From: FerdyRod Date: Fri, 24 May 2024 15:56:09 +0200 Subject: [PATCH] check schedule date when day is the same as current day but different month --- .../test/java/org/dhis2/bindings/DateExtensionsTest.kt | 10 ++++++++++ .../main/java/org/dhis2/commons/date/DateExtensions.kt | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/src/test/java/org/dhis2/bindings/DateExtensionsTest.kt b/app/src/test/java/org/dhis2/bindings/DateExtensionsTest.kt index 64f870f3c0..29ca4bf6b1 100644 --- a/app/src/test/java/org/dhis2/bindings/DateExtensionsTest.kt +++ b/app/src/test/java/org/dhis2/bindings/DateExtensionsTest.kt @@ -204,6 +204,16 @@ class DateExtensionsTest { assert(date.toOverdueOrScheduledUiText(resourceManager, currentDate) == "Today") } + @Test + fun `Should return 'In x days', when the scheduled date is same day but more than 3 month and same year`() { + val currentDate = currentCalendar().time + val date: Date? = currentCalendar().apply { + add(Calendar.MONTH, 1) + }.time + whenever(resourceManager.getPlural(R.plurals.schedule_days, 30, 30)) doReturn "In 30 days" + assert(date.toOverdueOrScheduledUiText(resourceManager, currentDate) == "In 30 days") + } + @Test fun `Should return 'In x days', when the current date is -x days from the scheduled date and less than 90 days`() { val currentDate = currentCalendar().time 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 f2258133e6..1896d4fca8 100644 --- a/commons/src/main/java/org/dhis2/commons/date/DateExtensions.kt +++ b/commons/src/main/java/org/dhis2/commons/date/DateExtensions.kt @@ -124,7 +124,7 @@ fun Date?.toOverdueOrScheduledUiText( ) } - period.days in 1..89 -> { + period.days in 0..89 && period.months in 1..3 -> { val intervalDays = if (this.time > currentDay.time) { Interval(currentDay.time, this.time) } else {