Java Code Examples for org.threeten.bp.LocalDateTime#now()

The following examples show how to use org.threeten.bp.LocalDateTime#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: SessionsReminder.java    From droidconat-2016 with Apache License 2.0 6 votes vote down vote up
public void addSessionReminder(@NonNull Session session) {
    if (!isEnabled()) {
        Timber.d("SessionsReminder is not enable, skip adding session");
        return;
    }

    PendingIntent intent = createSessionReminderIntent(session);
    LocalDateTime now = LocalDateTime.now();
    LocalDateTime sessionStartTime = session.getFromTime().minusMinutes(3);
    if (!sessionStartTime.isAfter(now)) {
        Timber.w("Do not set reminder for passed session");
        return;
    }
    Timber.d("Setting reminder on %s", sessionStartTime);
    App.setExactAlarm(alarmManager, sessionStartTime.atZone(ZoneOffset.systemDefault()).toInstant().toEpochMilli(), intent);
}
 
Example 2
Source File: NetworkMapperTest.java    From droidconat-2016 with Apache License 2.0 6 votes vote down vote up
@Test
public void should_convert_network_sessions_to_app_sessions() {
    // Given
    LocalDateTime startAt = LocalDateTime.now();
    Session session = new Session(1, startAt, 20, Room.NONE.id, singletonList(10), "title", "description");
    Map<Integer, com.nilhcem.droidconat.data.app.model.Speaker> speakersMap = new HashMap<>();
    speakersMap.put(10, new com.nilhcem.droidconat.data.app.model.Speaker(10, "ten", null, null, null, null, null, null));

    // When
    List<com.nilhcem.droidconat.data.app.model.Session> result = networkMapper.toAppSessions(singletonList(session), speakersMap);

    // Then
    assertThat(result).hasSize(1);
    assertThat(result.get(0).getId()).isEqualTo(1);
    assertThat(result.get(0).getFromTime()).isEqualTo(startAt);
    assertThat(result.get(0).getToTime()).isEqualTo(startAt.plusMinutes(20));
    assertThat(result.get(0).getRoom()).isEqualTo(Room.NONE.label);
    assertThat(result.get(0).getSpeakers().get(0).getId()).isEqualTo(10);
    assertThat(result.get(0).getSpeakers().get(0).getName()).isEqualTo("ten");
    assertThat(result.get(0).getTitle()).isEqualTo("title");
    assertThat(result.get(0).getDescription()).isEqualTo("description");
}
 
Example 3
Source File: SelectedSessionsMemoryTest.java    From droidconat-2016 with Apache License 2.0 6 votes vote down vote up
@Test
public void should_remove_previous_session_when_adding_a_new_one_for_the_same_slot_time() {
    // Given
    LocalDateTime now = LocalDateTime.now();
    Map<LocalDateTime, Integer> map = new HashMap<>();
    map.put(now, 1);
    memory.setSelectedSessions(map);
    Session toAdd = new Session(3, null, null, null, null, now, now.plusMinutes(30));

    // When
    assertThat(memory.get(now)).isEqualTo(1);
    memory.toggleSessionState(toAdd, true);

    // Then
    assertThat(memory.get(now)).isEqualTo(3);
}
 
Example 4
Source File: ScheduleSlotTest.java    From droidconat-2016 with Apache License 2.0 6 votes vote down vote up
@Test
public void should_restore_from_parcelable() {
    // Given
    LocalDateTime time = LocalDateTime.now();
    List<Session> sessions = Arrays.asList(new Session(1, null, null, null, null, null, null), new Session(2, null, null, null, null, null, null), new Session(3, null, null, null, null, null, null));
    ScheduleSlot slot = new ScheduleSlot(time, sessions);

    // When
    Parcel parcel = Parcel.obtain();
    slot.writeToParcel(parcel, 0);
    parcel.setDataPosition(0);
    ScheduleSlot fromParcel = ScheduleSlot.CREATOR.createFromParcel(parcel);

    // Then
    assertThat(fromParcel.getTime()).isEqualTo(time);
    assertThat(fromParcel.getSessions()).hasSize(3);
}
 
Example 5
Source File: SelectedSessionsMemoryTest.java    From droidconat-2016 with Apache License 2.0 5 votes vote down vote up
@Test
public void should_set_selected_sessions() {
    // Given
    LocalDateTime now = LocalDateTime.now();
    Map<LocalDateTime, Integer> map = new HashMap<>();
    map.put(now, 1);

    // When
    assertThat(memory.get(now)).isNull();
    memory.setSelectedSessions(map);

    // Then
    assertThat(memory.get(now)).isEqualTo(1);
}
 
Example 6
Source File: DataProviderCacheTest.java    From droidconat-2016 with Apache License 2.0 5 votes vote down vote up
@Test
public void should_save_sessions_in_memory_keeping_save_time() {
    // Given When
    LocalDateTime before = LocalDateTime.now();
    cache.saveSessions(sessions);
    LocalDateTime after = LocalDateTime.now();

    // Then
    assertThat(cache.sessions).hasSize(2);
    assertThat(cache.sessionsFetchedTime).isAtLeast(before);
    assertThat(cache.sessionsFetchedTime).isAtMost(after);
}
 
Example 7
Source File: DataProviderCacheTest.java    From droidconat-2016 with Apache License 2.0 5 votes vote down vote up
@Test
public void should_return_sessions_when_cache_time_is_still_active() {
    // Given
    cache.sessionsFetchedTime = LocalDateTime.now();
    cache.sessions = sessions;

    // When
    List<Session> result = cache.getSessions();

    // Then
    assertThat(result).isEqualTo(sessions);
}
 
Example 8
Source File: DataProviderCacheTest.java    From droidconat-2016 with Apache License 2.0 5 votes vote down vote up
@Test
public void should_save_speakers_in_memory_keeping_save_time() {
    // Given When
    LocalDateTime before = LocalDateTime.now();
    cache.saveSpeakers(speakers);
    LocalDateTime after = LocalDateTime.now();

    // Then
    assertThat(cache.speakers).hasSize(2);
    assertThat(cache.speakersFetchedTime).isAtLeast(before);
    assertThat(cache.speakersFetchedTime).isAtMost(after);
}
 
Example 9
Source File: DataProviderCacheTest.java    From droidconat-2016 with Apache License 2.0 5 votes vote down vote up
@Test
public void should_return_speakers_when_cache_time_is_still_active() {
    // Given
    cache.speakersFetchedTime = LocalDateTime.now();
    cache.speakers = speakers;

    // When
    List<Speaker> result = cache.getSpeakers();

    // Then
    assertThat(result).isEqualTo(speakers);
}
 
Example 10
Source File: ElectricityViewModel.java    From android-things-electricity-monitor with Apache License 2.0 4 votes vote down vote up
private Duration getDifferenceBetweenTimeAndNow(long timeStart) {
    LocalDateTime today = LocalDateTime.now();
    LocalDateTime otherTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(timeStart), ZoneId.systemDefault());
    return Duration.between(otherTime, today);
}
 
Example 11
Source File: DataProviderCache.java    From droidconat-2016 with Apache License 2.0 4 votes vote down vote up
public void saveSessions(List<Session> sessions) {
    this.sessions = sessions;
    sessionsFetchedTime = LocalDateTime.now();
}
 
Example 12
Source File: DataProviderCache.java    From droidconat-2016 with Apache License 2.0 4 votes vote down vote up
public void saveSpeakers(List<Speaker> speakers) {
    this.speakers = speakers;
    speakersFetchedTime = LocalDateTime.now();
}