List of usage examples for java.time LocalDateTime toLocalDate
@Override
public LocalDate toLocalDate()
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 www. j a v a2 s.c o m 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: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 ww.j a v 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:de.steilerdev.myVerein.server.controller.admin.EventManagementController.java
/** * Returns all events, that are taking place on a specified date. The date parameter needs to be formatted according to the following pattern: YYYY/MM/DD. This function is invoked by GETting the URI /api/admin/event/date * @param date The selected date, correctly formatted (YYYY/MM/DD) * @return An HTTP response with a status code. If the function succeeds, a list of events is returned, otherwise an error code is returned. *///from ww w . j a v a 2 s.c om @RequestMapping(value = "date", produces = "application/json", method = RequestMethod.GET) public ResponseEntity<List<Event>> getEventsOfDate(@RequestParam String date, @CurrentUser User currentUser) { logger.trace("[" + currentUser + "] Getting events of date " + date); LocalDateTime startOfDay, endOfDay, startOfMonth, endOfMonth; ArrayList<Event> eventsOfDay = new ArrayList<>(); try { // Get start of day and start of next day startOfDay = LocalDate.parse(date, DateTimeFormatter.ISO_LOCAL_DATE).atStartOfDay(); endOfDay = startOfDay.plusDays(1); startOfMonth = LocalDate.of(startOfDay.getYear(), startOfDay.getMonth(), 1).atStartOfDay(); endOfMonth = startOfMonth.plusMonths(1); logger.debug("[" + currentUser + "] Converted to date object: " + startOfDay.toString()); } catch (DateTimeParseException e) { logger.warn("[" + currentUser + "] Unable to parse date: " + date + ": " + e.toString()); return new ResponseEntity<>(HttpStatus.BAD_REQUEST); } logger.debug("Getting all single day events..."); eventsOfDay.addAll(eventRepository.findAllByStartDateTimeBetweenAndMultiDate(startOfDay, endOfDay, false)); logger.debug("All single day events retrieved, got " + eventsOfDay.size() + " events so far"); logger.debug("Getting all multi day events..."); //Collecting all multi date events, that either start or end within the selected month (which means that events that are spanning over several months are not collected) eventsOfDay.addAll(Stream.concat( eventRepository.findAllByStartDateTimeBetweenAndMultiDate(startOfMonth, endOfMonth, true).stream(), //All multi date events starting within the month eventRepository.findAllByEndDateTimeBetweenAndMultiDate(startOfMonth, endOfMonth, true).stream()) //All multi date events ending within the month .distinct() //Removing all duplicated events .parallel() .filter(event -> event.getStartDate().isEqual(startOfDay.toLocalDate()) || event.getEndDate().isEqual(startOfDay.toLocalDate()) || (event.getEndDate().isAfter(endOfDay.toLocalDate()) && event.getStartDate().isBefore(startOfDay.toLocalDate()))) //Filter all multi date events that do not span over the date .collect(Collectors.toList())); logger.debug("All multi day events gathered, got " + eventsOfDay.size() + " events so far"); if (eventsOfDay.isEmpty()) { logger.warn("[" + currentUser + "] The events list of " + date + " is empty"); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } else { eventsOfDay.replaceAll(Event::getSendingObjectOnlyNameTimeId); logger.debug("[" + currentUser + "] Returning " + eventsOfDay.size() + " events for " + date); return new ResponseEntity<>(eventsOfDay, HttpStatus.OK); } }
From source file:net.resheim.eclipse.timekeeper.ui.Activator.java
/** * Must be called by the UI-thread//from w w w . j av a 2 s. c o m * * @param idleTimeMillis */ private void handleReactivation(long idleTimeMillis) { // We want only one dialog open. if (dialogIsOpen) { return; } synchronized (this) { if (idleTimeMillis < lastIdleTime && lastIdleTime > IDLE_INTERVAL) { // If we have an active task ITask task = TasksUi.getTaskActivityManager().getActiveTask(); if (task != null && Activator.getValue(task, Activator.START) != null) { dialogIsOpen = true; String tickString = Activator.getValue(task, Activator.TICK); LocalDateTime started = getActiveSince(); LocalDateTime ticked = LocalDateTime.parse(tickString); LocalDateTime lastTick = ticked; // Subtract the IDLE_INTERVAL time the computer _was_ // idle while counting up to the threshold. During this // period fields were updated. Thus must be adjusted for. ticked = ticked.minusNanos(IDLE_INTERVAL); String time = DurationFormatUtils.formatDuration(lastIdleTime, "H:mm:ss", true); StringBuilder sb = new StringBuilder(); if (task.getTaskKey() != null) { sb.append(task.getTaskKey()); sb.append(": "); } sb.append(task.getSummary()); MessageDialog md = new MessageDialog(Display.getCurrent().getActiveShell(), "Disregard idle time?", null, MessageFormat.format( "The computer has been idle since {0}, more than {1}. The active task \"{2}\" was started on {3}. Deactivate the task and disregard the idle time?", ticked.format(DateTimeFormatter.ofPattern("EEE e, HH:mm:ss", Locale.US)), time, sb.toString(), started.format(DateTimeFormatter.ofPattern("EEE e, HH:mm:ss", Locale.US))), MessageDialog.QUESTION, new String[] { "No", "Yes" }, 1); int open = md.open(); dialogIsOpen = false; if (open == 1) { // Stop task, subtract initial idle time TasksUi.getTaskActivityManager().deactivateTask(task); reduceTime(task, ticked.toLocalDate().toString(), IDLE_INTERVAL / 1000); } else { // Continue task, add idle time LocalDateTime now = LocalDateTime.now(); long seconds = lastTick.until(now, ChronoUnit.MILLIS); accumulateTime(task, ticked.toLocalDate().toString(), seconds); Activator.setValue(task, Activator.TICK, now.toString()); } } } } }
From source file:org.apache.tez.dag.history.logging.proto.DagManifesFileScanner.java
private boolean loadMore() throws IOException { LocalDateTime now = manifestLogger.getNow(); LocalDate today = now.toLocalDate(); String todayDir = manifestLogger.getDirForDate(today); loadNewFiles(todayDir);//from w w w . j av a 2 s . c o m while (newFiles.isEmpty()) { if (now.getHour() * 3600 + now.getMinute() * 60 + now.getSecond() < syncTime) { // We are in the delay window for today, do not advance date if we are moving from // yesterday. if (scanDir.equals(manifestLogger.getDirForDate(today.minusDays(1)))) { return false; } } String nextDir = manifestLogger.getNextDirectory(scanDir); if (nextDir == null) { return false; } scanDir = nextDir; offsets = new HashMap<>(); retryCount = new HashMap<>(); loadNewFiles(todayDir); } return true; }
From source file:org.darkware.wpman.util.TimeWindow.java
/** * Calculates the next time when a given hour and minute occur, based from the given start time. * * @param after The time to start searching from. * @param hour The hour to search for.//from w w w. ja v a 2 s .co m * @param minute The minute to search for. * @return A {@code DateTime} corresponding to the hour and minute declared which is explicitly after * the start time. */ public static LocalDateTime nextTime(final LocalDateTime after, final int hour, final int minute) { LocalTime time = LocalTime.of(hour, minute); LocalDate afterDate = after.toLocalDate(); if (!time.isAfter(after.toLocalTime())) afterDate = afterDate.plus(1, ChronoUnit.DAYS); return time.atDate(afterDate); }
From source file:org.ojbc.adapters.analyticsstaging.custody.processor.AbstractReportRepositoryProcessor.java
protected CustodyRelease processCustodyReleaseInfo(Node parentNode, Integer bookingId, String bookingNumber) throws Exception { String supervisionReleaseDateTimeString = XmlUtils.xPathStringSearch(parentNode, "jxdm51:Detention/jxdm51:SupervisionAugmentation/jxdm51:SupervisionReleaseDate/nc30:DateTime"); LocalDateTime supervisionReleaseDateTime = parseLocalDateTime(supervisionReleaseDateTimeString); CustodyRelease custodyRelease = new CustodyRelease(); if (supervisionReleaseDateTime != null) { custodyRelease.setReleaseDate(supervisionReleaseDateTime.toLocalDate()); custodyRelease.setReleaseTime(supervisionReleaseDateTime.toLocalTime()); } else {/*w w w .j ava 2s . co m*/ String releaseDateString = XmlUtils.xPathStringSearch(parentNode, "jxdm51:Detention/jxdm51:SupervisionAugmentation/jxdm51:SupervisionReleaseDate/nc30:Date"); custodyRelease.setReleaseDate(parseLocalDate(releaseDateString)); } if (custodyRelease.getReleaseDate() != null) { custodyRelease.setBookingId(bookingId); custodyRelease.setBookingNumber(bookingNumber); analyticalDatastoreDAO.saveCustodyRelease(custodyRelease); } return custodyRelease; }
From source file:org.ojbc.adapters.analyticsstaging.custody.processor.BookingReportProcessor.java
@Transactional private Booking processBookingReport(Document report) throws Exception { Node bookingReportNode = XmlUtils.xPathNodeSearch(report, "/br-doc:BookingReport"); String bookingNumber = XmlUtils.xPathStringSearch(bookingReportNode, "jxdm51:Booking/jxdm51:BookingAgencyRecordIdentification/nc30:IdentificationID"); checkBookingNumber(bookingNumber);// w w w.jav a2 s.c o m Booking booking = new Booking(); booking.setBookingNumber(bookingNumber); Integer personId = processPersonAndBehavioralHealthInfo(report); booking.setPersonId(personId); String bookingDateTimeString = XmlUtils.xPathStringSearch(bookingReportNode, "jxdm51:Booking/nc30:ActivityDate/nc30:DateTime"); LocalDateTime bookingDateTime = parseLocalDateTime(bookingDateTimeString); if (bookingDateTime != null) { booking.setBookingDate(bookingDateTime.toLocalDate()); booking.setBookingTime(bookingDateTime.toLocalTime()); } else { String bookingDateString = XmlUtils.xPathStringSearch(bookingReportNode, "jxdm51:Booking/nc30:ActivityDate/nc30:Date"); booking.setBookingDate(parseLocalDate(bookingDateString)); } String facility = XmlUtils.xPathStringSearch(bookingReportNode, "jxdm51:Booking/jxdm51:BookingDetentionFacility/nc30:FacilityIdentification/nc30:IdentificationID"); Integer facilityId = descriptionCodeLookupService.retrieveCode(CodeTable.Facility, facility); booking.setFacilityId(facilityId); String supervisionUnitType = XmlUtils.xPathStringSearch(bookingReportNode, "jxdm51:Detention/jxdm51:SupervisionAugmentation/jxdm51:SupervisionAreaIdentification/nc30:IdentificationID"); Integer supervisionUnitTypeId = descriptionCodeLookupService.retrieveCode(CodeTable.SupervisionUnitType, supervisionUnitType); booking.setSupervisionUnitTypeId(supervisionUnitTypeId); String supervisionReleaseEligibilityDate = XmlUtils.xPathStringSearch(bookingReportNode, "jxdm51:Detention/jxdm51:SupervisionAugmentation/jxdm51:SupervisionReleaseEligibilityDate/nc30:Date"); booking.setScheduledReleaseDate(parseLocalDate(supervisionReleaseEligibilityDate)); String inmateJailResidentIndicator = XmlUtils.xPathStringSearch(bookingReportNode, "jxdm51:Detention/br-ext:InmateJailResidentIndicator"); booking.setInmateJailResidentIndicator(BooleanUtils.toBooleanObject(inmateJailResidentIndicator)); Integer bookingId = analyticalDatastoreDAO.saveBooking(booking); booking.setBookingId(bookingId); processCustodyReleaseInfo(bookingReportNode, bookingId, bookingNumber); return booking; }
From source file:org.ojbc.adapters.analyticsstaging.custody.processor.CustodyReleaseReportProcessor.java
@Transactional(rollbackFor = Exception.class) public void processReport(Document report) throws Exception { log.info("Processing Custody Release report."); CustodyRelease custodyRelease = new CustodyRelease(); Node bookingNode = XmlUtils.xPathNodeSearch(report, "/crr-exc:CustodyReleaseReport/crr-ext:Custody/jxdm51:Booking"); String bookingNumber = XmlUtils.xPathStringSearch(bookingNode, "jxdm51:BookingAgencyRecordIdentification/nc30:IdentificationID"); Integer bookingId = getBookingIdByBookingNumber(bookingNumber); custodyRelease.setBookingId(bookingId); String releaseCondition = XmlUtils.xPathStringSearch(bookingNode, "following-sibling::nc30:Release/crr-ext:ReleaseCondition/nc30:ActivityDescriptionText"); custodyRelease.setReleaseCondition(releaseCondition); String releaseDateTimeString = XmlUtils.xPathStringSearch(bookingNode, "following-sibling::nc30:Release/nc30:ActivityDate/nc30:DateTime"); LocalDateTime releaseDateTime = parseLocalDateTime(releaseDateTimeString); if (releaseDateTime != null) { custodyRelease.setReleaseDate(releaseDateTime.toLocalDate()); custodyRelease.setReleaseTime(releaseDateTime.toLocalTime()); } else {//from ww w . ja v a 2 s. c o m String releaseDateString = XmlUtils.xPathStringSearch(bookingNode, "following-sibling::nc30:Release/nc30:ActivityDate/nc30:Date"); custodyRelease.setReleaseDate(parseLocalDate(releaseDateString)); } custodyRelease.setBookingNumber(bookingNumber); analyticalDatastoreDAO.saveCustodyRelease(custodyRelease); processBehavioralHealthInfo(report); log.info("Processed Custody Release report successfully."); }
From source file:org.ojbc.adapters.analyticsstaging.custody.processor.CustodyStatusChangeReportProcessor.java
@Transactional private Integer processCustodyStatusChangeReport(Document report) throws Exception { CustodyStatusChange custodyStatusChange = new CustodyStatusChange(); Node personNode = XmlUtils.xPathNodeSearch(report, "/cscr-doc:CustodyStatusChangeReport/cscr-ext:Custody/nc30:Person"); Node custodyNode = XmlUtils.xPathNodeSearch(report, "/cscr-doc:CustodyStatusChangeReport/cscr-ext:Custody"); String bookingNumber = XmlUtils.xPathStringSearch(custodyNode, "jxdm51:Booking/jxdm51:BookingAgencyRecordIdentification/nc30:IdentificationID"); custodyStatusChange.setBookingNumber(bookingNumber); Integer bookingId = getBookingIdByBookingNumber(bookingNumber); custodyStatusChange.setBookingId(bookingId); Integer personId = processPersonAndBehavioralHealthInfo(personNode, bookingNumber); custodyStatusChange.setPersonId(personId); String bookingDateTimeString = XmlUtils.xPathStringSearch(custodyNode, "jxdm51:Booking/nc30:ActivityDate/nc30:DateTime"); LocalDateTime bookingDateTime = parseLocalDateTime(bookingDateTimeString); if (bookingDateTime != null) { custodyStatusChange.setBookingDate(bookingDateTime.toLocalDate()); custodyStatusChange.setBookingTime(bookingDateTime.toLocalTime()); } else {// w w w . jav a2 s. co m String bookingDateString = XmlUtils.xPathStringSearch(custodyNode, "jxdm51:Booking/nc30:ActivityDate/nc30:Date"); custodyStatusChange.setBookingDate(parseLocalDate(bookingDateString)); } String facility = XmlUtils.xPathStringSearch(custodyNode, "jxdm51:Booking/jxdm51:BookingDetentionFacility/nc30:FacilityIdentification/nc30:IdentificationID"); Integer facilityId = descriptionCodeLookupService.retrieveCode(CodeTable.Facility, facility); custodyStatusChange.setFacilityId(facilityId); String supervisionUnitType = XmlUtils.xPathStringSearch(custodyNode, "jxdm51:Detention/jxdm51:SupervisionAugmentation/jxdm51:SupervisionAreaIdentification/nc30:IdentificationID"); Integer supervisionUnitTypeId = descriptionCodeLookupService.retrieveCode(CodeTable.SupervisionUnitType, supervisionUnitType); custodyStatusChange.setSupervisionUnitTypeId(supervisionUnitTypeId); String supervisionReleaseEligibilityDate = XmlUtils.xPathStringSearch(custodyNode, "jxdm51:Detention/jxdm51:SupervisionAugmentation/jxdm51:SupervisionReleaseEligibilityDate/nc30:Date"); custodyStatusChange.setScheduledReleaseDate(parseLocalDate(supervisionReleaseEligibilityDate)); String inmateJailResidentIndicator = XmlUtils.xPathStringSearch(custodyNode, "jxdm51:Detention/cscr-ext:InmateJailResidentIndicator"); custodyStatusChange .setInmateJailResidentIndicator(BooleanUtils.toBooleanObject(inmateJailResidentIndicator)); processCustodyReleaseInfo(custodyNode, bookingId, bookingNumber); Integer custodyStatusChangeId = analyticalDatastoreDAO.saveCustodyStatusChange(custodyStatusChange); return custodyStatusChangeId; }