diff --git a/opentasks-provider/src/androidTest/java/org/dmfs/provider/tasks/TaskProviderRecurrenceTest.java b/opentasks-provider/src/androidTest/java/org/dmfs/provider/tasks/TaskProviderRecurrenceTest.java index 7032cbfb0..ffe5f29af 100644 --- a/opentasks-provider/src/androidTest/java/org/dmfs/provider/tasks/TaskProviderRecurrenceTest.java +++ b/opentasks-provider/src/androidTest/java/org/dmfs/provider/tasks/TaskProviderRecurrenceTest.java @@ -200,6 +200,70 @@ public void testRRule() throws InvalidRecurrenceRuleException } + + /** + * Test if instances of a task with an all-day DTSTART, DUE and an RRULE. + */ + @Test + public void testAllDayRRule() throws InvalidRecurrenceRuleException + { + RowSnapshot taskList = new VirtualRowSnapshot<>(new LocalTaskListsTable(mAuthority)); + Table instancesTable = new InstanceTable(mAuthority); + RowSnapshot task = new VirtualRowSnapshot<>(new TaskListScoped(taskList, new TasksTable(mAuthority))); + + Duration days = new Duration(1, 2, 0); + DateTime start = DateTime.parse("20180104"); + DateTime due = start.addDuration(days); + DateTime localStart = start; + + Duration day = new Duration(1, 1, 0); + + DateTime second = localStart.addDuration(day); + DateTime third = second.addDuration(day); + DateTime fourth = third.addDuration(day); + DateTime fifth = fourth.addDuration(day); + + DateTime localDue = due; + + assertThat(new Seq<>( + new Put<>(taskList, new EmptyRowData<>()), + new Put<>(task, + new Composite<>( + new TimeData<>(start, due), + new RRuleTaskData(new RecurrenceRule("FREQ=DAILY;COUNT=5", RecurrenceRule.RfcMode.RFC2445_LAX)))) + + ), resultsIn(mClient, + new Assert<>(task, + new Composite<>( + new TimeData<>(start, due), + new CharSequenceRowData<>(Tasks.RRULE, "FREQ=DAILY;COUNT=5"))), +// new Counted<>(5, new AssertRelated<>(instancesTable, Instances.TASK_ID, task)), + new Counted<>(1, new AssertRelated<>(instancesTable, Instances.TASK_ID, task)), + // 1st instance: + new AssertRelated<>(instancesTable, Instances.TASK_ID, task, + new InstanceTestData(localStart, localDue, new Present<>(start), 0), + new EqArg(Instances.INSTANCE_ORIGINAL_TIME, start.getTimestamp()))/*, + // 2nd instance: + new AssertRelated<>(instancesTable, Instances.TASK_ID, task, + new InstanceTestData(second, second.addDuration(hour), new Present<>(second), 1), + new EqArg(Instances.INSTANCE_ORIGINAL_TIME, second.getTimestamp())), + // 3rd instance: + new AssertRelated<>(instancesTable, Instances.TASK_ID, task, + new InstanceTestData(third, third.addDuration(hour), new Present<>(third), 2), + new EqArg(Instances.INSTANCE_ORIGINAL_TIME, third.getTimestamp())), + // 4th instance: + new AssertRelated<>(instancesTable, Instances.TASK_ID, task, + new InstanceTestData(fourth, fourth.addDuration(hour), new Present<>(fourth), 3), + new EqArg(Instances.INSTANCE_ORIGINAL_TIME, fourth.getTimestamp())), + // 5th instance: + new AssertRelated<>(instancesTable, Instances.TASK_ID, task, + new InstanceTestData(fifth, fifth.addDuration(hour), new Present<>(fifth), 4), + new EqArg(Instances.INSTANCE_ORIGINAL_TIME, fifth.getTimestamp())) */) + ); + } + + + /** * Test if instances of a task with a DUE and an RRULE but no DTSTART. */ diff --git a/opentasks-provider/src/androidTest/java/org/dmfs/provider/tasks/TaskProviderTest.java b/opentasks-provider/src/androidTest/java/org/dmfs/provider/tasks/TaskProviderTest.java index e75914451..911f43d53 100644 --- a/opentasks-provider/src/androidTest/java/org/dmfs/provider/tasks/TaskProviderTest.java +++ b/opentasks-provider/src/androidTest/java/org/dmfs/provider/tasks/TaskProviderTest.java @@ -335,6 +335,40 @@ public void testInsertTaskWithStartAndDue() } + + /** + * Create task with start and due, check datetime values including generated duration. + */ + @Test + public void testInsertTaskWithAlldayStartAndDue() + { + RowSnapshot taskList = new VirtualRowSnapshot<>(new LocalTaskListsTable(mAuthority)); + RowSnapshot task = new VirtualRowSnapshot<>(new TaskListScoped(taskList, new TasksTable(mAuthority))); + + DateTime start = DateTime.now().toAllDay(); + DateTime due = start.addDuration(new Duration(1, 2, 0)); + + assertThat(new Seq<>( + new Put<>(taskList, new EmptyRowData()), + new Put<>(task, new TimeData<>(start, due)) + + ), resultsIn(mClient, + new Assert<>(task, new Composite<>( + new TimeData<>(start, due), + new VersionData(0))), + new AssertRelated<>( + new InstanceTable(mAuthority), Instances.TASK_ID, task, + new Composite( + new InstanceTestData( + start, + due, + absent(), + 0), + new CharSequenceRowData<>(Tasks.TZ, "UTC")) + ))); + } + + /** * Create task with start and due, check datetime and INSTANCE_STATUS values after updating the status. */ diff --git a/opentasks-provider/src/main/java/org/dmfs/provider/tasks/utils/InstanceValuesIterable.java b/opentasks-provider/src/main/java/org/dmfs/provider/tasks/utils/InstanceValuesIterable.java index f8317d8fe..3613a83f0 100644 --- a/opentasks-provider/src/main/java/org/dmfs/provider/tasks/utils/InstanceValuesIterable.java +++ b/opentasks-provider/src/main/java/org/dmfs/provider/tasks/utils/InstanceValuesIterable.java @@ -91,7 +91,7 @@ public Iterator> iterator() return new Mapped<>(dateTime -> new Distant(mTaskAdapter.valueOf(TaskAdapter.IS_CLOSED) ? -1 : 0, new Overridden(new Present<>(dateTime), - new Enduring(new DueDated(new Zipped<>(new Present<>(dateTime), effectiveDuration, DateTime::addDuration), + new Enduring(new DueDated(new Zipped<>(new Present<>(dateTime), effectiveDuration, this::addDuration), new StartDated(new Present<>(dateTime), new VanillaInstanceData()))))), new TaskInstanceIterable(mTaskAdapter).iterator()); } @@ -104,4 +104,14 @@ public Iterator> iterator() } + + private DateTime addDuration(DateTime dt, Duration dur) + { + if (dt.isAllDay() && dur.getSecondsOfDay() != 0) + { + dur = new Duration(1, dur.getWeeks() * 7 + dur.getDays() + dur.getSecondsOfDay() / (3600 * 24), 0); + } + return dt.addDuration(dur); + } + }