diff --git a/app/src/main/java/org/thoughtcrime/securesms/notifications/profiles/NotificationProfileSchedule.kt b/app/src/main/java/org/thoughtcrime/securesms/notifications/profiles/NotificationProfileSchedule.kt index 949905482..1bdf9efc6 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/notifications/profiles/NotificationProfileSchedule.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/notifications/profiles/NotificationProfileSchedule.kt @@ -51,8 +51,15 @@ data class NotificationProfileSchedule( return LocalTime.of(start / 100, start % 100) } - fun startDateTime(now: LocalDateTime): LocalDateTime { - return start.toLocalDateTime(now) + fun startDateTime(localNow: LocalDateTime): LocalDateTime { + val localStart: LocalDateTime = start.toLocalDateTime(localNow) + val localEnd: LocalDateTime = end.toLocalDateTime(localNow) + + return if (end < start && (daysEnabled.contains(localStart.dayOfWeek.minus(1)) && localNow.isBetween(localStart.minusDays(1), localEnd))) { + localStart.minusDays(1) + } else { + localStart + } } fun endTime(): LocalTime { diff --git a/app/src/test/java/org/thoughtcrime/securesms/notifications/profiles/NotificationProfilesTest.kt b/app/src/test/java/org/thoughtcrime/securesms/notifications/profiles/NotificationProfilesTest.kt index 36916c096..059d7ed51 100644 --- a/app/src/test/java/org/thoughtcrime/securesms/notifications/profiles/NotificationProfilesTest.kt +++ b/app/src/test/java/org/thoughtcrime/securesms/notifications/profiles/NotificationProfilesTest.kt @@ -151,4 +151,15 @@ class NotificationProfilesTest { val profiles = listOf(first.copy(schedule = schedule)) assertThat("active profile is first", NotificationProfiles.getActiveProfile(profiles, monday830am.toMillis(ZoneOffset.UTC), utc), `is`(profiles[0])) } + + @Test + fun `when profile is manually disabled and schedule is on but with start after end and now is before end then return null`() { + signalStore.dataSet.putLong(NotificationProfileValues.KEY_MANUALLY_ENABLED_PROFILE, 0) + signalStore.dataSet.putLong(NotificationProfileValues.KEY_MANUALLY_ENABLED_UNTIL, 0) + signalStore.dataSet.putLong(NotificationProfileValues.KEY_MANUALLY_DISABLED_AT, sunday830am.toMillis(ZoneOffset.UTC)) + + val schedule = NotificationProfileSchedule(id = 3L, enabled = true, start = 2200, end = 1000, daysEnabled = DayOfWeek.values().toSet()) + val profiles = listOf(first.copy(schedule = schedule)) + assertThat("active profile is null", NotificationProfiles.getActiveProfile(profiles, sunday9am.toMillis(ZoneOffset.UTC), utc), nullValue()) + } }