Java Code Examples for org.dmfs.rfc5545.DateTime#shiftTimeZone()

The following examples show how to use org.dmfs.rfc5545.DateTime#shiftTimeZone() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TimeDataTest.java    From opentasks with Apache License 2.0 6 votes vote down vote up
@Test
public void test_whenStartHasDifferentTimeZoneFromDue_shiftsStartsToDue()
{
    DateTime start = DateTime.now().swapTimeZone(TimeZone.getTimeZone("GMT+3"));
    DateTime due = start.addDuration(new Duration(1, 3, 0)).swapTimeZone(TimeZone.getTimeZone("GMT+6"));

    DateTime startExpected = start.shiftTimeZone(TimeZone.getTimeZone("GMT+6"));

    assertThat(new TimeData<>(start, due),
            builds(
                    withValuesOnly(
                            containing(Tasks.DTSTART, startExpected.getTimestamp()),
                            containing(Tasks.TZ, "GMT+06:00"),
                            containing(Tasks.IS_ALLDAY, 0),
                            containing(Tasks.DUE, due.getTimestamp()),
                            withNullValue(Tasks.DURATION)
                    )));
}
 
Example 2
Source File: UntilLimiter.java    From lib-recur with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new limiter for the UNTIL part.
 *
 * @param rule
 *         The {@link RecurrenceRule} to filter.
 * @param previous
 *         The previous filter instance.
 * @param start
 *         The first instance. This is used to determine if the iterated instances are floating or not.
 */
public UntilLimiter(RecurrenceRule rule, RuleIterator previous, CalendarMetrics calendarMetrics, TimeZone startTimezone)
{
    super(previous);
    DateTime until = rule.getUntil();
    if (!until.isFloating())
    {
        until = until.shiftTimeZone(startTimezone);
    }
    mUntil = until.getInstance();
}
 
Example 3
Source File: DateTimeArrayFieldAdapter.java    From opentasks-provider with Apache License 2.0 5 votes vote down vote up
@Override
public void setIn(ContentValues values, DateTime[] value)
{
	if (value != null && value.length > 0)
	{
		try
		{
			// Note: we only store the datetime strings, not the timezone
			StringBuilder result = new StringBuilder(value.length * 17 /* this is the maximum length */);

			boolean first = true;
			for (DateTime datetime : value)
			{
				if (first)
				{
					first = false;
				}
				else
				{
					result.append(',');
				}
				DateTime outvalue = datetime.isFloating() ? datetime : datetime.shiftTimeZone(DateTime.UTC);
				outvalue.writeTo(result);
			}
			values.put(mDateTimeListFieldName, result.toString());
		}
		catch (IOException e)
		{
			throw new RuntimeException("Can not serialize datetime list.");
		}

	}
	else
	{
		values.put(mDateTimeListFieldName, (Long) null);
	}
}
 
Example 4
Source File: RecurrenceRuleIterator.java    From lib-recur with Apache License 2.0 5 votes vote down vote up
/**
 * Skip all instances up to a specific date. <p> <strong>Note:</strong> After calling this method you should call {@link #hasNext()} before you continue
 * because there might no more instances left if there is an UNTIL or COUNT part in the rule. </p>
 *
 * @param until
 *         The earliest date to be returned by the next call to {@link #nextMillis()} or {@link #nextDateTime()}.
 */
public void fastForward(DateTime until)
{
    if (!hasNext())
    {
        return;
    }

    DateTime untilDate = until.shiftTimeZone(mTimeZone);

    // convert until to an instance
    long untilInstance = untilDate.getInstance();

    long next = Instance.maskWeekday(mNextInstance);
    if (untilInstance <= next)
    {
        // nothing to do
        return;
    }

    RuleIterator iterator = mRuleIterator;
    iterator.fastForward(untilInstance);

    while (next != Long.MIN_VALUE && next < untilInstance)
    {
        next = iterator.next();
    }

    mNextInstance = next;

    // invalidate mNextMillis
    mNextMillis = Long.MIN_VALUE;
    mNextDateTime = null;
}
 
Example 5
Source File: TaskProviderTest.java    From opentasks with Apache License 2.0 5 votes vote down vote up
/**
 * Create task with start and duration, check datetime values including generated due.
 */
@Test
public void testInsertWithStartAndDurationChangeTimeZone()
{
    RowSnapshot<TaskLists> taskList = new VirtualRowSnapshot<>(new LocalTaskListsTable(mAuthority));
    RowSnapshot<Tasks> task = new VirtualRowSnapshot<>(new TaskListScoped(taskList, new TasksTable(mAuthority)));

    DateTime start = DateTime.now();
    Duration duration = Duration.parse("PT1H");
    long durationMillis = duration.toMillis();
    DateTime startNew = start.shiftTimeZone(TimeZone.getTimeZone("America/New_York"));

    assertThat(new Seq<>(
            new Put<>(taskList, new EmptyRowData<TaskLists>()),
            new Put<>(task, new TimeData<>(start, duration)),
            // update the task with a the same start in a different time zone
            new Put<>(task, new TimeData<>(startNew, duration))

    ), resultsIn(mClient,
            new Assert<>(task, new Composite<>(
                    new TimeData<>(startNew, duration),
                    new VersionData(1))),
            // note that, apart from the time zone, all values stay the same
            new AssertRelated<>(
                    new InstanceTable(mAuthority), Instances.TASK_ID, task,
                    new Composite<Instances>(
                            new InstanceTestData(
                                    start.shiftTimeZone(TimeZone.getDefault()),
                                    start.shiftTimeZone(TimeZone.getDefault()).addDuration(duration),
                                    absent(),
                                    0),
                            new CharSequenceRowData<>(Tasks.TZ, "America/New_York"))
            )));
}
 
Example 6
Source File: TaskProviderRecurrenceTest.java    From opentasks with Apache License 2.0 4 votes vote down vote up
/**
     * Test if instances of a task with a DTSTART and RDATEs.
     */
    @Test
    public void testRDate() throws InvalidRecurrenceRuleException
    {
        RowSnapshot<TaskLists> taskList = new VirtualRowSnapshot<>(new LocalTaskListsTable(mAuthority));
        Table<Instances> instancesTable = new InstanceTable(mAuthority);
        RowSnapshot<Tasks> task = new VirtualRowSnapshot<>(new TaskListScoped(taskList, new TasksTable(mAuthority)));

        Duration hour = new Duration(1, 0, 3600 /* 1 hour */);
        DateTime start = DateTime.parse("20180104T123456Z");
        DateTime due = start.addDuration(hour);

        Duration day = new Duration(1, 1, 0);

        DateTime localStart = start.shiftTimeZone(TimeZone.getDefault());
        DateTime localDue = due.shiftTimeZone(TimeZone.getDefault());

        DateTime second = localStart.addDuration(day);
        DateTime third = second.addDuration(day);
        DateTime fourth = third.addDuration(day);
        DateTime fifth = fourth.addDuration(day);

        assertThat(new Seq<>(
                        new Put<>(taskList, new EmptyRowData<>()),
                        new Put<>(task,
                                new Composite<>(
                                        new TimeData<>(start, due),
                                        new RDatesTaskData(new Seq<>(start, second, third, fourth, fifth))))

                ), resultsIn(mClient,
                new Assert<>(task,
                        new Composite<>(
                                new TimeData<>(start, due),
                                new CharSequenceRowData<>(Tasks.RDATE,
                                        "20180104T123456Z," +
                                                "20180105T123456Z," +
                                                "20180106T123456Z," +
                                                "20180107T123456Z," +
                                                "20180108T123456Z"
                                ))),
//                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()))*/)
        );
    }
 
Example 7
Source File: TaskProviderDetachInstancesTest.java    From opentasks with Apache License 2.0 4 votes vote down vote up
/**
 * Test if two instances of a task with a DTSTART, DUE and an RRULE are detached correctly.
 */
@Test
public void testRRuleCompleteAll() throws InvalidRecurrenceRuleException, RemoteException, OperationApplicationException
{
    RowSnapshot<TaskLists> taskList = new VirtualRowSnapshot<>(new Synced<>(mTestAccount, new TaskListsTable(mAuthority)));
    Table<Instances> instancesTable = new InstanceTable(mAuthority);
    RowSnapshot<Tasks> task = new VirtualRowSnapshot<>(new TaskListScoped(taskList, new TasksTable(mAuthority)));

    Duration hour = new Duration(1, 0, 3600 /* 1 hour */);
    DateTime start = DateTime.parse("20180104T123456Z");
    DateTime due = start.addDuration(hour);
    DateTime localStart = start.shiftTimeZone(TimeZone.getDefault());

    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.shiftTimeZone(TimeZone.getDefault());

    OperationsQueue queue = new BasicOperationsQueue(mClient);
    queue.enqueue(new Seq<>(
            new Put<>(taskList, new EmptyRowData<>()),
            new Put<>(task,
                    new Composite<>(
                            new TitleData("Test-Task"),
                            new TimeData<>(start, due),
                            new RRuleTaskData(new RecurrenceRule("FREQ=DAILY;COUNT=2", RecurrenceRule.RfcMode.RFC2445_LAX)))),
            // complete the first non-closed instance
            new BulkUpdate<>(instancesTable, new StatusData<>(Tasks.STATUS_COMPLETED),
                    new AllOf<>(new ReferringTo<>(Instances.TASK_ID, task),
                            new EqArg<>(Instances.DISTANCE_FROM_CURRENT, 0)))
    ));
    queue.flush();

    Synced<Tasks> tasksTable = new Synced<>(mTestAccount, new TasksTable(mAuthority));
    Synced<Instances> syncedInstances = new Synced<>(mTestAccount, instancesTable);
    assertThat(new Seq<>(
                    // update the second instance
                    new BulkUpdate<>(instancesTable, new StatusData<>(Tasks.STATUS_COMPLETED),
                            new AllOf<>(new ReferringTo<>(Instances.TASK_ID, task),
                                    new EqArg<>(Instances.DISTANCE_FROM_CURRENT, 0)))
            ),
            resultsIn(queue,
                    /*
                     * We expect five tasks:
                     * - the original master with updated RRULE, DTSTART and DUE, deleted
                     * - a completed and deleted overrides for the first and second instance
                     * - a detached first and second instance
                     */

                    // the original master
                    new Assert<>(task,
                            new Composite<>(
                                    // points to former second instance before being deleted
                                    new TimeData<>(start.addDuration(day), due.addDuration(day)),
                                    new CharSequenceRowData<>(Tasks.RRULE, "FREQ=DAILY;COUNT=1"),
                                    new CharSequenceRowData<>(Tasks._DELETED, "1"))),
                    // there is no instance referring to the master because it has been fully completed (and deleted)
                    new Counted<>(0, new AssertRelated<>(instancesTable, Instances.TASK_ID, task)),
                    // the first detached task instance:
                    new Counted<>(1, new BulkAssert<>(syncedInstances,
                            new Composite<>(
                                    new InstanceTestData(localStart, localDue, absent(), -1),
                                    new CharSequenceRowData<>(Tasks.STATUS, String.valueOf(Tasks.STATUS_COMPLETED))),
                            new AllOf<>(
                                    new EqArg<>(Instances.INSTANCE_START, start.getTimestamp()),
                                    new Not<>(new ReferringTo<>(Instances.TASK_ID, task))))),
                    // the second detached task instance:
                    new Counted<>(1, new BulkAssert<>(syncedInstances,
                            new Composite<>(
                                    new InstanceTestData(second, second.addDuration(new Duration(1, 0, 3600)), absent(), -1),
                                    new CharSequenceRowData<>(Tasks.STATUS, String.valueOf(Tasks.STATUS_COMPLETED))),
                            new AllOf<>(
                                    new EqArg<>(Instances.INSTANCE_START, second.getTimestamp()),
                                    new Not<>(new ReferringTo<>(Instances.TASK_ID, task))))),
                    // two instances total, both completed
                    new Counted<>(2,
                            new BulkAssert<>(
                                    syncedInstances,
                                    new CharSequenceRowData<>(Tasks.STATUS, String.valueOf(Tasks.STATUS_COMPLETED)),
                                    new AnyOf<>())),
                    // five tasks in total
                    new Counted<>(5,
                            new BulkAssert<>(
                                    tasksTable,
                                    new TitleData("Test-Task"),
                                    new AnyOf<>())),
                    // three deleted tasks in total
                    new Counted<>(3,
                            new BulkAssert<>(
                                    tasksTable,
                                    new TitleData("Test-Task"),
                                    new EqArg<>(Tasks._DELETED, 1)))));
}
 
Example 8
Source File: TaskProviderDetachInstancesTest.java    From opentasks with Apache License 2.0 4 votes vote down vote up
/**
 * Test if the first instance of a task with a DTSTART, DUE and an RRULE is correctly detached when completed.
 */
@Test
public void testRRule() throws InvalidRecurrenceRuleException, RemoteException, OperationApplicationException
{
    RowSnapshot<TaskLists> taskList = new VirtualRowSnapshot<>(new Synced<>(mTestAccount, new TaskListsTable(mAuthority)));
    Table<Instances> instancesTable = new InstanceTable(mAuthority);
    RowSnapshot<Tasks> task = new VirtualRowSnapshot<>(new TaskListScoped(taskList, new TasksTable(mAuthority)));

    Duration hour = new Duration(1, 0, 3600 /* 1 hour */);
    DateTime start = DateTime.parse("20180104T123456Z");
    DateTime due = start.addDuration(hour);
    DateTime localStart = start.shiftTimeZone(TimeZone.getDefault());

    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.shiftTimeZone(TimeZone.getDefault());

    OperationsQueue queue = new BasicOperationsQueue(mClient);
    queue.enqueue(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))))
    ));
    queue.flush();

    assertThat(new Seq<>(
                    // update the first non-closed instance
                    new BulkUpdate<>(instancesTable, new StatusData<>(Tasks.STATUS_COMPLETED),
                            new AllOf<>(new ReferringTo<>(Instances.TASK_ID, task),
                                    new EqArg<>(Instances.DISTANCE_FROM_CURRENT, 0)))
            ),
            resultsIn(queue,
                    /*
                     * We expect three tasks:
                     * - the original master with updated RRULE, DTSTART and DUE
                     * - a deleted instance
                     * - a detached task
                     */

                    // the original master
                    new Assert<>(task,
                            new Composite<>(
                                    new TimeData<>(start.addDuration(day), due.addDuration(day)),
                                    new CharSequenceRowData<>(Tasks.RRULE, "FREQ=DAILY;COUNT=4"))),
                    // there is one instance referring to the master (the old second instance, now first)
                    new Counted<>(1, new AssertRelated<>(instancesTable, Instances.TASK_ID, task)),
                    // the detached task instance:
                    new Counted<>(1, new BulkAssert<>(new Synced<>(mTestAccount, instancesTable),
                            new Composite<>(
                                    new InstanceTestData(localStart, localDue, absent(), -1),
                                    new CharSequenceRowData<>(Tasks.STATUS, String.valueOf(Tasks.STATUS_COMPLETED))),
                            new Not<>(new ReferringTo<>(Instances.TASK_ID, task)))),
                    // the deleted task (doesn't have an instance)
                    new Counted<>(1, new BulkAssert<>(new Synced<>(mTestAccount, new TasksTable(mAuthority)),
                            new Composite<>(new TimeData<>(start, due)),
                            new AllOf<>(
                                    new ReferringTo<>(Tasks.ORIGINAL_INSTANCE_ID, task),
                                    new EqArg<>(Tasks._DELETED, 1)))),
                    // the former 2nd instance (now first)
                    new AssertRelated<>(new Synced<>(mTestAccount, instancesTable), Instances.TASK_ID, task,
                            new InstanceTestData(second, second.addDuration(hour), new Present<>(second), 0),
                            new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, second.getTimestamp()))));
}
 
Example 9
Source File: TaskProviderRecurrenceTest.java    From opentasks with Apache License 2.0 4 votes vote down vote up
/**
     * Test if instances of a task with a DTSTART and RDATEs, complete first via instances table.
     */
    @Test
    public void testRDateFirstCompleteViaInstances() throws InvalidRecurrenceRuleException
    {
        RowSnapshot<TaskLists> taskList = new VirtualRowSnapshot<>(new LocalTaskListsTable(mAuthority));
        Table<Tasks> tasksTable = new TasksTable(mAuthority);
        Table<Instances> instancesTable = new InstanceTable(mAuthority);
        RowSnapshot<Tasks> task = new VirtualRowSnapshot<>(new TaskListScoped(taskList, tasksTable));

        Duration hour = new Duration(1, 0, 3600 /* 1 hour */);
        DateTime start = DateTime.parse("20180104T123456Z");
        DateTime due = start.addDuration(hour);

        Duration day = new Duration(1, 1, 0);

        DateTime localStart = start.shiftTimeZone(TimeZone.getDefault());
        DateTime localDue = due.shiftTimeZone(TimeZone.getDefault());

        DateTime second = localStart.addDuration(day);
        DateTime third = second.addDuration(day);
        DateTime fourth = third.addDuration(day);
        DateTime fifth = fourth.addDuration(day);

        assertThat(new Seq<>(
                        new Put<>(taskList, new EmptyRowData<>()),
                        // first insert the task
                        new Put<>(task,
                                new Composite<>(
                                        new TimeData<>(start, due),
                                        new RDatesTaskData(start, second, third, fourth, fifth))),
                        // then complete the first instance
                        new BulkUpdate<>(instancesTable, new CharSequenceRowData<>(Tasks.STATUS, String.valueOf(Tasks.STATUS_COMPLETED)),
                                new AllOf<>(
                                        new ReferringTo<>(Instances.TASK_ID, task),
                                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, start.getTimestamp())))),
                resultsIn(mClient,
                        // we've already closed the first instance which has been detached, the master now points to the second instance
                        new Counted<>(1,
                                new Assert<>(task,
                                        new Composite<>(
                                                new TimeData<>(DateTime.parse("20180105T123456Z"), DateTime.parse("20180105T133456Z")),
                                                new RDatesTaskData(
                                                        // "20180104T123456Z"  // the detached instance
                                                        DateTime.parse("20180105T123456Z"),
                                                        DateTime.parse("20180106T123456Z"),
                                                        DateTime.parse("20180107T123456Z"),
                                                        DateTime.parse("20180108T123456Z"))))),
                        // there must be one task which is not equal to the original task, it's the detached instance
                        new Counted<>(1,
                                new BulkAssert<>(tasksTable,
                                        new Composite<>(
                                                new TimeData<>(start, due),
                                                new StatusData<>(Tasks.STATUS_COMPLETED),
                                                new CharSequenceRowData<>(Tasks.ORIGINAL_INSTANCE_ID, null),
                                                new CharSequenceRowData<>(Tasks.ORIGINAL_INSTANCE_SYNC_ID, null),
                                                new CharSequenceRowData<>(Tasks.ORIGINAL_INSTANCE_TIME, null)),
                                        new Not<>(new ReferringTo<>(Tasks._ID, task)))),
                        // and one instance which doesn't refer to the original task
                        new Counted<>(1, new BulkAssert<>(instancesTable, new Not<>(new ReferringTo<>(Instances.TASK_ID, task)))),
                        // but 4 instances of that original task
//                new Counted<>(4, new AssertRelated<>(instancesTable, Instances.TASK_ID, task)),
                        new Counted<>(1, new AssertRelated<>(instancesTable, Instances.TASK_ID, task)),
                        // 1st instance, detached and completed
                        new Counted<>(1, new BulkAssert<>(instancesTable,
                                new Composite<>(
                                        new InstanceTestData(localStart, localDue, absent(), -1)),
                                new AllOf<>(
                                        new IsNull<>(Instances.INSTANCE_ORIGINAL_TIME),  // the detached instance has no INSTANCE_ORIGINAL_TIME
                                        new Not<>(new ReferringTo<>(Instances.TASK_ID, task))))),
                        // 2nd instance:
                        new Counted<>(1,
                                new AssertRelated<>(instancesTable, Instances.TASK_ID, task,
                                        new InstanceTestData(second, second.addDuration(hour), new Present<>(second), 0),
                                        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), 1),
                        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), 2),
                        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), 3),
                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, fifth.getTimestamp()))*/)
        );
    }
 
Example 10
Source File: TaskProviderRecurrenceTest.java    From opentasks with Apache License 2.0 4 votes vote down vote up
/**
     * Test if instances of a task with a DTSTART and RDATEs, complete first inserted first.
     */
    @Test
    public void testRDateFirstCompleteFirstInserted() throws InvalidRecurrenceRuleException
    {
        RowSnapshot<TaskLists> taskList = new VirtualRowSnapshot<>(new LocalTaskListsTable(mAuthority));
        Table<Instances> instancesTable = new InstanceTable(mAuthority);
        RowSnapshot<Tasks> task = new VirtualRowSnapshot<>(new TaskListScoped(taskList, new TasksTable(mAuthority)));
        RowSnapshot<Tasks> override = new VirtualRowSnapshot<>(new TaskListScoped(taskList, new TasksTable(mAuthority)));

        Duration hour = new Duration(1, 0, 3600 /* 1 hour */);
        DateTime start = DateTime.parse("20180104T123456Z");
        DateTime due = start.addDuration(hour);

        Duration day = new Duration(1, 1, 0);

        DateTime localStart = start.shiftTimeZone(TimeZone.getDefault());
        DateTime localDue = due.shiftTimeZone(TimeZone.getDefault());

        DateTime second = localStart.addDuration(day);
        DateTime third = second.addDuration(day);
        DateTime fourth = third.addDuration(day);
        DateTime fifth = fourth.addDuration(day);

        assertThat(new Seq<>(
                        new Put<>(taskList, new EmptyRowData<>()),
                        // first insert override
                        new Put<>(override,
                                new Composite<>(
                                        new TimeData<>(start, due),
                                        new OriginalInstanceSyncIdData("xyz", start),
                                        new StatusData<>(Tasks.STATUS_COMPLETED))),
                        // then insert task
                        new Put<>(task,
                                new Composite<>(
                                        new SyncIdData("xyz"),
                                        new TimeData<>(start, due),
                                        new RDatesTaskData(new Seq<>(start, second, third, fourth, fifth))))

                ), resultsIn(mClient,
                new Assert<>(task,
                        new Composite<>(
                                new TimeData<>(start, due),
                                new SyncIdData("xyz"),
                                new CharSequenceRowData<>(Tasks.RDATE,
                                        "20180104T123456Z," +
                                                "20180105T123456Z," +
                                                "20180106T123456Z," +
                                                "20180107T123456Z," +
                                                "20180108T123456Z"
                                ))),
                new Assert<>(override,
                        new Composite<>(
                                new TimeData<>(start, due),
                                new OriginalInstanceSyncIdData("xyz", start),
                                new StatusData<>(Tasks.STATUS_COMPLETED))),
                new Counted<>(1, new AssertRelated<>(instancesTable, Instances.TASK_ID, override)),
//                new Counted<>(4, new AssertRelated<>(instancesTable, Instances.TASK_ID, task)),
                new Counted<>(1, new AssertRelated<>(instancesTable, Instances.TASK_ID, task)),
                // 1st instance, overridden and completed
                new AssertRelated<>(instancesTable, Instances.TASK_ID, override,
                        new InstanceTestData(localStart, localDue, new Present<>(start), -1),
                        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), 0),
                        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), 1),
                        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), 2),
                        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), 3),
                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, fifth.getTimestamp()))*/)
        );
    }
 
Example 11
Source File: TaskProviderRecurrenceTest.java    From opentasks with Apache License 2.0 4 votes vote down vote up
/**
     * Test if instances of a task with a DTSTART and RDATEs, complete first.
     */
    @Test
    public void testRDateFirstComplete() throws InvalidRecurrenceRuleException
    {
        RowSnapshot<TaskLists> taskList = new VirtualRowSnapshot<>(new LocalTaskListsTable(mAuthority));
        Table<Instances> instancesTable = new InstanceTable(mAuthority);
        RowSnapshot<Tasks> task = new VirtualRowSnapshot<>(new TaskListScoped(taskList, new TasksTable(mAuthority)));
        RowSnapshot<Tasks> override = new VirtualRowSnapshot<>(new TaskListScoped(taskList, new TasksTable(mAuthority)));

        Duration hour = new Duration(1, 0, 3600 /* 1 hour */);
        DateTime start = DateTime.parse("20180104T123456Z");
        DateTime due = start.addDuration(hour);

        Duration day = new Duration(1, 1, 0);

        DateTime localStart = start.shiftTimeZone(TimeZone.getDefault());
        DateTime localDue = due.shiftTimeZone(TimeZone.getDefault());

        DateTime second = localStart.addDuration(day);
        DateTime third = second.addDuration(day);
        DateTime fourth = third.addDuration(day);
        DateTime fifth = fourth.addDuration(day);

        assertThat(new Seq<>(
                        new Put<>(taskList, new EmptyRowData<>()),
                        // first insert new task,
                        new Put<>(task,
                                new Composite<>(
                                        new TimeData<>(start, due),
                                        new RDatesTaskData(new Seq<>(start, second, third, fourth, fifth)))),
                        // next, insert override
                        new Put<>(override,
                                new Composite<>(
                                        new TimeData<>(start, due),
                                        new OriginalInstanceData(task, start),
                                        new StatusData<>(Tasks.STATUS_COMPLETED)))

                ), resultsIn(mClient,
                new Assert<>(task,
                        new Composite<>(
                                new TimeData<>(start, due),
                                new CharSequenceRowData<>(Tasks.RDATE,
                                        "20180104T123456Z," +
                                                "20180105T123456Z," +
                                                "20180106T123456Z," +
                                                "20180107T123456Z," +
                                                "20180108T123456Z"
                                ))),
                new Counted<>(1, new AssertRelated<>(instancesTable, Instances.TASK_ID, override)),
//                new Counted<>(4, 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, override,
                        new InstanceTestData(localStart, localDue, new Present<>(start), -1),
                        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), 0),
                        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), 1),
                        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), 2),
                        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), 3),
                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, fifth.getTimestamp()))*/)
        );
    }
 
Example 12
Source File: TaskProviderRecurrenceTest.java    From opentasks with Apache License 2.0 4 votes vote down vote up
/**
     * Test if instances of a task with a DTSTART and RDATEs, add exdate afterwards.
     */
    @Test
    public void testRDateAddExDate() throws InvalidRecurrenceRuleException
    {
        RowSnapshot<TaskLists> taskList = new VirtualRowSnapshot<>(new LocalTaskListsTable(mAuthority));
        Table<Instances> instancesTable = new InstanceTable(mAuthority);
        RowSnapshot<Tasks> task = new VirtualRowSnapshot<>(new TaskListScoped(taskList, new TasksTable(mAuthority)));

        Duration hour = new Duration(1, 0, 3600 /* 1 hour */);
        DateTime start = DateTime.parse("20180104T123456Z");
        DateTime due = start.addDuration(hour);

        Duration day = new Duration(1, 1, 0);

        DateTime localStart = start.shiftTimeZone(TimeZone.getDefault());
        DateTime localDue = due.shiftTimeZone(TimeZone.getDefault());

        DateTime second = localStart.addDuration(day);
        DateTime third = second.addDuration(day);
        DateTime fourth = third.addDuration(day);
        DateTime fifth = fourth.addDuration(day);

        assertThat(new Seq<>(
                        new Put<>(taskList, new EmptyRowData<>()),
                        new Put<>(task,
                                new Composite<>(
                                        new TimeData<>(start, due),
                                        new RDatesTaskData(new Seq<>(start, second, third, fourth, fifth)))),
                        // the third instance becomed an exdate now
                        new Put<>(task,
                                new Composite<>(
                                        new ExDatesTaskData(new Seq<>(third))))
                ), resultsIn(mClient,
                new Assert<>(task,
                        new Composite<>(
                                new TimeData<>(start, due),
                                new CharSequenceRowData<>(Tasks.RDATE,
                                        "20180104T123456Z," +
                                                "20180105T123456Z," +
                                                "20180106T123456Z," +
                                                "20180107T123456Z," +
                                                "20180108T123456Z"),
                                new CharSequenceRowData<>(Tasks.EXDATE,
                                        "20180106T123456Z"
                                ))),
//                new Counted<>(4, 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), 2),
                        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), 3),
                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, fifth.getTimestamp()))*/)
        );
    }
 
Example 13
Source File: TaskProviderRecurrenceTest.java    From opentasks with Apache License 2.0 4 votes vote down vote up
/**
     * Test if instances of a task with a DTSTART, DUE and an RRULE.
     */
    @Test
    public void testRRule() throws InvalidRecurrenceRuleException
    {
        RowSnapshot<TaskLists> taskList = new VirtualRowSnapshot<>(new LocalTaskListsTable(mAuthority));
        Table<Instances> instancesTable = new InstanceTable(mAuthority);
        RowSnapshot<Tasks> task = new VirtualRowSnapshot<>(new TaskListScoped(taskList, new TasksTable(mAuthority)));

        Duration hour = new Duration(1, 0, 3600 /* 1 hour */);
        DateTime start = DateTime.parse("20180104T123456Z");
        DateTime due = start.addDuration(hour);
        DateTime localStart = start.shiftTimeZone(TimeZone.getDefault());

        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.shiftTimeZone(TimeZone.getDefault());

        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())) */)
        );
    }
 
Example 14
Source File: TaskProviderRecurrenceTest.java    From opentasks with Apache License 2.0 4 votes vote down vote up
/**
     * Test if instances of a task with a DTSTART, an RRULE and EXDATEs.
     */
    @Test
    public void testRRuleWithExDates() throws InvalidRecurrenceRuleException
    {
        RowSnapshot<TaskLists> taskList = new VirtualRowSnapshot<>(new LocalTaskListsTable(mAuthority));
        Table<Instances> instancesTable = new InstanceTable(mAuthority);
        RowSnapshot<Tasks> task = new VirtualRowSnapshot<>(new TaskListScoped(taskList, new TasksTable(mAuthority)));

        Duration hour = new Duration(1, 0, 3600 /* 1 hour */);
        DateTime start = DateTime.parse("20180104T123456Z");
        DateTime due = start.addDuration(hour);

        Duration day = new Duration(1, 1, 0);

        DateTime localStart = start.shiftTimeZone(TimeZone.getDefault());
        DateTime localDue = due.shiftTimeZone(TimeZone.getDefault());

        DateTime second = localStart.addDuration(day);
        DateTime third = second.addDuration(day);
        DateTime fourth = third.addDuration(day);
        DateTime fifth = fourth.addDuration(day);

        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)),
                                        new ExDatesTaskData(new Seq<>(third, fifth))))

                ), resultsIn(mClient,
                new Assert<>(task,
                        new Composite<>(
                                new TimeData<>(start, due),
                                new CharSequenceRowData<>(Tasks.RRULE, "FREQ=DAILY;COUNT=5"),
                                new CharSequenceRowData<>(Tasks.EXDATE, "20180106T123456Z,20180108T123456Z"))),
//                new Counted<>(3, 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())),
                // 4th instance (now 3rd):
                new AssertRelated<>(instancesTable, Instances.TASK_ID, task,
                        new InstanceTestData(fourth, fourth.addDuration(hour), new Present<>(fourth), 2),
                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, fourth.getTimestamp()))*/)
        );
    }
 
Example 15
Source File: TaskProviderRecurrenceTest.java    From opentasks with Apache License 2.0 4 votes vote down vote up
/**
 * Test RRULE with overridden instance (via update on the instances table). This time we don't override the date time fields and expect the instance to
 * inherit the original instance start and due (instead of the master start and due)
 */
@Ignore("Test tries to override the 3rd instance which has not been created because we currently only expand one instance.")
@Test
public void testRRuleWithOverride2() throws InvalidRecurrenceRuleException
{
    RowSnapshot<TaskLists> taskList = new VirtualRowSnapshot<>(new LocalTaskListsTable(mAuthority));
    Table<Tasks> tasksTable = new TasksTable(mAuthority);
    Table<Instances> instancesTable = new InstanceTable(mAuthority);
    RowSnapshot<Tasks> task = new VirtualRowSnapshot<>(new TaskListScoped(taskList, tasksTable));

    Duration hour = new Duration(1, 0, 3600 /* 1 hour */);
    DateTime start = DateTime.parse("20180104T123456Z");
    DateTime due = start.addDuration(hour);

    Duration day = new Duration(1, 1, 0);

    DateTime localStart = start.shiftTimeZone(TimeZone.getDefault());
    DateTime localDue = due.shiftTimeZone(TimeZone.getDefault());

    DateTime second = localStart.addDuration(day);
    DateTime third = second.addDuration(day);
    DateTime fourth = third.addDuration(day);
    DateTime fifth = fourth.addDuration(day);

    assertThat(new Seq<>(
                    new Put<>(taskList, new EmptyRowData<>()),
                    new Put<>(task,
                            new Composite<>(
                                    new TimeData<>(start, due),
                                    new TitleData("original"),
                                    new RRuleTaskData(new RecurrenceRule("FREQ=DAILY;COUNT=5", RecurrenceRule.RfcMode.RFC2445_LAX)))),
                    // the override just changes the title
                    new BulkUpdate<>(instancesTable,
                            new Composite<>(
                                    new CharSequenceRowData<Instances>(Tasks.TITLE, "override")),
                            new AllOf<>(new ReferringTo<>(Instances.TASK_ID, task), new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, third.getTimestamp())))
            ), resultsIn(mClient,
            new Assert<>(task,
                    new Composite<>(
                            new TimeData<>(start, due),
                            new CharSequenceRowData<>(Tasks.TITLE, "original"),
                            new CharSequenceRowData<>(Tasks.RRULE, "FREQ=DAILY;COUNT=5"))),
            new AssertRelated<>(tasksTable, Tasks.ORIGINAL_INSTANCE_ID, task,
                    new Composite<>(
                            // note the task table contains the original time zone, not the default one
                            new TimeData<>(third.shiftTimeZone(start.getTimeZone()), third.shiftTimeZone(start.getTimeZone()).addDuration(hour)),
                            new CharSequenceRowData<>(Tasks.TITLE, "override"),
                            new OriginalInstanceData(task, third))),
            new Counted<>(4, new AssertRelated<>(instancesTable, Instances.TASK_ID, task)),
            new Counted<>(1, new AssertRelated<>(instancesTable, Instances.ORIGINAL_INSTANCE_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())),
            // 3th instance (the overridden one). We don't have a row reference to this row, so we select it by the ORIGINAL_INSTANCE-ID
            new AssertRelated<>(instancesTable, Tasks.ORIGINAL_INSTANCE_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())))
    );
}
 
Example 16
Source File: TaskProviderRecurrenceTest.java    From opentasks with Apache License 2.0 4 votes vote down vote up
/**
     * Test RRULE with overridden instance (inserted into the tasks table)
     */
    @Test
    public void testRRuleWithOverride() throws InvalidRecurrenceRuleException
    {
        RowSnapshot<TaskLists> taskList = new VirtualRowSnapshot<>(new LocalTaskListsTable(mAuthority));
        Table<Instances> instancesTable = new InstanceTable(mAuthority);
        RowSnapshot<Tasks> task = new VirtualRowSnapshot<>(new TaskListScoped(taskList, new TasksTable(mAuthority)));
        RowSnapshot<Tasks> taskOverride = new VirtualRowSnapshot<>(new TaskListScoped(taskList, new TasksTable(mAuthority)));

        Duration hour = new Duration(1, 0, 3600 /* 1 hour */);
        DateTime start = DateTime.parse("20180104T123456Z");
        DateTime due = start.addDuration(hour);

        Duration day = new Duration(1, 1, 0);

        DateTime localStart = start.shiftTimeZone(TimeZone.getDefault());
        DateTime localDue = due.shiftTimeZone(TimeZone.getDefault());

        DateTime second = localStart.addDuration(day);
        DateTime third = second.addDuration(day);
        DateTime fourth = third.addDuration(day);
        DateTime fifth = fourth.addDuration(day);

        assertThat(new Seq<>(
                        new Put<>(taskList, new EmptyRowData<>()),
                        new Put<>(task,
                                new Composite<>(
                                        new TimeData<>(start, due),
                                        new TitleData("original"),
                                        new RRuleTaskData(new RecurrenceRule("FREQ=DAILY;COUNT=5", RecurrenceRule.RfcMode.RFC2445_LAX)))),
                        // the override moves the instance by an hour
                        new Put<>(taskOverride, new Composite<>(
                                new TimeData<>(third.addDuration(hour), third.addDuration(hour).addDuration(hour)),
                                new TitleData("override"),
                                new OriginalInstanceData(task, third)))
                ), resultsIn(mClient,
                new Assert<>(task,
                        new Composite<>(
                                new TimeData<>(start, due),
                                new CharSequenceRowData<>(Tasks.TITLE, "original"),
                                new CharSequenceRowData<>(Tasks.RRULE, "FREQ=DAILY;COUNT=5"))),
                new Assert<>(taskOverride,
                        new Composite<>(
                                new TimeData<>(third.addDuration(hour), third.addDuration(hour).addDuration(hour)),
                                new CharSequenceRowData<>(Tasks.TITLE, "override"),
                                new OriginalInstanceData(task, third))),
//                new Counted<>(1, new AssertRelated<>(instancesTable, Instances.TASK_ID, taskOverride)),
                new Counted<>(0, new AssertRelated<>(instancesTable, Instances.TASK_ID, taskOverride)),
//                new Counted<>(4, 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())),
                // 3th instance (the overridden one):
                new AssertRelated<>(instancesTable, Instances.TASK_ID, taskOverride,
                        new InstanceTestData(third.addDuration(hour), third.addDuration(hour).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()))*/)
        );
    }
 
Example 17
Source File: TaskProviderRecurrenceTest.java    From opentasks with Apache License 2.0 4 votes vote down vote up
/**
 * Remove an instance from a task with an RRULE.
 */
@Ignore("Test tries to delete 3rd instance which has not been created because currently only 1 instance is expanded")
@Test
public void testRRuleRemoveInstance() throws InvalidRecurrenceRuleException
{
    RowSnapshot<TaskLists> taskList = new VirtualRowSnapshot<>(new LocalTaskListsTable(mAuthority));
    Table<Instances> instancesTable = new InstanceTable(mAuthority);
    RowSnapshot<Tasks> task = new VirtualRowSnapshot<>(new TaskListScoped(taskList, new TasksTable(mAuthority)));

    Duration hour = new Duration(1, 0, 3600 /* 1 hour */);
    DateTime start = DateTime.parse("20180104T123456Z");
    DateTime due = start.addDuration(hour);

    Duration day = new Duration(1, 1, 0);

    DateTime localStart = start.shiftTimeZone(TimeZone.getDefault());
    DateTime localDue = due.shiftTimeZone(TimeZone.getDefault());

    DateTime second = localStart.addDuration(day);
    DateTime third = second.addDuration(day);
    DateTime fourth = third.addDuration(day);
    DateTime fifth = fourth.addDuration(day);

    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)))),
                    // remove the third instance
                    new BulkDelete<>(instancesTable,
                            new AllOf<>(new ReferringTo<>(Instances.TASK_ID, task), new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, third.getTimestamp())))

            ), resultsIn(mClient,
            new Assert<>(task,
                    new Composite<>(
                            new TimeData<>(start, due),
                            new CharSequenceRowData<>(Tasks.RRULE, "FREQ=DAILY;COUNT=5"),
                            new CharSequenceRowData<>(Tasks.EXDATE, "20180106T123456Z"))),
            new Counted<>(4, 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())),
            // 4th instance (now 3rd):
            new AssertRelated<>(instancesTable, Instances.TASK_ID, task,
                    new InstanceTestData(fourth, fourth.addDuration(hour), new Present<>(fourth), 2),
                    new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, fourth.getTimestamp())),
            // 5th instance (now 4th):
            new AssertRelated<>(instancesTable, Instances.TASK_ID, task,
                    new InstanceTestData(fifth, fifth.addDuration(hour), new Present<>(fifth), 3),
                    new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, fifth.getTimestamp())))
    );
}
 
Example 18
Source File: TaskProviderRecurrenceTest.java    From opentasks with Apache License 2.0 4 votes vote down vote up
/**
     * Test if instances of a task with a DTSTART and an RRULE but no DUE
     */
    @Test
    public void testRRuleNoDue() throws InvalidRecurrenceRuleException
    {
        RowSnapshot<TaskLists> taskList = new VirtualRowSnapshot<>(new LocalTaskListsTable(mAuthority));
        Table<Instances> instancesTable = new InstanceTable(mAuthority);
        RowSnapshot<Tasks> task = new VirtualRowSnapshot<>(new TaskListScoped(taskList, new TasksTable(mAuthority)));

        DateTime start = DateTime.parse("20180104T123456Z");

        Duration day = new Duration(1, 1, 0);

        DateTime localStart = start.shiftTimeZone(TimeZone.getDefault());

        DateTime second = localStart.addDuration(day);
        DateTime third = second.addDuration(day);
        DateTime fourth = third.addDuration(day);
        DateTime fifth = fourth.addDuration(day);

        assertThat(new Seq<>(
                        new Put<>(taskList, new EmptyRowData<>()),
                        new Put<>(task,
                                new Composite<>(
                                        new TimeData<>(start),
                                        new RRuleTaskData(new RecurrenceRule("FREQ=DAILY;COUNT=5", RecurrenceRule.RfcMode.RFC2445_LAX))))

                ), resultsIn(mClient,
                new Assert<>(task,
                        new Composite<>(
                                new TimeData<>(start),
                                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(new Present<>(localStart), absent(), new Present<>(start), 0),
                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, start.getTimestamp()))/*,
                // 2nd instance:
                new AssertRelated<>(instancesTable, Instances.TASK_ID, task,
                        new InstanceTestData(new Present<>(second), absent(), new Present<>(second), 1),
                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, second.getTimestamp())),
                // 3rd instance:
                new AssertRelated<>(instancesTable, Instances.TASK_ID, task,
                        new InstanceTestData(new Present<>(third), absent(), new Present<>(third), 2),
                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, third.getTimestamp())),
                // 4th instance:
                new AssertRelated<>(instancesTable, Instances.TASK_ID, task,
                        new InstanceTestData(new Present<>(fourth), absent(), new Present<>(fourth), 3),
                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, fourth.getTimestamp())),
                // 5th instance:
                new AssertRelated<>(instancesTable, Instances.TASK_ID, task,
                        new InstanceTestData(new Present<>(fifth), absent(), new Present<>(fifth), 4),
                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, fifth.getTimestamp()))*/)
        );
    }
 
Example 19
Source File: TaskProviderRecurrenceTest.java    From opentasks with Apache License 2.0 4 votes vote down vote up
/**
     * Test if instances of a task with a DUE and an RRULE but no DTSTART.
     */
    @Test
    public void testRRuleNoDtStart() throws InvalidRecurrenceRuleException
    {
        RowSnapshot<TaskLists> taskList = new VirtualRowSnapshot<>(new LocalTaskListsTable(mAuthority));
        Table<Instances> instancesTable = new InstanceTable(mAuthority);
        RowSnapshot<Tasks> task = new VirtualRowSnapshot<>(new TaskListScoped(taskList, new TasksTable(mAuthority)));

        DateTime due = DateTime.parse("20180104T123456Z");

        Duration day = new Duration(1, 1, 0);

        DateTime localDue = due.shiftTimeZone(TimeZone.getDefault());

        DateTime second = localDue.addDuration(day);
        DateTime third = second.addDuration(day);
        DateTime fourth = third.addDuration(day);
        DateTime fifth = fourth.addDuration(day);

        assertThat(new Seq<>(
                        new Put<>(taskList, new EmptyRowData<>()),
                        new Put<>(task,
                                new Composite<>(
                                        new DueData<>(due),
                                        new RRuleTaskData(new RecurrenceRule("FREQ=DAILY;COUNT=5", RecurrenceRule.RfcMode.RFC2445_LAX))))

                ), resultsIn(mClient,
                new Assert<>(task,
                        new Composite<>(
                                new DueData<>(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(absent(), new Present<>(localDue), new Present<>(due), 0),
                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, due.getTimestamp()))/*,
                // 2nd instance:
                new AssertRelated<>(instancesTable, Instances.TASK_ID, task,
                        new InstanceTestData(absent(), new Present<>(second), new Present<>(second), 1),
                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, second.getTimestamp())),
                // 3rd instance:
                new AssertRelated<>(instancesTable, Instances.TASK_ID, task,
                        new InstanceTestData(absent(), new Present<>(third), new Present<>(third), 2),
                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, third.getTimestamp())),
                // 4th instance:
                new AssertRelated<>(instancesTable, Instances.TASK_ID, task,
                        new InstanceTestData(absent(), new Present<>(fourth), new Present<>(fourth), 3),
                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, fourth.getTimestamp())),
                // 5th instance:
                new AssertRelated<>(instancesTable, Instances.TASK_ID, task,
                        new InstanceTestData(absent(), new Present<>(fifth), new Present<>(fifth), 4),
                        new EqArg<>(Instances.INSTANCE_ORIGINAL_TIME, fifth.getTimestamp()))*/)
        );
    }
 
Example 20
Source File: TaskProviderRecurrenceTest.java    From opentasks with Apache License 2.0 4 votes vote down vote up
/**
     * Test if instances of a task with a timed DTSTART, DUE and a floating RRULE UNTIL.
     * <p>
     * Note, this combination should not be accepted by the provider. For the time being, however, it should be tolerated instead of causing a crash.
     */
    @Test
    public void testRRuleWithFloatingMismatch() throws InvalidRecurrenceRuleException
    {
        RowSnapshot<TaskLists> taskList = new VirtualRowSnapshot<>(new LocalTaskListsTable(mAuthority));
        Table<Instances> instancesTable = new InstanceTable(mAuthority);
        RowSnapshot<Tasks> task = new VirtualRowSnapshot<>(new TaskListScoped(taskList, new TasksTable(mAuthority)));

        Duration hour = new Duration(1, 0, 3600 /* 1 hour */);
        DateTime start = DateTime.parse("20180104T123456Z");
        DateTime due = start.addDuration(hour);
        DateTime localStart = start.shiftTimeZone(TimeZone.getDefault());

        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.shiftTimeZone(TimeZone.getDefault());

        assertThat(new Seq<>(
                        new Put<>(taskList, new EmptyRowData<>()),
                        new Put<>(task,
                                new Composite<>(
                                        new TimeData<>(start, due),
                                        new RRuleTaskData(new RecurrenceRule("FREQ=DAILY;UNTIL=20180106", RecurrenceRule.RfcMode.RFC2445_LAX))))

                ), resultsIn(mClient,
                new Assert<>(task,
                        new Composite<>(
                                new TimeData<>(start, due),
                                new CharSequenceRowData<>(Tasks.RRULE, "FREQ=DAILY;UNTIL=20180106"))),
//                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())) */)
        );
    }