Assume tasks without specified due time to be due at midnight at the end of day

Close #1403
This commit is contained in:
MM20 2025-05-03 20:22:12 +02:00
parent 06095a75ab
commit 2267fac67f
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389

View File

@ -9,6 +9,8 @@ import de.mm20.launcher2.search.CalendarEvent
import de.mm20.launcher2.search.calendar.CalendarListType import de.mm20.launcher2.search.calendar.CalendarListType
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import java.time.Instant
import java.time.ZoneId
internal class TasksCalendarProvider( internal class TasksCalendarProvider(
private val context: Context, private val context: Context,
@ -22,10 +24,17 @@ internal class TasksCalendarProvider(
allowNetwork: Boolean allowNetwork: Boolean
): List<CalendarEvent> { ): List<CalendarEvent> {
return withContext(Dispatchers.IO) { return withContext(Dispatchers.IO) {
val startOfDay = Instant.ofEpochMilli(from)
.atZone(ZoneId.systemDefault())
.withHour(0)
.withMinute(0)
.withSecond(0)
.withNano(0)
.toInstant().toEpochMilli()
queryTasks( queryTasks(
selection = buildList { selection = buildList {
add("($to >= hideUntil OR hideUntil IS NULL)") add("($to >= hideUntil OR hideUntil IS NULL)")
add("$from <= dueDate") add("($from <= dueDate OR ($startOfDay <= dueDate AND dueDate % 60000 <= 0))")
if (excludedCalendars.isNotEmpty()) { if (excludedCalendars.isNotEmpty()) {
add("cdl_id NOT IN (${excludedCalendars.joinToString()})") add("cdl_id NOT IN (${excludedCalendars.joinToString()})")
} }
@ -62,7 +71,8 @@ internal class TasksCalendarProvider(
color = cursor.getIntOrNull(colorIndex) ?: 0, color = cursor.getIntOrNull(colorIndex) ?: 0,
types = listOf(CalendarListType.Tasks), types = listOf(CalendarListType.Tasks),
providerId = "tasks.org", providerId = "tasks.org",
owner = cursor.getStringOrNull(accountIndex)?.substringAfter(":", "")?.takeIf { it.isNotBlank() }, owner = cursor.getStringOrNull(accountIndex)?.substringAfter(":", "")
?.takeIf { it.isNotBlank() },
) )
} }
} }
@ -94,6 +104,22 @@ internal class TasksCalendarProvider(
val id = cursor.getLongOrNull(idIndex) ?: continue val id = cursor.getLongOrNull(idIndex) ?: continue
val dueDate = cursor.getLongOrNull(dueIndex)?.takeIf { it > 0L } ?: continue val dueDate = cursor.getLongOrNull(dueIndex)?.takeIf { it > 0L } ?: continue
// https://github.com/tasks/tasks/blob/13d4c029e855fd32ec91e4d4ec5f740ec506136e/data/src/commonMain/kotlin/org/tasks/data/entity/Task.kt#L345
val isAllDay = dueDate % 60000 <= 0
val endTime = if (isAllDay) {
Instant.ofEpochMilli(dueDate)
.atZone(ZoneId.systemDefault())
.withHour(23)
.withMinute(59)
.withSecond(59)
.withNano(999_999_999)
.toInstant()
.toEpochMilli()
} else {
dueDate
}
results += TasksCalendarEvent( results += TasksCalendarEvent(
id = id, id = id,
label = cursor.getStringOrNull(titleIndex) ?: continue, label = cursor.getStringOrNull(titleIndex) ?: continue,
@ -101,8 +127,8 @@ internal class TasksCalendarProvider(
color = cursor.getIntOrNull(colorIndex), color = cursor.getIntOrNull(colorIndex),
calendarName = cursor.getStringOrNull(calendarNameIndex), calendarName = cursor.getStringOrNull(calendarNameIndex),
startTime = cursor.getLongOrNull(startIndex)?.takeIf { it > 0L }, startTime = cursor.getLongOrNull(startIndex)?.takeIf { it > 0L },
endTime = dueDate, endTime = endTime,
allDay = dueDate % 60000 <= 0, // https://github.com/tasks/tasks/blob/13d4c029e855fd32ec91e4d4ec5f740ec506136e/data/src/commonMain/kotlin/org/tasks/data/entity/Task.kt#L345 allDay = isAllDay,
isCompleted = (cursor.getLongOrNull(completedIndex) ?: 0L) != 0L, isCompleted = (cursor.getLongOrNull(completedIndex) ?: 0L) != 0L,
) )
} }