List of usage examples for java.time LocalDateTime toString
@Override
public String toString()
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. jav a2s .c o m*/ @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
private void installTaxameter() { switch (Platform.getOS()) { case Platform.OS_MACOSX: detector = new MacIdleTimeDetector(); break;/*from w w w .j av a 2 s. c o m*/ case Platform.OS_LINUX: detector = new X11IdleTimeDetector(); break; case Platform.OS_WIN32: detector = new WindowsIdleTimeDetector(); break; default: detector = new GenericIdleTimeDetector(); break; } Timer timer = new Timer("Timekeeper", true); timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { if (!PlatformUI.getWorkbench().isClosing()) { long idleTimeMillis = detector.getIdleTimeMillis(); ITask task = TasksUi.getTaskActivityManager().getActiveTask(); if (null != task) { if (idleTimeMillis < lastIdleTime && lastIdleTime > IDLE_INTERVAL) { // Was idle on last check, reactivate Display.getDefault().syncExec(() -> handleReactivation(idleTimeMillis)); } else if (lastIdleTime < IDLE_INTERVAL) { String tickString = Activator.getValue(task, Activator.TICK); LocalDateTime now = LocalDateTime.now(); LocalDateTime ticked = LocalDateTime.parse(tickString); // Currently not idle so accumulate spent time accumulateTime(task, now.toLocalDate().toString(), ticked.until(now, ChronoUnit.MILLIS)); Activator.setValue(task, Activator.TICK, now.toString()); } } lastIdleTime = idleTimeMillis; } } }, SHORT_INTERVAL, SHORT_INTERVAL); // Immediately run the idle handler if the system has been idle and // the user has pressed a key or mouse button _inside_ the running // application. reactivationListener = new Listener() { public void handleEvent(Event event) { long idleTimeMillis = detector.getIdleTimeMillis(); if (idleTimeMillis < lastIdleTime && lastIdleTime > IDLE_INTERVAL) { handleReactivation(idleTimeMillis); } lastIdleTime = idleTimeMillis; } }; final Display display = PlatformUI.getWorkbench().getDisplay(); display.addFilter(SWT.KeyUp, reactivationListener); display.addFilter(SWT.MouseUp, reactivationListener); }
From source file:controller.UpdateEC.java
private void insertedEvidence(ArrayList<FileItem> files, LocalDateTime now, ExtenuatingCircumstance inserted, Account studentAccount) throws SQLException { String fname;/*from w ww . ja va2 s . c o m*/ Evidence evidence = null; String destination = StringUtils.EMPTY; for (FileItem file : files) { try { evidence = new Evidence(); fname = new File(file.getName()).getName(); String ext = FilenameUtils.getExtension(fname); String newFilename = studentAccount.getUsername() + System.currentTimeMillis() + "." + ext; destination = Upload_Directory + File.separator + newFilename; System.out.println("destination: " + destination); file.write(new File(destination)); } catch (Exception ex) { Logger.getLogger(UpdateEC.class.getName()).log(Level.SEVERE, null, ex); } evidence.setFiles(destination); evidence.setEvidence_date(now.toString()); evidence.setEcId(inserted.getId()); new EvidenceDAO().insertEvidence(evidence); } }
From source file:controller.AddNewEC.java
private void insertedEvidence(ArrayList<FileItem> files, LocalDateTime now, ExtenuatingCircumstance inserted, Account studentAccount) throws SQLException { String fname;/*from w ww . ja va 2s.c o m*/ Evidence evidence = null; String destination = StringUtils.EMPTY; for (FileItem file : files) { try { evidence = new Evidence(); fname = new File(file.getName()).getName(); String ext = FilenameUtils.getExtension(fname); String newFilename = studentAccount.getUsername() + System.currentTimeMillis() + "." + ext; destination = Upload_Directory + File.separator + newFilename; System.out.println("destination: " + destination); file.write(new File(destination)); } catch (Exception ex) { Logger.getLogger(AddNewEC.class.getName()).log(Level.SEVERE, null, ex); } evidence.setFiles(destination); evidence.setEvidence_date(now.toString()); evidence.setEcId(inserted.getId()); Evidence insertedE = new EvidenceDAO().insertEvidence(evidence); } }
From source file:net.resheim.eclipse.timekeeper.internal.TaskActivationListener.java
@Override public void preTaskActivated(ITask task) { LocalDateTime now = LocalDateTime.now(); String startString = Activator.getValue(task, Activator.START); String tickString = Activator.getValue(task, Activator.TICK); if (startString != null) { LocalDateTime ticked = LocalDateTime.parse(tickString); LocalDateTime stopped = LocalDateTime.now(); long seconds = ticked.until(stopped, ChronoUnit.SECONDS); String time = DurationFormatUtils.formatDuration(seconds * 1000, "H:mm", true); boolean confirm = MessageDialog.openConfirm(Display.getCurrent().getActiveShell(), "Add elapsed time?", "Work was already started and task was last updated on " + ticked.format(DateTimeFormatter.ofPattern("EEE e, HH:mm", Locale.US)) + ". Continue and add the elapsed time since (" + time + ") to the task total?"); if (confirm) { Activator.accumulateTime(task, startString, ticked.until(LocalDateTime.now(), ChronoUnit.MILLIS)); }// w w w . ja va 2 s.c o m } Activator.setValue(task, Activator.TICK, now.toString()); Activator.setValue(task, Activator.START, now.toString()); }
From source file:org.cyclop.model.adapter.LocalDateTimeAdapter.java
@Override public String marshal(LocalDateTime val) throws Exception { if (val == null) { return null; }// www . j a v a 2 s . c om return val.toString(); }
From source file:org.wso2.security.tools.scanner.dependency.js.preprocessor.ResourceDownloader.java
/** * This method calculate and returns the no of days between published date of particular weekly release * and scan date (Current system date)./*w w w . jav a 2 s .com*/ * * @param releaseDate published date of particulae weekly release. * @return no of days between published date of particular weekly release * and scan date (Current system date) * @throws ParseException Exception occurred parsing the string to date format. */ long getDateDiffFromLastWeeklyRelease(String releaseDate) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH); LocalDateTime now = LocalDateTime.now(); Date firstDate = sdf.parse(releaseDate); Date secondDate = sdf.parse(now.toString()); long diffInMillis = Math.abs(secondDate.getTime() - firstDate.getTime()); return TimeUnit.DAYS.convert(diffInMillis, TimeUnit.MILLISECONDS); }