Merge #128 into release/v1.4.0

This commit is contained in:
makiolaj committed 2026-11-18 19:47:30 +01:00
commit 4bb48555b0
11 files changed
+243 -22

No files matched your search

+4
View File
@@ -32,6 +32,10 @@ All notable changes to this project are documented here. The format follows
it back as a date; other apps show that time. Reminders for it ring at the
all-day reminder time. With a tasks app as the store, both ends gain or
drop their time together (#101).
- Upcoming can be limited to tasks due within the next week, two weeks,
month, three months or year, from its view options. The home count and
preview and Upcoming widgets follow; tasks due further ahead stay in All
(#128).
## [1.3.2] - 2026-11-13
@@ -19,6 +19,9 @@ import de.jeanlucmakiola.agendula.domain.TaskSection
import de.jeanlucmakiola.agendula.domain.asTaskReminder
import de.jeanlucmakiola.agendula.domain.asReminderLead
import de.jeanlucmakiola.agendula.domain.TaskSortOrder
import de.jeanlucmakiola.agendula.domain.SmartList
import de.jeanlucmakiola.agendula.domain.UpcomingRange
import de.jeanlucmakiola.agendula.domain.dueBefore
import de.jeanlucmakiola.floret.reminders.ReminderLead
import de.jeanlucmakiola.floret.reminders.ReminderOverride
import de.jeanlucmakiola.floret.reminders.ReminderOverrideCodec
@@ -28,9 +31,12 @@ import de.jeanlucmakiola.floret.reminders.reminderLeadsFor
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.distinctUntilChanged
import java.time.DayOfWeek
import java.time.ZoneId
import kotlinx.coroutines.flow.map
import javax.inject.Inject
import javax.inject.Singleton
import kotlin.time.Clock
import kotlin.time.Instant
/** [BLACK] is dark with pure-black surfaces, for AMOLED screens. */
enum class ThemeMode {
@@ -122,14 +128,24 @@ data class Settings(
val defaultStartToday: Boolean = false,
/** Task-list sections folded away; Done starts folded. */
val collapsedSections: Set<TaskSection> = DEFAULT_COLLAPSED_SECTIONS,
/** How far ahead the Upcoming smart list reaches. */
val upcomingRange: UpcomingRange = UpcomingRange.ALL,
) {
/** [tasks] as [filter] shows them: a smart list drops the lists kept out of it. */
fun visibleIn(filter: TaskFilter, tasks: List<Task>): List<Task> =
if (filter is TaskFilter.Smart && hiddenFromSmartLists.isNotEmpty()) {
tasks.filter { it.listId !in hiddenFromSmartLists }
} else {
tasks
}
/**
* [tasks] as [filter] shows them: a smart list drops the lists kept out of it,
* and Upcoming whatever is due past [upcomingRange].
*/
fun visibleIn(
filter: TaskFilter,
tasks: List<Task>,
now: Instant = Clock.System.now(),
zone: ZoneId = ZoneId.systemDefault(),
): List<Task> {
if (filter !is TaskFilter.Smart) return tasks
val end = if (filter.list == SmartList.UPCOMING) upcomingRange.end(now, zone) else null
if (hiddenFromSmartLists.isEmpty() && end == null) return tasks
return tasks.filter { it.listId !in hiddenFromSmartLists && (end == null || dueBefore(it, end, zone)) }
}
/** The lead times for a task in [listId]: its override if set, else the global default. */
fun reminderLeadsFor(listId: Long): List<ReminderLead> =
@@ -202,6 +218,8 @@ class SettingsPrefs @Inject constructor(
?.mapNotNull { name -> runCatching { TaskSection.valueOf(name) }.getOrNull() }
?.toSet()
?: DEFAULT_COLLAPSED_SECTIONS,
upcomingRange = p[UPCOMING_RANGE]?.let { runCatching { UpcomingRange.valueOf(it) }.getOrNull() }
?: UpcomingRange.ALL,
)
}
@@ -210,6 +228,8 @@ class SettingsPrefs @Inject constructor(
p[COLLAPSED_SECTIONS] = if (collapsed) current + section.name else current - section.name
}
suspend fun setUpcomingRange(range: UpcomingRange) = dataStore.edit { it[UPCOMING_RANGE] = range.name }
suspend fun setSortOrder(order: TaskSortOrder) = dataStore.edit { it[SORT_ORDER] = order.name }
suspend fun setSnoozeMinutes(minutes: Int) = dataStore.edit { it[SNOOZE_MINUTES] = minutes.coerceAtLeast(1) }
@@ -372,6 +392,7 @@ class SettingsPrefs @Inject constructor(
val SMART_LIST_HIDDEN = stringSetPreferencesKey("smart_list_hidden")
val DEFAULT_START_TODAY = booleanPreferencesKey("default_start_today")
val COLLAPSED_SECTIONS = stringSetPreferencesKey("collapsed_sections")
val UPCOMING_RANGE = stringPreferencesKey("upcoming_range")
val SAVED_FILTERS = stringPreferencesKey("saved_filters")
val SAVED_FILTER_NEXT_ID = longPreferencesKey("saved_filter_next_id")
}
@@ -29,18 +29,22 @@ sealed interface TaskFilter {
*/
object TaskFiltering {
/** [saved] is the definition behind a [TaskFilter.Saved]; without one it matches nothing. */
/**
* [saved] is the definition behind a [TaskFilter.Saved]; without one it matches nothing.
* [upcomingEnd] caps Upcoming to dues before it (see [UpcomingRange.end]); `null` = no cap.
*/
fun matches(
task: Task,
filter: TaskFilter,
todayStart: Instant,
todayEnd: Instant,
saved: SavedFilter? = null,
upcomingEnd: Instant? = null,
): Boolean =
when (filter) {
is TaskFilter.OfList -> task.listId == filter.listId
is TaskFilter.OfLists -> task.listId in filter.listIds
is TaskFilter.Smart -> matchesSmart(task, filter.list, todayStart, todayEnd)
is TaskFilter.Smart -> matchesSmart(task, filter.list, todayStart, todayEnd, upcomingEnd)
is TaskFilter.Tagged -> filter.tag in task.tags
is TaskFilter.Saved -> saved?.takeIf { it.id == filter.id }?.matches(task, todayStart, todayEnd) ?: false
}
@@ -62,13 +66,20 @@ object TaskFiltering {
/** Whether [task] carries every one of [tags]; an empty set matches everything. */
fun hasAllTags(task: Task, tags: Set<String>): Boolean = task.tags.containsAll(tags)
private fun matchesSmart(task: Task, list: SmartList, todayStart: Instant, todayEnd: Instant): Boolean =
private fun matchesSmart(
task: Task,
list: SmartList,
todayStart: Instant,
todayEnd: Instant,
upcomingEnd: Instant?,
): Boolean =
when (list) {
SmartList.COMPLETED -> task.isCompleted
SmartList.ALL -> !task.isClosed
SmartList.NO_DATE -> !task.isClosed && dueWindowOf(task, todayStart, todayEnd) == DueWindow.NO_DATE
SmartList.OVERDUE -> !task.isClosed && dueWindowOf(task, todayStart, todayEnd) == DueWindow.OVERDUE
SmartList.TODAY -> isToday(task, todayStart, todayEnd)
SmartList.UPCOMING -> !task.isClosed && dueWindowOf(task, todayStart, todayEnd) == DueWindow.UPCOMING
SmartList.UPCOMING -> !task.isClosed && dueWindowOf(task, todayStart, todayEnd) == DueWindow.UPCOMING &&
(upcomingEnd == null || dueBefore(task, upcomingEnd))
}
}
@@ -0,0 +1,31 @@
package de.jeanlucmakiola.agendula.domain
import java.time.LocalDate
import java.time.ZoneId
import kotlin.time.Instant
/** How far ahead the Upcoming smart list reaches; [ALL] has no limit. */
enum class UpcomingRange {
ALL, WEEK, TWO_WEEKS, MONTH, THREE_MONTHS, YEAR;
/** The last day Upcoming shows when today is [today]; `null` for no limit. */
fun lastDay(today: LocalDate): LocalDate? = when (this) {
ALL -> null
WEEK -> today.plusWeeks(1)
TWO_WEEKS -> today.plusWeeks(2)
MONTH -> today.plusMonths(1)
THREE_MONTHS -> today.plusMonths(3)
YEAR -> today.plusYears(1)
}
/** Local midnight after [lastDay], the bound a due must fall before; `null` for no limit. */
fun end(now: Instant, zone: ZoneId = ZoneId.systemDefault()): Instant? {
val today = java.time.Instant.ofEpochMilli(now.toEpochMilliseconds()).atZone(zone).toLocalDate()
val last = lastDay(today) ?: return null
return Instant.fromEpochMilliseconds(last.plusDays(1).atStartOfDay(zone).toInstant().toEpochMilli())
}
}
/** Whether [task] is due before [end]; an undated task never is. */
fun dueBefore(task: Task, end: Instant, zone: ZoneId = ZoneId.systemDefault()): Boolean =
task.wallClock(task.due, zone)?.let { it < end } ?: false
@@ -15,6 +15,7 @@ import de.jeanlucmakiola.agendula.domain.Task
import de.jeanlucmakiola.agendula.domain.TaskFilter
import de.jeanlucmakiola.agendula.domain.TaskFiltering
import de.jeanlucmakiola.agendula.domain.TaskList
import de.jeanlucmakiola.agendula.domain.UpcomingRange
import de.jeanlucmakiola.agendula.domain.tagsInUse
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
@@ -141,10 +142,10 @@ class ListsViewModel @Inject constructor(
// Open smart lists drop completed tasks, but the Today ring needs the
// ones already ticked off to show "x of y done", so read them too.
repository.tasks(TaskFilter.Smart(SmartList.COMPLETED)),
settingsPrefs.settings.map { it.hiddenFromSmartLists }.distinctUntilChanged(),
settingsPrefs.settings.map { it.hiddenFromSmartLists to it.upcomingRange }.distinctUntilChanged(),
settingsPrefs.savedFilters,
) { lists, openTasks, completedTasks, hidden, filters ->
buildContent(lists, openTasks, completedTasks, hidden, filters) as ListsUiState
) { lists, openTasks, completedTasks, (hidden, upcomingRange), filters ->
buildContent(lists, openTasks, completedTasks, hidden, upcomingRange, filters) as ListsUiState
}.recoveringFromProviderFailure { ListsUiState.Failure }
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), ListsUiState.Loading)
@@ -153,17 +154,22 @@ class ListsViewModel @Inject constructor(
openTasks: List<Task>,
completedTasks: List<Task>,
hidden: Set<Long>,
upcomingRange: UpcomingRange,
savedFilters: List<SavedFilter>,
): ListsUiState.Content {
val (todayStart, todayEnd) = DayWindow.today(Clock.System.now(), ZoneId.systemDefault())
val now = Clock.System.now()
val zone = ZoneId.systemDefault()
val (todayStart, todayEnd) = DayWindow.today(now, zone)
// Count only top-level tasks: a subtask is represented by its parent (and
// its progress chip), and an open subtask under a *completed* parent must
// not read as an open item here. Mirrors the task list collapsing subtasks.
val topLevel = openTasks.filter { !it.isSubtask }
// The smart counts leave out the hidden lists; each list's own count does not.
val smartTopLevel = topLevel.filter { it.listId !in hidden }
fun count(smart: SmartList) =
smartTopLevel.count { TaskFiltering.matches(it, TaskFilter.Smart(smart), todayStart, todayEnd) }
val upcomingEnd = upcomingRange.end(now, zone)
fun inSmart(task: Task, smart: SmartList) =
TaskFiltering.matches(task, TaskFilter.Smart(smart), todayStart, todayEnd, upcomingEnd = upcomingEnd)
fun count(smart: SmartList) = smartTopLevel.count { inSmart(it, smart) }
val smartCounts = listOf(
SmartCount(SmartList.TODAY, count(SmartList.TODAY)),
@@ -182,7 +188,7 @@ class ListsViewModel @Inject constructor(
// Upcoming preview: the next handful of open tasks due tomorrow onward,
// already sorted by the repository's default ordering.
val upcoming = smartTopLevel
.filter { TaskFiltering.matches(it, TaskFilter.Smart(SmartList.UPCOMING), todayStart, todayEnd) }
.filter { inSmart(it, SmartList.UPCOMING) }
.take(UPCOMING_PREVIEW)
val openByList = topLevel.groupingBy { it.listId }.eachCount()
val groups = lists
@@ -71,6 +71,7 @@ import androidx.compose.material3.SwipeToDismissBox
import androidx.compose.ui.res.pluralStringResource
import de.jeanlucmakiola.agendula.domain.TaskEnd
import de.jeanlucmakiola.agendula.domain.TaskSortOrder
import de.jeanlucmakiola.agendula.domain.UpcomingRange
import de.jeanlucmakiola.floret.components.revealOnFocus
import de.jeanlucmakiola.floret.components.InlineTextField
import de.jeanlucmakiola.floret.components.FullScreenPicker
@@ -209,7 +210,8 @@ fun TaskListScreen(
},
actions = {
IconButton(onClick = { showSort = true }, enabled = content != null) {
BadgedBox(badge = { if (content?.selectedTags?.isNotEmpty() == true) Badge() }) {
val narrowed = content?.selectedTags?.isNotEmpty() == true || content?.upcomingLimited == true
BadgedBox(badge = { if (narrowed) Badge() }) {
Icon(Icons.Rounded.Tune, contentDescription = stringResource(R.string.view_options_title))
}
}
@@ -314,6 +316,8 @@ fun TaskListScreen(
if (showSort && content != null) {
ViewOptionsPicker(
sortOrder = content.sortOrder,
upcomingRange = content.upcomingRange.takeIf { filter == TaskFilter.Smart(SmartList.UPCOMING) },
onUpcomingRange = viewModel::setUpcomingRange,
tags = content.availableTags,
selectedTags = content.selectedTags,
onSortOrder = viewModel::setSortOrder,
@@ -434,7 +438,12 @@ private fun TaskListBody(
),
) {
if (state.tasks.isEmpty()) {
item(key = "empty") { EmptyState(stringResource(R.string.task_list_empty)) }
val empty = if (state.hiddenByRange && state.selectedTags.isEmpty()) {
R.string.upcoming_range_empty
} else {
R.string.task_list_empty
}
item(key = "empty") { EmptyState(stringResource(empty)) }
}
sections.forEach { section ->
@@ -1231,10 +1240,13 @@ private fun CenteredMessage(text: String, inner: PaddingValues) {
/**
* Sort and tag filter in one place. Stays open while choosing, since several
* tags can be ticked; back leaves. A task must carry every ticked tag.
* [upcomingRange] is set only in Upcoming, which then offers how far it reaches.
*/
@Composable
private fun ViewOptionsPicker(
sortOrder: TaskSortOrder,
upcomingRange: UpcomingRange?,
onUpcomingRange: (UpcomingRange) -> Unit,
tags: List<String>,
selectedTags: Set<String>,
onSortOrder: (TaskSortOrder) -> Unit,
@@ -1262,6 +1274,20 @@ private fun ViewOptionsPicker(
onClick = { onSortOrder(order) },
)
}
if (upcomingRange != null) {
Spacer(Modifier.height(8.dp))
GroupedSectionHeader(stringResource(R.string.upcoming_range_title))
UpcomingRange.entries.forEachIndexed { index, range ->
val isSelected = range == upcomingRange
GroupedRow(
title = stringResource(upcomingRangeLabel(range)),
position = positionOf(index, UpcomingRange.entries.size),
selected = isSelected,
trailing = if (isSelected) ({ SelectedCheck() }) else null,
onClick = { onUpcomingRange(range) },
)
}
}
if (tags.isNotEmpty()) {
Spacer(Modifier.height(8.dp))
GroupedSectionHeader(stringResource(R.string.view_filter_tags))
@@ -1280,6 +1306,15 @@ private fun ViewOptionsPicker(
}
}
private fun upcomingRangeLabel(range: UpcomingRange): Int = when (range) {
UpcomingRange.ALL -> R.string.upcoming_range_all
UpcomingRange.WEEK -> R.string.upcoming_range_week
UpcomingRange.TWO_WEEKS -> R.string.upcoming_range_two_weeks
UpcomingRange.MONTH -> R.string.upcoming_range_month
UpcomingRange.THREE_MONTHS -> R.string.upcoming_range_three_months
UpcomingRange.YEAR -> R.string.upcoming_range_year
}
@Composable
private fun titleFor(filter: TaskFilter, name: String?): String = when (filter) {
is TaskFilter.OfList -> name ?: stringResource(R.string.tasks_title)
@@ -9,6 +9,7 @@ import de.jeanlucmakiola.agendula.data.sync.RemoteLists
import de.jeanlucmakiola.agendula.data.tasks.TasksRepository
import de.jeanlucmakiola.agendula.data.tasks.recoveringFromProviderFailure
import de.jeanlucmakiola.agendula.domain.SavedFilter
import de.jeanlucmakiola.agendula.domain.SmartList
import de.jeanlucmakiola.agendula.domain.Task
import de.jeanlucmakiola.agendula.domain.TaskFilter
import de.jeanlucmakiola.agendula.domain.TaskFiltering
@@ -17,6 +18,8 @@ import de.jeanlucmakiola.agendula.domain.TaskForm
import de.jeanlucmakiola.agendula.domain.TaskList
import de.jeanlucmakiola.agendula.domain.TaskSection
import de.jeanlucmakiola.agendula.domain.TaskSortOrder
import de.jeanlucmakiola.agendula.domain.UpcomingRange
import de.jeanlucmakiola.agendula.widget.TaskWidgetUpdater
import de.jeanlucmakiola.agendula.domain.comparator
import de.jeanlucmakiola.agendula.ui.lists.ListWriteFailure
import de.jeanlucmakiola.agendula.ui.lists.asFailure
@@ -41,6 +44,7 @@ import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import javax.inject.Inject
import kotlin.time.Clock
sealed interface TaskListUiState {
data object Loading : TaskListUiState
@@ -59,6 +63,9 @@ sealed interface TaskListUiState {
/** Whether a real list uses the bottom quick-add bar instead of the FAB. */
val bottomAddBar: Boolean = false,
val sortOrder: TaskSortOrder = TaskSortOrder.DUE,
val upcomingRange: UpcomingRange = UpcomingRange.ALL,
/** Upcoming's time frame is hiding tasks due further ahead. */
val hiddenByRange: Boolean = false,
/** Sections whose rows are folded under their header. */
val collapsedSections: Set<TaskSection> = DEFAULT_COLLAPSED_SECTIONS,
/** This real list is kept out of the smart lists. */
@@ -71,7 +78,11 @@ sealed interface TaskListUiState {
val savedFilter: SavedFilter? = null,
/** The filter this content was built for; a reused screen briefly holds the previous one's. */
val filter: TaskFilter? = null,
) : TaskListUiState
) : TaskListUiState {
/** Upcoming, narrowed to a time frame the user picked. */
val upcomingLimited: Boolean
get() = filter == TaskFilter.Smart(SmartList.UPCOMING) && upcomingRange != UpcomingRange.ALL
}
}
/**
@@ -95,6 +106,7 @@ class TaskListViewModel @Inject constructor(
private val settingsPrefs: SettingsPrefs,
private val remoteLists: RemoteLists,
private val manualSync: ManualSync,
private val widgetUpdater: TaskWidgetUpdater,
@ApplicationScope private val appScope: CoroutineScope,
) : ViewModel() {
@@ -141,7 +153,11 @@ class TaskListViewModel @Inject constructor(
// and fold in the live UI settings (add-subtask row, bottom add bar).
combine(content, pendingDeletes, settingsPrefs.settings, tagFilter) { st, pending, settings, tags ->
if (st is TaskListUiState.Content) {
val visible = settings.visibleIn(f, st.tasks).filter { it.occurrenceKey !in pending }
val now = Clock.System.now()
val inView = settings.visibleIn(f, st.tasks, now)
val hiddenByRange = settings.upcomingRange != UpcomingRange.ALL &&
settings.copy(upcomingRange = UpcomingRange.ALL).visibleIn(f, st.tasks, now).size > inView.size
val visible = inView.filter { it.occurrenceKey !in pending }
val available = tagsInUse(visible) - setOfNotNull((f as? TaskFilter.Tagged)?.tag)
// A tag that vanished can no longer be unticked, so it is dropped
// for good rather than narrowing again when it comes back.
@@ -157,6 +173,8 @@ class TaskListViewModel @Inject constructor(
showAddSubtaskRow = settings.showAddSubtaskRow,
bottomAddBar = settings.bottomAddBar,
sortOrder = settings.sortOrder,
upcomingRange = settings.upcomingRange,
hiddenByRange = hiddenByRange,
collapsedSections = settings.collapsedSections,
hiddenFromSmartLists = st.list?.id?.let { it in settings.hiddenFromSmartLists } ?: false,
)
@@ -296,6 +314,11 @@ class TaskListViewModel @Inject constructor(
fun setSortOrder(order: TaskSortOrder) = viewModelScope.launch { settingsPrefs.setSortOrder(order) }
fun setUpcomingRange(range: UpcomingRange) = viewModelScope.launch {
settingsPrefs.setUpcomingRange(range)
widgetUpdater.requestRefresh()
}
/**
* Deletes every completed task in [listId]. A completed occurrence goes on its
* own, a series that is closed as a whole goes whole, and a parent that still
+8
View File
@@ -42,6 +42,14 @@
<string name="sort_title">Sort by</string>
<string name="view_options_title">Sort and filter</string>
<string name="view_filter_tags">Filter by tag</string>
<string name="upcoming_range_title">Show tasks due within</string>
<string name="upcoming_range_all">Any time</string>
<string name="upcoming_range_week">The next week</string>
<string name="upcoming_range_two_weeks">The next 2 weeks</string>
<string name="upcoming_range_month">The next month</string>
<string name="upcoming_range_three_months">The next 3 months</string>
<string name="upcoming_range_year">The next year</string>
<string name="upcoming_range_empty">Nothing due in this time frame. Widen it in the view options.</string>
<string name="view_filter_clear">Clear filter</string>
<string name="sort_due">Due date</string>
<string name="sort_priority">Priority</string>
@@ -3,8 +3,11 @@ package de.jeanlucmakiola.agendula.data.prefs
import com.google.common.truth.Truth.assertThat
import de.jeanlucmakiola.agendula.domain.SmartList
import de.jeanlucmakiola.agendula.domain.TaskFilter
import de.jeanlucmakiola.agendula.domain.UpcomingRange
import de.jeanlucmakiola.agendula.domain.testTask
import org.junit.jupiter.api.Test
import java.time.ZoneId
import kotlin.time.Instant
class SettingsVisibilityTest {
@@ -20,4 +23,17 @@ class SettingsVisibilityTest {
fun `the hidden list still shows its own tasks`() {
assertThat(settings.visibleIn(TaskFilter.OfList(2), tasks)).isEqualTo(tasks)
}
@Test
fun `upcoming leaves out what is due past its range`() {
val zone = ZoneId.of("UTC")
val dayMs = 86_400_000L
val now = Instant.fromEpochMilliseconds(1000 * dayMs)
val near = testTask(id = 1, due = Instant.fromEpochMilliseconds(1005 * dayMs))
val far = testTask(id = 2, due = Instant.fromEpochMilliseconds(1100 * dayMs))
val limited = Settings(upcomingRange = UpcomingRange.TWO_WEEKS)
val upcoming = limited.visibleIn(TaskFilter.Smart(SmartList.UPCOMING), listOf(near, far), now, zone)
assertThat(upcoming.map { it.taskId }).containsExactly(1L)
assertThat(limited.visibleIn(TaskFilter.Smart(SmartList.ALL), listOf(near, far), now, zone)).hasSize(2)
}
}
@@ -1,7 +1,10 @@
package de.jeanlucmakiola.agendula.domain
import com.google.common.truth.Truth.assertThat
import de.jeanlucmakiola.floret.time.DayWindow
import org.junit.jupiter.api.Test
import java.time.LocalDate
import java.time.ZoneId
import kotlin.time.Instant
class TaskFilteringTest {
@@ -36,6 +39,33 @@ class TaskFilteringTest {
assertThat(matches(task, SmartList.TODAY)).isFalse()
}
@Test
fun `upcoming stops short of its end`() {
val end = at(1015 * dayMs)
fun inUpcoming(task: Task) =
TaskFiltering.matches(task, TaskFilter.Smart(SmartList.UPCOMING), todayStart, todayEnd, upcomingEnd = end)
assertThat(inUpcoming(testTask(due = at(1015 * dayMs - 1)))).isTrue()
assertThat(inUpcoming(testTask(due = at(1015 * dayMs)))).isFalse()
val farOff = testTask(due = at(1100 * dayMs))
assertThat(TaskFiltering.matches(farOff, TaskFilter.Smart(SmartList.ALL), todayStart, todayEnd, upcomingEnd = end)).isTrue()
}
@Test
fun `an all-day due on the range's last day stays in upcoming`() {
val zone = ZoneId.systemDefault()
val today = LocalDate.of(2026, 3, 10)
val (start, end) = DayWindow.today(
Instant.fromEpochMilliseconds(today.atTime(9, 0).atZone(zone).toInstant().toEpochMilli()),
zone,
)
val upcomingEnd = UpcomingRange.WEEK.end(start, zone)
fun dueOn(date: LocalDate) = testTask(due = allDayInstantOf(date), isAllDay = true)
fun inUpcoming(task: Task) =
TaskFiltering.matches(task, TaskFilter.Smart(SmartList.UPCOMING), start, end, upcomingEnd = upcomingEnd)
assertThat(inUpcoming(dueOn(today.plusDays(7)))).isTrue()
assertThat(inUpcoming(dueOn(today.plusDays(8)))).isFalse()
}
@Test
fun `no-date is open without a due`() {
val task = testTask(due = null)
@@ -0,0 +1,36 @@
package de.jeanlucmakiola.agendula.domain
import com.google.common.truth.Truth.assertThat
import org.junit.jupiter.api.Test
import java.time.LocalDate
import java.time.ZoneId
import kotlin.time.Instant
class UpcomingRangeTest {
private val zone = ZoneId.of("Europe/Berlin")
private val today = LocalDate.of(2026, 3, 10)
private val now = at(today, hour = 9)
private fun at(date: LocalDate, hour: Int = 0): Instant =
Instant.fromEpochMilliseconds(date.atTime(hour, 0).atZone(zone).toInstant().toEpochMilli())
@Test
fun `all has no end`() {
assertThat(UpcomingRange.ALL.lastDay(today)).isNull()
assertThat(UpcomingRange.ALL.end(now, zone)).isNull()
}
@Test
fun `the end is local midnight after the last day`() {
assertThat(UpcomingRange.TWO_WEEKS.end(now, zone)).isEqualTo(at(today.plusDays(15)))
assertThat(UpcomingRange.WEEK.end(now, zone)).isEqualTo(at(today.plusDays(8)))
}
@Test
fun `months follow the calendar`() {
assertThat(UpcomingRange.MONTH.lastDay(LocalDate.of(2026, 1, 31))).isEqualTo(LocalDate.of(2026, 2, 28))
assertThat(UpcomingRange.THREE_MONTHS.lastDay(today)).isEqualTo(LocalDate.of(2026, 6, 10))
assertThat(UpcomingRange.YEAR.lastDay(today)).isEqualTo(LocalDate.of(2027, 3, 10))
}
}