Example usage for java.time.temporal ChronoUnit DAYS

List of usage examples for java.time.temporal ChronoUnit DAYS

Introduction

In this page you can find the example usage for java.time.temporal ChronoUnit DAYS.

Prototype

ChronoUnit DAYS

To view the source code for java.time.temporal ChronoUnit DAYS.

Click Source Link

Document

Unit that represents the concept of a day.

Usage

From source file:ch.elexis.data.TarmedOptifier.java

private String checkAge(String limitsString, Konsultation kons) {
    LocalDateTime consDate = new TimeTool(kons.getDatum()).toLocalDateTime();
    Patient patient = kons.getFall().getPatient();
    String geburtsdatum = patient.getGeburtsdatum();
    if (StringUtils.isEmpty(geburtsdatum)) {
        return "Patienten Alter nicht ok, kein Geburtsdatum angegeben";
    }//from  w  w w . j av a  2  s  . c o  m
    long patientAgeDays = patient.getAgeAt(consDate, ChronoUnit.DAYS);

    List<TarmedLeistungAge> ageLimits = TarmedLeistungAge.of(limitsString, consDate);
    for (TarmedLeistungAge tarmedLeistungAge : ageLimits) {
        if (tarmedLeistungAge.isValidOn(consDate.toLocalDate())) {
            // if only one of the limits is set, check only that limit
            if (tarmedLeistungAge.getFromDays() >= 0 && !(tarmedLeistungAge.getToDays() >= 0)) {
                if (patientAgeDays < tarmedLeistungAge.getFromDays()) {
                    return "Patient ist zu jung, verrechenbar ab " + tarmedLeistungAge.getFromText();
                }
            } else if (tarmedLeistungAge.getToDays() >= 0 && !(tarmedLeistungAge.getFromDays() >= 0)) {
                if (patientAgeDays > tarmedLeistungAge.getToDays()) {
                    return "Patient ist zu alt, verrechenbar bis " + tarmedLeistungAge.getToText();
                }
            } else if (tarmedLeistungAge.getToDays() >= 0 && tarmedLeistungAge.getFromDays() >= 0) {
                if (tarmedLeistungAge.getToDays() < tarmedLeistungAge.getFromDays()) {
                    if (patientAgeDays > tarmedLeistungAge.getToDays()
                            && patientAgeDays < tarmedLeistungAge.getFromDays()) {
                        return "Patienten Alter nicht ok, verrechenbar " + tarmedLeistungAge.getText();
                    }
                } else {
                    if (patientAgeDays > tarmedLeistungAge.getToDays()
                            || patientAgeDays < tarmedLeistungAge.getFromDays()) {
                        return "Patienten Alter nicht ok, verrechenbar " + tarmedLeistungAge.getText();
                    }
                }
            }
        }
    }
    return null;
}

From source file:nu.yona.server.analysis.service.ActivityUpdateServiceTest.java

private DayActivity mockExistingActivities(Goal forGoal, Activity... activities) {
    LocalDateTime startTime = activities[0].getStartTime();
    DayActivity dayActivity = DayActivity.createInstance(userAnonEntity, forGoal, userAnonZoneId,
            startTime.truncatedTo(ChronoUnit.DAYS).toLocalDate());
    Arrays.asList(activities).forEach(a -> dayActivity.addActivity(a));
    ActivityDto existingActivity = ActivityDto.createInstance(activities[activities.length - 1]);
    when(mockDayActivityRepository.findOne(userAnonId, dayActivity.getStartDate(), forGoal.getId()))
            .thenReturn(dayActivity);//from  w  ww  . j  av  a 2 s .com
    when(mockAnalysisEngineCacheService.fetchLastActivityForUser(userAnonId, deviceAnonId, forGoal.getId()))
            .thenReturn(existingActivity);
    WeekActivity weekActivity = WeekActivity.createInstance(userAnonEntity, forGoal, userAnonZoneId,
            TimeUtil.getStartOfWeek(startTime.toLocalDate()));
    weekActivity.addDayActivity(dayActivity);
    forGoal.addWeekActivity(weekActivity);
    return dayActivity;
}

From source file:com.orange.cepheus.broker.controller.NgsiControllerTest.java

@Test
public void postUpdateContextWithoutProvidingApplicationAndWithEmptyRemoteBrokerButWithNotify()
        throws Exception {

    when(configuration.getRemoteUrl()).thenReturn("");

    //localRegistrations mock return always without providingApplication
    when(providingApplication.hasNext()).thenReturn(false);
    when(localRegistrations.findProvidingApplication(any(), any())).thenReturn(providingApplication);

    //subscriptions mock return always with matched subscriptions
    when(matchedSubscriptions.hasNext()).thenReturn(true, false);
    SubscribeContext subscribeContext = createSubscribeContextTemperature();
    Subscription subscription = new Subscription("999999", Instant.now().plus(1, ChronoUnit.DAYS),
            subscribeContext);/*from   ww w . j  a  v  a 2s  . c  o  m*/
    when(matchedSubscriptions.next()).thenReturn(subscription);
    when(subscriptions.findSubscriptions(any(), any())).thenReturn(matchedSubscriptions);

    //ngsiclient mock return always createUpdateContextREsponseTemperature when call updateContext
    when(ngsiClient.updateContext(any(), any(), any())).thenReturn(updateContextResponseListenableFuture);

    //ngsiClient mock return always CODE_200
    when(ngsiClient.notifyContext(any(), any(), any())).thenReturn(notifyContextResponseListenableFuture);

    mockMvc.perform(post("/v1/updateContext").content(json(mapper, createUpdateContextTempSensorAndPressure()))
            .contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk())
            .andExpect(MockMvcResultMatchers.jsonPath("$.errorCode").doesNotExist())
            .andExpect(MockMvcResultMatchers.jsonPath("$.contextElementResponses[0].contextElement.id")
                    .value("S1"))
            .andExpect(MockMvcResultMatchers.jsonPath("$.contextElementResponses[0].contextElement.type")
                    .value("TempSensor"))
            .andExpect(MockMvcResultMatchers
                    .jsonPath("$.contextElementResponses[0].contextElement.attributes[0].name").value("temp"))
            .andExpect(MockMvcResultMatchers
                    .jsonPath("$.contextElementResponses[0].contextElement.attributes[0].type").value("float"))
            .andExpect(MockMvcResultMatchers
                    .jsonPath("$.contextElementResponses[0].contextElement.attributes[0].value").value("15.5"))
            .andExpect(MockMvcResultMatchers
                    .jsonPath("$.contextElementResponses[0].contextElement.attributes[1].name")
                    .value("pressure"))
            .andExpect(MockMvcResultMatchers
                    .jsonPath("$.contextElementResponses[0].contextElement.attributes[1].type").value("int"))
            .andExpect(MockMvcResultMatchers
                    .jsonPath("$.contextElementResponses[0].contextElement.attributes[1].value").value("1015"))
            .andExpect(MockMvcResultMatchers.jsonPath("$.contextElementResponses[0].statusCode.code")
                    .value("200"));

    //Capture attributes (Set<String> searchAttributes) when findProvidingApplication is called on localRegistrations Set<String> searchAttributes
    verify(localRegistrations).findProvidingApplication(entityIdArgumentCaptor.capture(),
            attributeArgumentCaptor.capture());

    //check entityId
    assertEquals("S1", entityIdArgumentCaptor.getValue().getId());
    assertEquals("TempSensor", entityIdArgumentCaptor.getValue().getType());
    assertFalse(entityIdArgumentCaptor.getValue().getIsPattern());

    //check attributes
    assertEquals(2, attributeArgumentCaptor.getValue().size());
    assertTrue(attributeArgumentCaptor.getValue().contains("temp"));
    assertTrue(attributeArgumentCaptor.getValue().contains("pressure"));

    //check ListenableFuture is called never and with addCallback method
    verify(updateContextResponseListenableFuture, never()).addCallback(any(), any());

    //verify ngsiClient.updateContext is never called
    verify(ngsiClient, never()).updateContext(any(), any(), any());

    //check ngsiClient.notify is called at least once
    // Capture notifyContext when postNotifyContextRequest is called on updateContextRequest,
    ArgumentCaptor<NotifyContext> notifyContextArg = ArgumentCaptor.forClass(NotifyContext.class);
    verify(notifyContextResponseListenableFuture, atLeastOnce()).addCallback(any(), any());
    String urlReference = subscribeContext.getReference().toString();
    verify(ngsiClient, atLeastOnce()).notifyContext(eq(urlReference), any(), notifyContextArg.capture());
    // Check id and status correspond to the required
    assertEquals(1, notifyContextArg.getValue().getContextElementResponseList().size());
    ContextElementResponse contextElementResponse = notifyContextArg.getValue().getContextElementResponseList()
            .get(0);
    assertEquals("S1", contextElementResponse.getContextElement().getEntityId().getId());
    assertEquals("200", contextElementResponse.getStatusCode().getCode());
}

From source file:nu.yona.server.analysis.service.ActivityService.java

private DayActivityDto getDayActivityDetail(UUID userId, UUID userAnonymizedId, LocalDate date, UUID goalId,
        Set<IntervalInactivityDto> missingInactivities) {
    UserAnonymizedDto userAnonymized = userAnonymizedService.getUserAnonymized(userAnonymizedId);
    DayActivity dayActivityEntity = dayActivityRepository.findOne(userAnonymizedId, date, goalId);
    if (dayActivityEntity == null) {
        return getMissingInactivity(userId, date, goalId, userAnonymized, ChronoUnit.DAYS,
                (goal, startOfDay) -> createDayInactivity(userAnonymized, goal, startOfDay,
                        LevelOfDetail.DAY_DETAIL, missingInactivities));
    }//from www  .  ja  va  2  s.c  o m
    return DayActivityDto.createInstance(dayActivityEntity, LevelOfDetail.DAY_DETAIL);
}

From source file:com.orange.cepheus.broker.controller.NgsiControllerTest.java

@Test
public void postUpdateContextWithoutProvidingApplicationAndWithoutRemoteBrokerButWithNullOriginator()
        throws Exception {

    when(configuration.getRemoteUrl()).thenReturn(null);
    when(configuration.getLocalUrl()).thenReturn(null);

    //localRegistrations mock return always without providingApplication
    when(providingApplication.hasNext()).thenReturn(false);
    when(localRegistrations.findProvidingApplication(any(), any())).thenReturn(providingApplication);

    //subscriptions mock return always with matched subscriptions
    when(matchedSubscriptions.hasNext()).thenReturn(true, false);
    SubscribeContext subscribeContext = createSubscribeContextTemperature();
    Subscription subscription = new Subscription("999999", Instant.now().plus(1, ChronoUnit.DAYS),
            subscribeContext);/*from   ww  w .j  av a 2  s  .c om*/
    when(matchedSubscriptions.next()).thenReturn(subscription);
    when(subscriptions.findSubscriptions(any(), any())).thenReturn(matchedSubscriptions);

    //ngsiclient mock return always createUpdateContextREsponseTemperature when call updateContext
    when(ngsiClient.updateContext(any(), any(), any())).thenReturn(updateContextResponseListenableFuture);

    //ngsiClient mock return always CODE_200
    when(ngsiClient.notifyContext(any(), any(), any())).thenReturn(notifyContextResponseListenableFuture);

    mockMvc.perform(post("/v1/updateContext").content(json(mapper, createUpdateContextTempSensorAndPressure()))
            .contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk())
            .andExpect(MockMvcResultMatchers.jsonPath("$.errorCode").doesNotExist())
            .andExpect(MockMvcResultMatchers.jsonPath("$.contextElementResponses[0].contextElement.id")
                    .value("S1"))
            .andExpect(MockMvcResultMatchers.jsonPath("$.contextElementResponses[0].contextElement.type")
                    .value("TempSensor"))
            .andExpect(MockMvcResultMatchers
                    .jsonPath("$.contextElementResponses[0].contextElement.attributes[0].name").value("temp"))
            .andExpect(MockMvcResultMatchers
                    .jsonPath("$.contextElementResponses[0].contextElement.attributes[0].type").value("float"))
            .andExpect(MockMvcResultMatchers
                    .jsonPath("$.contextElementResponses[0].contextElement.attributes[0].value").value("15.5"))
            .andExpect(MockMvcResultMatchers
                    .jsonPath("$.contextElementResponses[0].contextElement.attributes[1].name")
                    .value("pressure"))
            .andExpect(MockMvcResultMatchers
                    .jsonPath("$.contextElementResponses[0].contextElement.attributes[1].type").value("int"))
            .andExpect(MockMvcResultMatchers
                    .jsonPath("$.contextElementResponses[0].contextElement.attributes[1].value").value("1015"))
            .andExpect(MockMvcResultMatchers.jsonPath("$.contextElementResponses[0].statusCode.code")
                    .value("200"));

    //Capture attributes (Set<String> searchAttributes) when findProvidingApplication is called on localRegistrations Set<String> searchAttributes
    verify(localRegistrations).findProvidingApplication(entityIdArgumentCaptor.capture(),
            attributeArgumentCaptor.capture());

    //check entityId
    assertEquals("S1", entityIdArgumentCaptor.getValue().getId());
    assertEquals("TempSensor", entityIdArgumentCaptor.getValue().getType());
    assertFalse(entityIdArgumentCaptor.getValue().getIsPattern());

    //check attributes
    assertEquals(2, attributeArgumentCaptor.getValue().size());
    assertTrue(attributeArgumentCaptor.getValue().contains("temp"));
    assertTrue(attributeArgumentCaptor.getValue().contains("pressure"));

    //check ListenableFuture is called never and with addCallback method
    verify(updateContextResponseListenableFuture, never()).addCallback(any(), any());

    //verify ngsiClient.updateContext is never called
    verify(ngsiClient, never()).updateContext(any(), any(), any());

    //check ngsiClient.notify is never called
    verify(notifyContextResponseListenableFuture, never()).addCallback(any(), any());
    verify(ngsiClient, never()).notifyContext(any(), any(), any());
}

From source file:nu.yona.server.analysis.service.AnalysisEngineServiceTest.java

@Test
public void analyze_crossDayAppActivity_twoDayActivitiesCreated() {
    ZonedDateTime endTime = now();
    JUnitUtil.skipBefore("Skip shortly after midnight", endTime, 0, 5);
    ZonedDateTime startTime = endTime.minusDays(1);

    service.analyze(userAnonId, deviceAnonId, createSingleAppActivity("Poker App", startTime, endTime));

    ArgumentCaptor<ActivityPayload> activityPayloadCaptor = ArgumentCaptor.forClass(ActivityPayload.class);
    verify(mockActivityUpdater, times(2)).addActivity(any(), activityPayloadCaptor.capture(),
            eq(GoalDto.createInstance(gamblingGoal)), any());
    List<ActivityPayload> payloads = activityPayloadCaptor.getAllValues();
    assertThat(payloads.size(), equalTo(2));
    assertThat(payloads.get(0).startTime, equalTo(startTime));
    assertThat(payloads.get(0).endTime, equalTo(endTime.truncatedTo(ChronoUnit.DAYS)));
    assertThat(payloads.get(1).startTime, equalTo(endTime.truncatedTo(ChronoUnit.DAYS)));
    assertThat(payloads.get(1).endTime, equalTo(endTime));
    verify(mockActivityUpdater, never()).updateTimeExistingActivity(any(), any());
    verify(mockActivityUpdater, never()).updateTimeLastActivity(any(), any(), any());
}

From source file:alfio.manager.TicketReservationManager.java

public static int getOfflinePaymentWaitingPeriod(Event event, ConfigurationManager configurationManager) {
    ZonedDateTime now = ZonedDateTime.now(event.getZoneId());
    ZonedDateTime eventBegin = event.getBegin();
    int daysToBegin = (int) ChronoUnit.DAYS.between(now.toLocalDate(), eventBegin.toLocalDate());
    if (daysToBegin < 0) {
        throw new OfflinePaymentException("Cannot confirm an offline reservation after event start");
    }/*from w w w . ja va 2  s  .c  o  m*/
    int waitingPeriod = configurationManager.getIntConfigValue(
            Configuration.from(event.getOrganizationId(), event.getId(), OFFLINE_PAYMENT_DAYS), 5);
    return Math.min(daysToBegin, waitingPeriod);
}

From source file:com.orange.cepheus.broker.controller.NgsiControllerTest.java

@Test
public void postUpdateContextWithoutProvidingApplicationAndWithoutRemoteBrokerButWithEmptyOriginator()
        throws Exception {

    when(configuration.getRemoteUrl()).thenReturn(null);
    when(configuration.getLocalUrl()).thenReturn("");

    //localRegistrations mock return always without providingApplication
    when(providingApplication.hasNext()).thenReturn(false);
    when(localRegistrations.findProvidingApplication(any(), any())).thenReturn(providingApplication);

    //subscriptions mock return always with matched subscriptions
    when(matchedSubscriptions.hasNext()).thenReturn(true, false);
    SubscribeContext subscribeContext = createSubscribeContextTemperature();
    Subscription subscription = new Subscription("999999", Instant.now().plus(1, ChronoUnit.DAYS),
            subscribeContext);//from ww  w. ja v  a2s . co  m
    when(matchedSubscriptions.next()).thenReturn(subscription);
    when(subscriptions.findSubscriptions(any(), any())).thenReturn(matchedSubscriptions);

    //ngsiclient mock return always createUpdateContextREsponseTemperature when call updateContext
    when(ngsiClient.updateContext(any(), any(), any())).thenReturn(updateContextResponseListenableFuture);

    //ngsiClient mock return always CODE_200
    when(ngsiClient.notifyContext(any(), any(), any())).thenReturn(notifyContextResponseListenableFuture);

    mockMvc.perform(post("/v1/updateContext").content(json(mapper, createUpdateContextTempSensorAndPressure()))
            .contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk())
            .andExpect(MockMvcResultMatchers.jsonPath("$.errorCode").doesNotExist())
            .andExpect(MockMvcResultMatchers.jsonPath("$.contextElementResponses[0].contextElement.id")
                    .value("S1"))
            .andExpect(MockMvcResultMatchers.jsonPath("$.contextElementResponses[0].contextElement.type")
                    .value("TempSensor"))
            .andExpect(MockMvcResultMatchers
                    .jsonPath("$.contextElementResponses[0].contextElement.attributes[0].name").value("temp"))
            .andExpect(MockMvcResultMatchers
                    .jsonPath("$.contextElementResponses[0].contextElement.attributes[0].type").value("float"))
            .andExpect(MockMvcResultMatchers
                    .jsonPath("$.contextElementResponses[0].contextElement.attributes[0].value").value("15.5"))
            .andExpect(MockMvcResultMatchers
                    .jsonPath("$.contextElementResponses[0].contextElement.attributes[1].name")
                    .value("pressure"))
            .andExpect(MockMvcResultMatchers
                    .jsonPath("$.contextElementResponses[0].contextElement.attributes[1].type").value("int"))
            .andExpect(MockMvcResultMatchers
                    .jsonPath("$.contextElementResponses[0].contextElement.attributes[1].value").value("1015"))
            .andExpect(MockMvcResultMatchers.jsonPath("$.contextElementResponses[0].statusCode.code")
                    .value("200"));

    //Capture attributes (Set<String> searchAttributes) when findProvidingApplication is called on localRegistrations Set<String> searchAttributes
    verify(localRegistrations).findProvidingApplication(entityIdArgumentCaptor.capture(),
            attributeArgumentCaptor.capture());

    //check entityId
    assertEquals("S1", entityIdArgumentCaptor.getValue().getId());
    assertEquals("TempSensor", entityIdArgumentCaptor.getValue().getType());
    assertFalse(entityIdArgumentCaptor.getValue().getIsPattern());

    //check attributes
    assertEquals(2, attributeArgumentCaptor.getValue().size());
    assertTrue(attributeArgumentCaptor.getValue().contains("temp"));
    assertTrue(attributeArgumentCaptor.getValue().contains("pressure"));

    //check ListenableFuture is called never and with addCallback method
    verify(updateContextResponseListenableFuture, never()).addCallback(any(), any());

    //verify ngsiClient.updateContext is never called
    verify(ngsiClient, never()).updateContext(any(), any(), any());

    //check ngsiClient.notify is never called
    verify(notifyContextResponseListenableFuture, never()).addCallback(any(), any());
    verify(ngsiClient, never()).notifyContext(any(), any(), any());
}

From source file:alfio.manager.EventManager.java

private Stream<Event> getActiveEventsStream() {
    return eventRepository.findAll().stream().filter(e -> e.getEnd().truncatedTo(ChronoUnit.DAYS).plusDays(1)
            .isAfter(ZonedDateTime.now(e.getZoneId()).truncatedTo(ChronoUnit.DAYS)));
}

From source file:alfio.manager.TicketReservationManager.java

private static Predicate<TicketReservation> notificationNotSent(ZoneId eventZoneId, int quietPeriod) {
    return r -> r.latestNotificationTimestamp(eventZoneId).map(t -> t.truncatedTo(ChronoUnit.DAYS)
            .plusDays(quietPeriod).isBefore(ZonedDateTime.now(eventZoneId).truncatedTo(ChronoUnit.DAYS)))
            .orElse(true);/*from  www .  j a  v  a  2  s  .c om*/
}