Skip to content

Commit

Permalink
correctly display correct formatted schedule or overdue date label
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferdy Rodriguez authored and ferdyrod committed May 30, 2024
1 parent f5bf20c commit 70bb48b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/src/test/java/org/dhis2/bindings/DateExtensionsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -113,7 +116,6 @@ fun Date?.toOverdueOrScheduledUiText(
isOverdue,
)
}

period.months >= 3 && period.years < 1 -> {
getString(
resourceManager,
Expand All @@ -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 {
Expand All @@ -133,8 +134,6 @@ fun Date?.toOverdueOrScheduledUiText(

getOverdueDaysString(intervalDays, isOverdue)
}

period.days == 0 -> resourceManager.getString(R.string.overdue_today)
else -> {
getOverdueDaysString(period.days, isOverdue)
}
Expand Down

0 comments on commit 70bb48b

Please sign in to comment.