mirror of https://github.com/tasks/tasks
Replace hidden and completed eq with lte
parent
6e8587875f
commit
ddf9ccdf5d
@ -0,0 +1,42 @@
|
||||
package org.tasks.db;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.tasks.db.QueryUtils.showCompleted;
|
||||
import static org.tasks.db.QueryUtils.showHidden;
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import com.todoroo.andlib.sql.Functions;
|
||||
import com.todoroo.astrid.data.Task;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class QueryUtilsTest {
|
||||
@Test
|
||||
public void replaceHiddenLT() {
|
||||
assertEquals(
|
||||
"(1)",
|
||||
showHidden(Task.HIDE_UNTIL.lt(Functions.now()).toString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void replaceHiddenLTE() {
|
||||
assertEquals(
|
||||
"(1)",
|
||||
showHidden(Task.HIDE_UNTIL.lte(Functions.now()).toString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void replaceUncompletedEQ() {
|
||||
assertEquals(
|
||||
"(1)",
|
||||
showCompleted(Task.COMPLETION_DATE.eq(0).toString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void replaceUncompletedLTE() {
|
||||
assertEquals(
|
||||
"(1)",
|
||||
showCompleted(Task.COMPLETION_DATE.lte(0).toString()));
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package org.tasks.db;
|
||||
|
||||
import com.todoroo.andlib.sql.Criterion;
|
||||
import com.todoroo.andlib.utility.DateUtilities;
|
||||
import com.todoroo.astrid.data.Task;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class QueryUtils {
|
||||
|
||||
private static final Pattern HIDDEN =
|
||||
Pattern.compile("tasks\\.hideUntil<=?\\(strftime\\('%s','now'\\)\\*1000\\)");
|
||||
|
||||
private static final Pattern UNCOMPLETED = Pattern.compile("tasks\\.completed<?=0");
|
||||
|
||||
public static String showHidden(String query) {
|
||||
return HIDDEN.matcher(query).replaceAll("1");
|
||||
}
|
||||
|
||||
public static String showCompleted(String query) {
|
||||
return UNCOMPLETED.matcher(query).replaceAll("1");
|
||||
}
|
||||
|
||||
public static String showHiddenAndCompleted(String query) {
|
||||
return showCompleted(showHidden(query));
|
||||
}
|
||||
|
||||
public static String showRecentlyCompleted(String query) {
|
||||
return UNCOMPLETED
|
||||
.matcher(query)
|
||||
.replaceAll(
|
||||
Criterion.or(
|
||||
Task.COMPLETION_DATE.lte(0),
|
||||
Task.COMPLETION_DATE.gte(DateUtilities.now() - 59999))
|
||||
.toString());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue