Java Code Examples for org.dmfs.rfc5545.DateTime#now()
The following examples show how to use
org.dmfs.rfc5545.DateTime#now() .
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 |
@Test public void test_whenStartAndDurationAreProvided_setsThemAndNullsDue() { DateTime start = DateTime.now(); Duration duration = new Duration(1, 3, 0); assertThat(new TimeData<>(start, duration), builds( withValuesOnly( containing(Tasks.DTSTART, start.getTimestamp()), containing(Tasks.TZ, "UTC"), containing(Tasks.IS_ALLDAY, 0), withNullValue(Tasks.DUE), containing(Tasks.DURATION, duration.toString()) ))); }
Example 2
Source File: TimeDataTest.java From opentasks with Apache License 2.0 | 6 votes |
@Test public void test_whenStartAndDueAreProvided_setsThemAndNullsDuration() { DateTime start = DateTime.now(); DateTime due = start.addDuration(new Duration(1, 1, 0)); assertThat(new TimeData<>(start, due), builds( withValuesOnly( containing(Tasks.DTSTART, start.getTimestamp()), containing(Tasks.TZ, "UTC"), containing(Tasks.IS_ALLDAY, 0), containing(Tasks.DUE, due.getTimestamp()), withNullValue(Tasks.DURATION) ))); }
Example 3
Source File: InstanceTestDataTest.java From opentasks with Apache License 2.0 | 6 votes |
@Test public void testWithDueDateAndOriginalTime() { DateTime due = DateTime.now(); DateTime original = due.addDuration(Duration.parse("P2DT2H")); assertThat(new InstanceTestData(absent(), new Present<>(due), new Present<>(original), 5), builds( withValuesOnly( withNullValue(TaskContract.Instances.INSTANCE_START), withNullValue(TaskContract.Instances.INSTANCE_START_SORTING), containing(TaskContract.Instances.INSTANCE_DUE, due.getTimestamp()), containing(TaskContract.Instances.INSTANCE_DUE_SORTING, due.shiftTimeZone(TimeZone.getDefault()).getInstance()), withNullValue(TaskContract.Instances.INSTANCE_DURATION), containing(TaskContract.Instances.INSTANCE_ORIGINAL_TIME, original.getTimestamp()), containing(TaskContract.Instances.DISTANCE_FROM_CURRENT, 5), withNullValue(TaskContract.Instances.DTSTART), containing(TaskContract.Instances.DUE, due.getTimestamp()), containing(TaskContract.Instances.ORIGINAL_INSTANCE_TIME, original.getTimestamp()), withNullValue(TaskContract.Instances.DURATION), withNullValue(TaskContract.Instances.RRULE), withNullValue(TaskContract.Instances.RDATE), withNullValue(TaskContract.Instances.EXDATE) ) )); }
Example 4
Source File: InstanceTestDataTest.java From opentasks with Apache License 2.0 | 6 votes |
@Test public void testWithStartDateAndOriginalTime() { DateTime start = DateTime.now(); DateTime original = start.addDuration(Duration.parse("P2DT2H")); assertThat(new InstanceTestData(new Present<>(start), absent(), new Present<>(original), 5), builds( withValuesOnly( containing(TaskContract.Instances.INSTANCE_START, start.getTimestamp()), containing(TaskContract.Instances.INSTANCE_START_SORTING, start.shiftTimeZone(TimeZone.getDefault()).getInstance()), withNullValue(TaskContract.Instances.INSTANCE_DUE), withNullValue(TaskContract.Instances.INSTANCE_DUE_SORTING), withNullValue(TaskContract.Instances.INSTANCE_DURATION), containing(TaskContract.Instances.INSTANCE_ORIGINAL_TIME, original.getTimestamp()), containing(TaskContract.Instances.DISTANCE_FROM_CURRENT, 5), containing(TaskContract.Instances.DTSTART, start.getTimestamp()), containing(TaskContract.Instances.ORIGINAL_INSTANCE_TIME, original.getTimestamp()), withNullValue(TaskContract.Instances.DUE), withNullValue(TaskContract.Instances.DURATION), withNullValue(TaskContract.Instances.RRULE), withNullValue(TaskContract.Instances.RDATE), withNullValue(TaskContract.Instances.EXDATE) ) )); }
Example 5
Source File: InstanceTestDataTest.java From opentasks with Apache License 2.0 | 6 votes |
@Test public void testWithDateAndOriginalTime() { DateTime start = DateTime.now(); DateTime due = start.addDuration(Duration.parse("P1DT1H")); DateTime original = start.addDuration(Duration.parse("P2DT2H")); assertThat(new InstanceTestData(start, due, new Present<>(original), 5), builds( withValuesOnly( containing(TaskContract.Instances.INSTANCE_START, start.getTimestamp()), containing(TaskContract.Instances.INSTANCE_START_SORTING, start.shiftTimeZone(TimeZone.getDefault()).getInstance()), containing(TaskContract.Instances.INSTANCE_DUE, due.getTimestamp()), containing(TaskContract.Instances.INSTANCE_DUE_SORTING, due.shiftTimeZone(TimeZone.getDefault()).getInstance()), containing(TaskContract.Instances.INSTANCE_DURATION, due.getTimestamp() - start.getTimestamp()), containing(TaskContract.Instances.INSTANCE_ORIGINAL_TIME, original.getTimestamp()), containing(TaskContract.Instances.DISTANCE_FROM_CURRENT, 5), containing(TaskContract.Instances.DTSTART, start.getTimestamp()), containing(TaskContract.Instances.DUE, due.getTimestamp()), containing(TaskContract.Instances.ORIGINAL_INSTANCE_TIME, original.getTimestamp()), withNullValue(TaskContract.Instances.DURATION), withNullValue(TaskContract.Instances.RRULE), withNullValue(TaskContract.Instances.RDATE), withNullValue(TaskContract.Instances.EXDATE) ) )); }
Example 6
Source File: InstanceTestDataTest.java From opentasks with Apache License 2.0 | 6 votes |
@Test public void testWithDate() { DateTime start = DateTime.now(); DateTime due = start.addDuration(Duration.parse("P1DT1H")); assertThat(new InstanceTestData(start, due, absent(), 5), builds( withValuesOnly( containing(TaskContract.Instances.INSTANCE_START, start.getTimestamp()), containing(TaskContract.Instances.INSTANCE_START_SORTING, start.shiftTimeZone(TimeZone.getDefault()).getInstance()), containing(TaskContract.Instances.INSTANCE_DUE, due.getTimestamp()), containing(TaskContract.Instances.INSTANCE_DUE_SORTING, due.shiftTimeZone(TimeZone.getDefault()).getInstance()), containing(TaskContract.Instances.INSTANCE_DURATION, due.getTimestamp() - start.getTimestamp()), withNullValue(TaskContract.Instances.INSTANCE_ORIGINAL_TIME), containing(TaskContract.Instances.DISTANCE_FROM_CURRENT, 5), containing(TaskContract.Instances.DTSTART, start.getTimestamp()), containing(TaskContract.Instances.DUE, due.getTimestamp()), withNullValue(TaskContract.Instances.ORIGINAL_INSTANCE_TIME), withNullValue(TaskContract.Instances.DURATION), withNullValue(TaskContract.Instances.RRULE), withNullValue(TaskContract.Instances.RDATE), withNullValue(TaskContract.Instances.EXDATE) ) )); }
Example 7
Source File: TaskProviderTest.java From opentasks with Apache License 2.0 | 5 votes |
/** * Having a task with start and due. * Update it with different due, check datetime values correct in Tasks and Instances. */ @Test public void testUpdateDue() throws Exception { RowSnapshot<TaskLists> taskList = new VirtualRowSnapshot<>(new LocalTaskListsTable(mAuthority)); RowSnapshot<Tasks> task = new VirtualRowSnapshot<>(new TaskListScoped(taskList, new TasksTable(mAuthority))); OperationsQueue queue = new BasicOperationsQueue(mClient); DateTime start = DateTime.now(); DateTime due = start.addDuration(new Duration(1, 0, 1)); queue.enqueue(new Seq<>( new Put<>(taskList, new NameData("list1")), new Put<>(task, new TimeData<>(start, due)) )); queue.flush(); DateTime due2 = due.addDuration(new Duration(1, 0, 2)); assertThat(new SingletonIterable<>( new Put<>(task, new TimeData<>(start, due2)) ), resultsIn(queue, new Assert<>(task, new Composite<>( new TimeData<>(start, due2), new VersionData(1))), new AssertRelated<>( new InstanceTable(mAuthority), Instances.TASK_ID, task, new Composite<Instances>( new InstanceTestData( start.shiftTimeZone(TimeZone.getDefault()), due2.shiftTimeZone(TimeZone.getDefault()), absent(), 0), new CharSequenceRowData<>(Tasks.TZ, "UTC")) ))); }
Example 8
Source File: TimeDataTest.java From opentasks with Apache License 2.0 | 5 votes |
@Test public void test_whenOnlyStartIsProvided_setsItAndNullsDueAndDuration() { DateTime start = DateTime.now(); assertThat(new TimeData<>(start), builds( withValuesOnly( containing(Tasks.DTSTART, start.getTimestamp()), containing(Tasks.TZ, "UTC"), containing(Tasks.IS_ALLDAY, 0), withNullValue(Tasks.DUE), withNullValue(Tasks.DURATION) ))); }
Example 9
Source File: TaskProviderTest.java From opentasks with Apache License 2.0 | 5 votes |
/** * Create task with start and due, check datetime values including generated duration. */ @Test public void testInsertTaskWithoutStartAndDueButRRULE() throws InvalidRecurrenceRuleException { RowSnapshot<TaskLists> taskList = new VirtualRowSnapshot<>(new LocalTaskListsTable(mAuthority)); RowSnapshot<Tasks> task = new VirtualRowSnapshot<>(new TaskListScoped(taskList, new TasksTable(mAuthority))); DateTime start = DateTime.now(); DateTime due = start.addDuration(new Duration(1, 1, 0)); assertThat(new Seq<>( new Put<>(taskList, new EmptyRowData<>()), new Put<>(task, new Composite<>( new TitleData("test"), new RRuleTaskData(new RecurrenceRule("FREQ=DAILY;COUNT=5", RecurrenceRule.RfcMode.RFC2445_LAX))))), resultsIn(mClient, new Assert<>(task, new Composite<>( new TitleData("test"), new VersionData(0))), new AssertRelated<>( new InstanceTable(mAuthority), Instances.TASK_ID, task, new Composite<>( new CharSequenceRowData<>(Tasks.TITLE, "test"), new InstanceTestData( absent(), absent(), absent(), 0), new CharSequenceRowData<>(Tasks.TZ, null)) ))); }
Example 10
Source File: TaskProviderTest.java From opentasks with Apache License 2.0 | 5 votes |
/** * Contract: Setting ORIGINAL_INSTANCE_ID for an exception task, * provider must fill ORIGINAL_INSTANCE_SYNC_ID with corresponding original task's _SYNC_ID. */ @Test public void testExceptionalInstance_settingRegularId_shouldUpdateSyncId() throws Exception { RowSnapshot<TaskLists> taskList = new VirtualRowSnapshot<>(new LocalTaskListsTable(mAuthority)); Table<Tasks> taskTable = new TaskListScoped(taskList, new TasksTable(mAuthority)); RowSnapshot<Tasks> task = new VirtualRowSnapshot<>(taskTable); RowSnapshot<Tasks> exceptionTask = new VirtualRowSnapshot<>(taskTable); OperationsQueue queue = new BasicOperationsQueue(mClient); queue.enqueue(new Seq<Operation<?>>( new Put<>(taskList, new NameData("list1")), new Put<>(task, new Composite<>( new TitleData("task1"), new SyncIdData("syncId1"))) )); queue.flush(); DateTime now = DateTime.now(); assertThat(new SingletonIterable<>( new Put<>(exceptionTask, new Composite<>( new TitleData("task1exception"), new OriginalInstanceData(task, now))) ), resultsIn(queue, new AssertRelated<>(new TasksTable(mAuthority), Tasks.ORIGINAL_INSTANCE_ID, task, new Composite<>( new TitleData("task1exception"), new OriginalInstanceSyncIdData("syncId1", now) )) )); }
Example 11
Source File: TaskProviderTest.java From opentasks with Apache License 2.0 | 5 votes |
/** * 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 12
Source File: TaskProviderTest.java From opentasks with Apache License 2.0 | 5 votes |
/** * Create task with start and duration, check datetime values including generated due. */ @Test public void testInsertWithStartAndDuration() { 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(); assertThat(new Seq<>( new Put<>(taskList, new EmptyRowData<TaskLists>()), new Put<>(task, new TimeData<>(start, duration)) ), resultsIn(mClient, new Assert<>(task, new Composite<>( new TimeData<>(start, duration), new VersionData(0))), 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, "UTC")) ))); }
Example 13
Source File: TaskProviderTest.java From opentasks with Apache License 2.0 | 5 votes |
/** * Create task without dates and set start and due afterwards, check datetime values including generated duration. */ @Test public void testInsertTaskWithStartAndDueAddedAfterwards() { RowSnapshot<TaskLists> taskList = new VirtualRowSnapshot<>(new LocalTaskListsTable(mAuthority)); RowSnapshot<Tasks> task = new VirtualRowSnapshot<>(new TaskListScoped(taskList, new TasksTable(mAuthority))); DateTime start = DateTime.now(); DateTime due = start.addDuration(new Duration(1, 1, 0)); assertThat(new Seq<>( new Put<>(taskList, new EmptyRowData<TaskLists>()), new Put<>(task, new TitleData("Test")), new Put<>(task, new TimeData<>(start, due)) ), resultsIn(mClient, new Assert<>(task, new Composite<>( new TimeData<>(start, due), new VersionData(1))), new AssertRelated<>( new InstanceTable(mAuthority), Instances.TASK_ID, task, new Composite<Instances>( new InstanceTestData( start.shiftTimeZone(TimeZone.getDefault()), due.shiftTimeZone(TimeZone.getDefault()), absent(), 0), new CharSequenceRowData<>(Tasks.TZ, "UTC")) ))); }
Example 14
Source File: TaskProviderTest.java From opentasks with Apache License 2.0 | 5 votes |
/** * Create task with start and due and update it with new values, check datetime values including generated duration. */ @Test public void testInsertTaskWithStartAndDueMovedBackwards() { RowSnapshot<TaskLists> taskList = new VirtualRowSnapshot<>(new LocalTaskListsTable(mAuthority)); RowSnapshot<Tasks> task = new VirtualRowSnapshot<>(new TaskListScoped(taskList, new TasksTable(mAuthority))); DateTime start = DateTime.now(); DateTime due = start.addDuration(new Duration(1, 1, 0)); Duration duration = new Duration(-1, 2, 0); DateTime startNew = start.addDuration(duration); DateTime dueNew = due.addDuration(duration); assertThat(new Seq<>( new Put<>(taskList, new EmptyRowData<TaskLists>()), new Put<>(task, new TimeData<>(start, due)), new Put<>(task, new TimeData<>(startNew, dueNew)) ), resultsIn(mClient, new Assert<>(task, new Composite<>( new TimeData<>(startNew, dueNew), new VersionData(1))), new AssertRelated<>( new InstanceTable(mAuthority), Instances.TASK_ID, task, new Composite<Instances>( new InstanceTestData( startNew.shiftTimeZone(TimeZone.getDefault()), dueNew.shiftTimeZone(TimeZone.getDefault()), absent(), 0), new CharSequenceRowData<>(Tasks.TZ, "UTC")) ))); }
Example 15
Source File: TaskProviderTest.java From opentasks with Apache License 2.0 | 5 votes |
/** * Create task with start and due and update it with new values, check datetime values including generated duration. */ @Test public void testInsertTaskWithStartAndDueMovedForward() { RowSnapshot<TaskLists> taskList = new VirtualRowSnapshot<>(new LocalTaskListsTable(mAuthority)); RowSnapshot<Tasks> task = new VirtualRowSnapshot<>(new TaskListScoped(taskList, new TasksTable(mAuthority))); DateTime start = DateTime.now(); DateTime due = start.addDuration(new Duration(1, 1, 0)); Duration duration = new Duration(1, 2, 0); DateTime startNew = start.addDuration(duration); DateTime dueNew = due.addDuration(duration); assertThat(new Seq<>( new Put<>(taskList, new EmptyRowData<TaskLists>()), new Put<>(task, new TimeData<>(start, due)), new Put<>(task, new TimeData<>(startNew, dueNew)) ), resultsIn(mClient, new Assert<>(task, new Composite<>( new TimeData<>(startNew, dueNew), new VersionData(1))), new AssertRelated<>( new InstanceTable(mAuthority), Instances.TASK_ID, task, new Composite<Instances>( new InstanceTestData( startNew.shiftTimeZone(TimeZone.getDefault()), dueNew.shiftTimeZone(TimeZone.getDefault()), absent(), 0), new CharSequenceRowData<>(Tasks.TZ, "UTC")) ))); }
Example 16
Source File: TaskProviderTest.java From opentasks with Apache License 2.0 | 5 votes |
/** * Create task with start and due, check datetime and INSTANCE_STATUS values after updating the task twice. */ @Test public void testInsertTaskWithStartAndDueUpdateTwice() { RowSnapshot<TaskLists> taskList = new VirtualRowSnapshot<>(new LocalTaskListsTable(mAuthority)); RowSnapshot<Tasks> task = new VirtualRowSnapshot<>(new TaskListScoped(taskList, new TasksTable(mAuthority))); DateTime start = DateTime.now(); DateTime due = start.addDuration(new Duration(1, 1, 0)); assertThat(new Seq<>( new Put<>(taskList, new EmptyRowData<>()), new Put<>(task, new TimeData<>(start, due)), // update the status of the new task new Put<>(task, new StatusData<>(Tasks.STATUS_COMPLETED)), // update the title of the new task new Put<>(task, new TitleData("Task Title")) ), resultsIn(mClient, new Assert<>(task, new Composite<>( new TimeData<>(start, due), new TitleData("Task Title"), new VersionData(2))), // task has been updated twice new AssertRelated<>( new InstanceTable(mAuthority), Instances.TASK_ID, task, new Composite<Instances>( new InstanceTestData( start.shiftTimeZone(TimeZone.getDefault()), due.shiftTimeZone(TimeZone.getDefault()), absent(), -1), new CharSequenceRowData<>(Tasks.TZ, "UTC")) ))); }
Example 17
Source File: DueDataTest.java From opentasks with Apache License 2.0 | 5 votes |
@Test public void test_whenNoTimeZoneNotAllDay_setsValuesAccordingly_andNullsOtherTimeRelatedValues() { DateTime due = DateTime.now(); assertThat(new DueData<>(due), builds( withValuesOnly( containing(Tasks.DUE, due.getTimestamp()), containing(Tasks.TZ, "UTC"), containing(Tasks.IS_ALLDAY, 0), withNullValue(Tasks.DTSTART), withNullValue(Tasks.DURATION) ))); }
Example 18
Source File: TaskProviderTest.java From opentasks with Apache License 2.0 | 5 votes |
/** * Create task with start and due, check datetime values including generated duration. */ @Test public void testInsertTaskWithStartAndDue() { RowSnapshot<TaskLists> taskList = new VirtualRowSnapshot<>(new LocalTaskListsTable(mAuthority)); RowSnapshot<Tasks> task = new VirtualRowSnapshot<>(new TaskListScoped(taskList, new TasksTable(mAuthority))); DateTime start = DateTime.now(); DateTime due = start.addDuration(new Duration(1, 1, 0)); assertThat(new Seq<>( new Put<>(taskList, new EmptyRowData<TaskLists>()), new Put<>(task, new TimeData<>(start, due)) ), resultsIn(mClient, new Assert<>(task, new Composite<>( new TimeData<>(start, due), new VersionData(0))), new AssertRelated<>( new InstanceTable(mAuthority), Instances.TASK_ID, task, new Composite<Instances>( new InstanceTestData( start.shiftTimeZone(TimeZone.getDefault()), due.shiftTimeZone(TimeZone.getDefault()), absent(), 0), new CharSequenceRowData<>(Tasks.TZ, "UTC")) ))); }
Example 19
Source File: JsonAccessToken.java From oauth2-essentials with Apache License 2.0 | 4 votes |
public JsonAccessToken(JSONObject tokenResponse, OAuth2Scope scope) { mScope = scope; mTokenResponse = tokenResponse; mIssueDate = DateTime.now(); }
Example 20
Source File: ImplicitGrantAccessToken.java From oauth2-essentials with Apache License 2.0 | 3 votes |
/** * Represents the {@link OAuth2AccessToken} that's contained in the provided redirect URI. * * @param redirectUri * The URI the user agent was redirected to. * @param scope * The scope that has been requested from the server. * @param state * The state that was provided to the authorization endpoint. * @param defaultExpiresIn * The default expiration duration to assume if no expiration duration was provided with the response. * * @throws ProtocolException * If the state doesn't match the one returned by the server. */ public ImplicitGrantAccessToken(Uri redirectUri, OAuth2Scope scope, CharSequence state, Duration defaultExpiresIn) throws ProtocolException { mRedirectUri = redirectUri; mRedirectUriParameters = new XwfueParameterList(redirectUri.fragment().value()); if (!state.toString().equals(new TextParameter(STATE, mRedirectUriParameters).toString())) { throw new ProtocolException("State in redirect uri doesn't match the original state!"); } mIssueDate = DateTime.now(); mScope = scope; mDefaultExpiresIn = defaultExpiresIn; }