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

The following examples show how to use org.dmfs.rfc5545.DateTime#parse() . 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: RecurrenceSetIteratorTest.java    From lib-recur with Apache License 2.0 6 votes vote down vote up
/**
 * Test results if multiple exception lists have been provided.
 */
@Test
public void testMultipleExceptions()
{
    TimeZone testZone = TimeZone.getTimeZone("UTC");
    DateTime start = DateTime.parse("20180101T120000");
    RecurrenceSetIterator recurrenceSetIterator = new RecurrenceSetIterator(
            asList(new RecurrenceList("20180101T120000,20180102T120000,20180103T120000,20180104T120000", testZone).getIterator(testZone,
                    start.getTimestamp())),
            asList(new RecurrenceList("20180103T120000", testZone).getIterator(testZone, start.getTimestamp()),
                    new RecurrenceList("20180102T120000", testZone).getIterator(testZone, start.getTimestamp())));

    // note we call hasNext twice to ensure it's idempotent
    assertThat(recurrenceSetIterator.hasNext(), is(true));
    assertThat(recurrenceSetIterator.hasNext(), is(true));
    assertThat(recurrenceSetIterator.next(), is(start.getTimestamp()));
    assertThat(recurrenceSetIterator.hasNext(), is(true));
    assertThat(recurrenceSetIterator.hasNext(), is(true));
    assertThat(recurrenceSetIterator.next(), is(start.addDuration(new Duration(1, 3, 0)).getTimestamp()));
    assertThat(recurrenceSetIterator.hasNext(), is(false));
    assertThat(recurrenceSetIterator.hasNext(), is(false));
}
 
Example 2
Source File: RecurrenceSetIteratorTest.java    From lib-recur with Apache License 2.0 6 votes vote down vote up
/**
 * Test results if a single exception list has been provided.
 */
@Test
public void testExceptions()
{
    TimeZone testZone = TimeZone.getTimeZone("UTC");
    DateTime start = DateTime.parse("20180101T120000");
    RecurrenceSetIterator recurrenceSetIterator = new RecurrenceSetIterator(
            asList(new RecurrenceList("20180101T120000,20180102T120000,20180103T120000,20180104T120000", testZone).getIterator(testZone,
                    start.getTimestamp())),
            asList(new RecurrenceList("20180102T120000,20180103T120000", testZone).getIterator(testZone, start.getTimestamp())));

    // note we call hasNext twice to ensure it's idempotent
    assertThat(recurrenceSetIterator.hasNext(), is(true));
    assertThat(recurrenceSetIterator.hasNext(), is(true));
    assertThat(recurrenceSetIterator.next(), is(start.getTimestamp()));
    assertThat(recurrenceSetIterator.hasNext(), is(true));
    assertThat(recurrenceSetIterator.hasNext(), is(true));
    assertThat(recurrenceSetIterator.next(), is(start.addDuration(new Duration(1, 3, 0)).getTimestamp()));
    assertThat(recurrenceSetIterator.hasNext(), is(false));
    assertThat(recurrenceSetIterator.hasNext(), is(false));
}
 
Example 3
Source File: RecurrenceSetIteratorTest.java    From lib-recur with Apache License 2.0 6 votes vote down vote up
/**
 * Test results if a single exception list has been provided.
 */
@Test
public void testExceptionsAllDay()
{
    TimeZone testZone = TimeZone.getTimeZone("UTC");
    DateTime start = DateTime.parse("20180101");
    RecurrenceSetIterator recurrenceSetIterator = new RecurrenceSetIterator(
            asList(new RecurrenceList("20180101,20180102,20180103,20180104", testZone).getIterator(testZone, start.getTimestamp())),
            asList(new RecurrenceList("20180102,20180103", testZone).getIterator(testZone, start.getTimestamp())));

    // note we call hasNext twice to ensure it's idempotent
    assertThat(recurrenceSetIterator.hasNext(), is(true));
    assertThat(recurrenceSetIterator.hasNext(), is(true));
    assertThat(recurrenceSetIterator.next(), is(start.getTimestamp()));
    assertThat(recurrenceSetIterator.hasNext(), is(true));
    assertThat(recurrenceSetIterator.hasNext(), is(true));
    assertThat(recurrenceSetIterator.next(), is(start.addDuration(new Duration(1, 3, 0)).getTimestamp()));
    assertThat(recurrenceSetIterator.hasNext(), is(false));
    assertThat(recurrenceSetIterator.hasNext(), is(false));
}
 
Example 4
Source File: DueDatedTest.java    From opentasks with Apache License 2.0 5 votes vote down vote up
@Test
public void testStartAmerica()
{
    DateTime start = DateTime.parse("America/New_York", "20171208T125500");

    ContentValues instanceData = new DueDated(new Present<>(start), ContentValues::new).value();

    assertThat(instanceData, new ContentValuesWithLong(TaskContract.Instances.INSTANCE_DUE, start.getTimestamp()));
    assertThat(instanceData,
            new ContentValuesWithLong(TaskContract.Instances.INSTANCE_DUE_SORTING, start.shiftTimeZone(TimeZone.getDefault()).getInstance()));
    assertThat(instanceData.size(), is(2));
}
 
Example 5
Source File: StartDatedTest.java    From opentasks with Apache License 2.0 5 votes vote down vote up
@Test
public void testStartEurope()
{
    DateTime start = DateTime.parse("Europe/Berlin", "20171208T125500");

    ContentValues instanceData = new StartDated(new Present<>(start), ContentValues::new).value();

    assertThat(instanceData, new ContentValuesWithLong(TaskContract.Instances.INSTANCE_START, start.getTimestamp()));
    assertThat(instanceData,
            new ContentValuesWithLong(TaskContract.Instances.INSTANCE_START_SORTING, start.shiftTimeZone(TimeZone.getDefault()).getInstance()));
    assertThat(instanceData.size(), is(2));
}
 
Example 6
Source File: TaskProviderInstancesTest.java    From opentasks with Apache License 2.0 5 votes vote down vote up
/**
 * Create a single instance and insert an override for exactly the same instance.
 */
@Test(expected = IllegalArgumentException.class)
public void testInsertSingleInstanceTwice() throws RemoteException, OperationApplicationException
{
    RowSnapshot<TaskLists> taskList = new VirtualRowSnapshot<>(new LocalTaskListsTable(mAuthority));
    RowSnapshot<Tasks> task = new VirtualRowSnapshot<>(new TasksTable(mAuthority));
    RowSnapshot<Instances> instance = new VirtualRowSnapshot<>(new InstanceTable(mAuthority));

    DateTime dateTime = DateTime.parse("20180110T224500Z");
    String dtstart = Long.toString(dateTime.getTimestamp());

    new BaseTransaction().with(new Seq<>(
            // create a local list
            new Put<>(taskList, new NameData("list1")),
            // insert a new task into the tasks table (we insert a task to get a RowReference to the new row)
            new Put<>(task,
                    new Composite<>(
                            new Referring<>(Tasks.LIST_ID, taskList),
                            new TimeData<>(dateTime),
                            new TitleData("task1"))),
            new Put<>(instance,
                    new Composite<>(
                            new Referring<>(Tasks.LIST_ID, taskList),
                            new CharSequenceRowData<>(Tasks.DTSTART, "1234"),
                            // insert an instance which would override the original instance, which already exists
                            new Referring<>(Tasks.ORIGINAL_INSTANCE_ID, task),
                            new CharSequenceRowData<>(Tasks.ORIGINAL_INSTANCE_TIME, dtstart),
                            new CharSequenceRowData<>(Tasks.TZ, "UTC"),
                            new CharSequenceRowData<>(Tasks.TITLE, "task1")))

    )).commit(mClient);
}
 
Example 7
Source File: StartDatedTest.java    From opentasks with Apache License 2.0 5 votes vote down vote up
@Test
public void testStartAmerica()
{
    DateTime start = DateTime.parse("America/New_York", "20171208T125500");

    ContentValues instanceData = new StartDated(new Present<>(start), ContentValues::new).value();

    assertThat(instanceData, new ContentValuesWithLong(TaskContract.Instances.INSTANCE_START, start.getTimestamp()));
    assertThat(instanceData,
            new ContentValuesWithLong(TaskContract.Instances.INSTANCE_START_SORTING, start.shiftTimeZone(TimeZone.getDefault()).getInstance()));
    assertThat(instanceData.size(), is(2));
}
 
Example 8
Source File: TestRule.java    From lib-recur with Apache License 2.0 5 votes vote down vote up
private TestRule _setUntil(String lastInstance)
{
    until = DateTime.parse(lastInstance);
    floating = !lastInstance.endsWith("Z");
    allday = !lastInstance.contains("T");
    return this;
}
 
Example 9
Source File: DateTimeArrayFieldAdapter.java    From opentasks-provider with Apache License 2.0 5 votes vote down vote up
@Override
public DateTime[] getFrom(ContentValues values)
{
	String datetimeList = values.getAsString(mDateTimeListFieldName);
	if (datetimeList == null)
	{
		// no list, return null
		return null;
	}

	// create a new TimeZone for the given time zone string
	String timezoneString = mTimeZoneFieldName == null ? null : values.getAsString(mTimeZoneFieldName);
	TimeZone timeZone = timezoneString == null ? null : TimeZone.getTimeZone(timezoneString);

	String[] datetimes = SEPARATOR_PATTERN.split(datetimeList);

	DateTime[] result = new DateTime[datetimes.length];
	for (int i = 0, count = datetimes.length; i < count; ++i)
	{
		DateTime value = DateTime.parse(timeZone, datetimes[i]);

		if (!value.isAllDay() && value.isFloating())
		{
			throw new IllegalArgumentException("DateTime values must not be floating, unless they are all-day.");
		}

		result[i] = value;
		if (i > 0 && result[0].isAllDay() != value.isAllDay())
		{
			throw new IllegalArgumentException("DateTime values must all be of the same type.");
		}
	}

	return result;
}
 
Example 10
Source File: TestRule.java    From lib-recur with Apache License 2.0 4 votes vote down vote up
public TestRule setLastInstance(String lastInstance, String tzId)
{
    this.lastInstance = DateTime.parse(tzId, lastInstance);
    return this;
}
 
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, 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 12
Source File: TestRule.java    From lib-recur with Apache License 2.0 4 votes vote down vote up
public TestRule setLastInstance(String lastInstance)
{
    this.lastInstance = DateTime.parse(lastInstance);
    return this;
}
 
Example 13
Source File: TaskProviderInstancesTest.java    From opentasks with Apache License 2.0 4 votes vote down vote up
/**
     * Create a single instance and insert an override for a new instance, turning the event into a recurring event.
     */
    @Ignore("Inserting instances is currently not supported.")
    @Test
    public void testInsertSingleInstanceAddAnother()
    {
        RowSnapshot<TaskLists> taskList = new VirtualRowSnapshot<>(new LocalTaskListsTable(mAuthority));
        RowSnapshot<Tasks> task = new VirtualRowSnapshot<>(new TasksTable(mAuthority));
        RowSnapshot<Instances> instance = new VirtualRowSnapshot<>(new InstanceTable(mAuthority));

        DateTime dateTimeOriginal = DateTime.parse("20180110T224500Z");
        // override is one day later
        DateTime dateTimeOverride = DateTime.parse("20180111T224500Z");
        String startOverride = Long.toString(dateTimeOverride.getTimestamp());

        assertThat(new Seq<>(
                // create a local list
                new Put<>(taskList, new NameData("list1")),
                // insert a new task into the tasks table (we insert a task to get a RowReference to the new row)
                new Put<>(task,
                        new Composite<Tasks>(
                                new Referring<>(Tasks.LIST_ID, taskList),
                                new TimeData(dateTimeOriginal),
                                new TitleData("task1"))),
                new Put<>(instance,
                        new Composite<Instances>(
                                new Referring<>(Tasks.LIST_ID, taskList),
                                new CharSequenceRowData<>(Tasks.DTSTART, "1234"),
                                new CharSequenceRowData<>(Tasks.IS_ALLDAY, "0"),
                                // insert an override instance
                                new Referring<>(Tasks.ORIGINAL_INSTANCE_ID, task),
                                new CharSequenceRowData<>(Tasks.ORIGINAL_INSTANCE_TIME, startOverride),
                                new CharSequenceRowData<>(Tasks.TZ, "UTC"),
                                new CharSequenceRowData<>(Tasks.TITLE, "task override")))

        ), resultsIn(mClient,
                new Assert<>(taskList, new NameData("list1")),
                // the task list contains exactly two tasks
                new Counted<>(2, new BulkAssert<>(new TasksTable(mAuthority))),
                // check that the original task has RDATES now, one for the original start and one for the new override
                new Assert<>(task,
                        new Composite<Tasks>(
                                new Referring<>(Tasks.LIST_ID, taskList),
                                new TimeData(dateTimeOriginal),
                                new CharSequenceRowData<>(Tasks.RDATE, "20180110T224500Z,20180111T224500Z"),
                                new TitleData("task1"))),
                // and check there is a task for the override
                new AssertRelated<>(new TasksTable(mAuthority), Tasks.ORIGINAL_INSTANCE_ID, task,
                        new Composite<Tasks>(
                                new Referring<>(Tasks.LIST_ID, taskList),
                                new CharSequenceRowData<>(Tasks.ORIGINAL_INSTANCE_TIME, startOverride),
                                new TimeData(new DateTime(1234)),
                                new TitleData("task override")))
                // TODO: enable tests below once recurrence has been implemented
//                // the instances table contains two instances as well
//                new Counted<>(2, new BulkAssert<>(new InstanceTable(mAuthority))),
//                // one instance is related to the task
//               new AssertRelated<>(new InstanceTable(mAuthority), Instances.TASK_ID, task,
//                        new Composite<>(
//                                new InstanceTestData(new Present<>(dateTimeOriginal), new Absent<>(), new Present<>(dateTimeOriginal), 0),
//                                new CharSequenceRowData<>(Tasks.TITLE, "task1"))),
//                // the other instance is for the override
//                new Assert<>(instance, new Composite<>(
//                        new InstanceTestData(new Present<>(new DateTime(1234)), new Absent<>(), new Present<>(dateTimeOverride), 0),
//                        new CharSequenceRowData<>(Tasks.TITLE, "task override")))
        ));
    }
 
Example 14
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 15
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 16
Source File: TaskProviderRecurrenceTest.java    From opentasks with Apache License 2.0 4 votes vote down vote up
/**
     * Test if instances of a task with an all-day DTSTART, DUE and an RRULE.
     */
    @Test
    public void testAllDayRRule() 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 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())) */)
        );
    }
 
Example 17
Source File: TaskProviderRecurrenceTest.java    From opentasks with Apache License 2.0 4 votes vote down vote up
/**
     * Test if instances of a task with an all-day DTSTART, DUE and an RRULE with an absolute 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 testAllDayRRuleFloatingMismatch() 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 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;UNTIL=20180106T120000Z", RecurrenceRule.RfcMode.RFC2445_LAX))))

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