List of usage examples for java.time LocalDate plusDays
public LocalDate plusDays(long daysToAdd)
From source file:Main.java
public static LocalDate[] getWeekday(LocalDate date) { int DAYS_OF_WEEK = 7; if (date == null) { date = LocalDate.now();/*from w w w . ja va 2 s . c o m*/ } LocalDate begin = null; if (date.getDayOfWeek().equals(DayOfWeek.SUNDAY)) { begin = date; } else { begin = date.minusDays(date.getDayOfWeek().getValue()); } LocalDate end = begin.plusDays(DAYS_OF_WEEK - 1); LocalDate localDate[] = { begin, end }; return localDate; }
From source file:Main.java
public static List<LocalDate> getDatesFrom(Date startDate) { List<LocalDate> dates = new ArrayList<>(); LocalDate startLocalDate = getLocalDateFromDate(startDate); LocalDate endLocalDate = LocalDate.now(); dates.add(startLocalDate);/*from ww w. j a v a 2 s. c o m*/ for (int i = 0; i < ChronoUnit.DAYS.between(startLocalDate, endLocalDate); i++) { dates.add(startLocalDate.plusDays(i + 1)); } return dates; }
From source file:daylightchart.daylightchart.calculation.RiseSetUtility.java
/** * Generate a year's worth of dates// w w w . j ava2s . c o m * * @return All the dates for the year */ private static List<LocalDate> getYearsDates(final int year) { final List<LocalDate> dates = new ArrayList<LocalDate>(); LocalDate date = LocalDate.of(year, 1, 1); do { dates.add(date); date = date.plusDays(1); } while (!(date.getMonthValue() == 1 && date.getDayOfMonth() == 1)); return dates; }
From source file:org.silverpeas.core.calendar.CalendarEventOccurrence.java
/** * Gets optionally an event occurrence by its identifier. * <p>If the occurrence exists into the persistence, it is returned. Otherwise it is generated. * <p>Otherwise and if start date is valid, the occurrence is generated. * @param id the identifier of the aimed occurrence. * @return an optional calendar event occurrence. *//* ww w . j a va 2s . c o m*/ public static Optional<CalendarEventOccurrence> getById(final String id) { final CalendarEventOccurrenceRepository repository = CalendarEventOccurrenceRepository.get(); final Mutable<CalendarEventOccurrence> occurrence = Mutable.ofNullable(repository.getById(id)); if (!occurrence.isPresent()) { final Pair<String, Temporal> explodedId = explodeId(id); final String eventId = explodedId.getLeft(); final Temporal startDate = explodedId.getRight(); final Optional<CalendarEvent> event = Optional.ofNullable(CalendarEvent.getById(eventId)); event.ifPresent(e -> { if (e.isRecurrent()) { final LocalDate occStartDate; final LocalDate occEndDate; if (startDate instanceof LocalDate) { final LocalDate date = (LocalDate) startDate; occStartDate = date.minusDays(1); occEndDate = date.plusDays(1); } else { final OffsetDateTime dateTime = (OffsetDateTime) startDate; occStartDate = dateTime.minusDays(1).toLocalDate(); occEndDate = dateTime.plusDays(1).toLocalDate(); } final List<CalendarEventOccurrence> occurrences = e.getCalendar() .between(occStartDate, occEndDate).getEventOccurrences(); occurrences.removeIf(o -> !o.getCalendarEvent().getId().equals(eventId) || (!o.getStartDate().equals(startDate))); if (occurrences.size() == 1) { occurrence.set(occurrences.get(0)); } } else { occurrence.set(new CalendarEventOccurrence(e, e.getStartDate(), e.getEndDate())); } }); } return Optional.ofNullable(occurrence.orElse(null)); }
From source file:br.edu.ifpb.padroes.projeto.sisbiblioteca.model.EmprestimoBo.java
public void finalizaEmprestimo(Emprestimo emprestimo) throws EmprestimoAtrasadoException, EmprestimoJaFinalizadoException { try {//from w w w . ja v a2 s.c om emprestimo.finalizarEmprestimo(); finalizeEmprestimoOnDao(emprestimo); } catch (EmprestimoAtrasadoException ex) { LocalDate now = LocalDate.now(); Bloqueio bloqueio = new Bloqueio(now, now.plusDays(3), emprestimo.getAluno(), EstadoBloqueioEnum.ANDAMENTO); //insere o bloqueio! bloqueioDao.inserir(bloqueio); finalizeEmprestimoOnDao(emprestimo); throw new EmprestimoAtrasadoException("O Devoluo do emprstimo foi feita com sucesso" + " mas a entrega do mesmo atrasou. O Aluno ficar banido de realizar emprstimos" + " durante 3 dias! "); } }
From source file:org.openhab.binding.openuv.internal.handler.OpenUVBridgeHandler.java
public @Nullable OpenUVResult getUVData(String latitude, String longitude, @Nullable String altitude) { StringBuilder urlBuilder = new StringBuilder(BASE_URL).append("?lat=").append(latitude).append("&lng=") .append(longitude);//from ww w.jav a2 s .c o m if (altitude != null) { urlBuilder.append("&alt=").append(altitude); } String errorMessage = null; try { String jsonData = HttpUtil.executeUrl("GET", urlBuilder.toString(), header, null, null, REQUEST_TIMEOUT); OpenUVResponse uvResponse = gson.fromJson(jsonData, OpenUVResponse.class); if (uvResponse.getError() == null) { updateStatus(ThingStatus.ONLINE); return uvResponse.getResult(); } else { errorMessage = uvResponse.getError(); } } catch (IOException e) { errorMessage = e.getMessage(); } if (errorMessage.startsWith(ERROR_QUOTA_EXCEEDED)) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, errorMessage); LocalDate today = LocalDate.now(); LocalDate tomorrow = today.plusDays(1); LocalDateTime tomorrowMidnight = tomorrow.atStartOfDay().plusMinutes(2); logger.warn("Quota Exceeded, going OFFLINE for today, will retry at : {} ", tomorrowMidnight); scheduler.schedule(this::initiateConnexion, Duration.between(LocalDateTime.now(), tomorrowMidnight).toMinutes(), TimeUnit.MINUTES); } else if (errorMessage.startsWith(ERROR_WRONG_KEY)) { logger.error("Error occured during API query : {}", errorMessage); updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, errorMessage); } return null; }
From source file:br.edu.ifpb.padroes.projeto.sisbiblioteca.model.EmprestimoBo.java
public Emprestimo realizarEmprestimo(Aluno aluno, Livro livro, LocalDate startDate) throws LivroIndisponivelException, AlunoInabilitadoException { Emprestimo emprestimo = new Emprestimo(aluno, livro, startDate, startDate.plusDays(10), EstadoEmprestimoEnum.ANDAMENTO); emprestimo.processarEmprestimo();//from w ww. j a v a2 s. co m newEmprestimoOnDao(emprestimo); return emprestimo; }
From source file:org.openmrs.module.operationtheater.api.impl.OperationTheaterServiceImpl.java
@Override public Interval getLocationAvailableTime(Location location, LocalDate date) { Date date1 = Date.from(date.atStartOfDay(ZoneId.systemDefault()).toInstant()); Date date2 = Date.from(date.plusDays(1).atStartOfDay(ZoneId.systemDefault()).toInstant()); List<AppointmentBlock> blocks = appointmentService.getAppointmentBlocks(date1, date2, location.getId() + ",", null, null); // List<AppointmentBlock> blocks = new ArrayList<AppointmentBlock>(); if (blocks.size() == 1) { // return new Interval(new DateTime(blocks.get(0).getStartDate()), new DateTime(blocks.get(0).getEndDate())); Instant startInstant = LocalDateTime.from(blocks.get(0).getStartDate().toInstant()) .toInstant(ZoneOffset.UTC); Instant endInstant = LocalDateTime.from(blocks.get(0).getEndDate().toInstant()) .toInstant(ZoneOffset.UTC); return Interval.of(startInstant, endInstant); } else if (blocks.size() > 1) { throw new APIException("There shouldn't be multiple appointment blocks per location and date"); }//from w w w . j a v a 2 s . c o m DateTimeFormatter timeFormatter = OTMetadata.AVAILABLE_TIME_FORMATTER; LocalDateTime availableStart = null; LocalDateTime availableEnd = null; for (LocationAttribute attribute : location.getAttributes()) { if (attribute.getAttributeType().getUuid().equals(OTMetadata.DEFAULT_AVAILABLE_TIME_BEGIN_UUID)) { LocalTime beginTime = LocalTime.parse((String) attribute.getValue(), timeFormatter); // availableStart = date.withTime(beginTime.getHourOfDay(), beginTime.getMinuteOfHour(), 0, 0); availableStart = date.atTime(beginTime.getHour(), beginTime.getMinute()); } else if (attribute.getAttributeType().getUuid().equals(OTMetadata.DEFAULT_AVAILABLE_TIME_END_UUID)) { LocalTime endTime = LocalTime.parse((String) attribute.getValue(), timeFormatter); // availableEnd = date.withTime(endTime.getHourOfDay(), endTime.getMinuteOfHour(), 0, 0); availableEnd = date.atTime(endTime.getHour(), endTime.getMinute()); } } if (availableStart != null && availableEnd != null) { return Interval.of(availableStart.toInstant(ZoneOffset.UTC), availableEnd.toInstant(ZoneOffset.UTC)); } throw new APIException("Available times not defined. please make sure that the attributes " + "'default available time begin' and 'default available time end' for the location " + location.getName() + " are defined"); }
From source file:com.gigglinggnus.controllers.ManageExamsController.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { EntityManager em = (EntityManager) request.getSession().getAttribute("em"); Clock clk = (Clock) (request.getSession().getAttribute("clock")); List<Term> terms = Term.getFutureTerms(em, Instant.now(clk)); List<Exam> exams = terms.stream().flatMap(term -> term.getExams().stream()) .filter(exam -> exam.getStatus() == ExamStatus.PENDING).collect(Collectors.toList()); Map<Exam, ArrayList<String>> utilMap = new HashMap(); for (Exam e : exams) { Interval<Instant> examInt = e.getInterval(); LocalDate testDate = examInt.getStart().atZone(ZoneId.systemDefault()).toLocalDate(); LocalDate endDate = examInt.getEnd().atZone(ZoneId.systemDefault()).toLocalDate(); Term t = e.getTerm();// w ww.j a v a 2 s.c o m Map<LocalDate, Long> examUtilMap = new HashMap(); ArrayList<String> examList = new ArrayList(); while (testDate.isBefore(endDate.plusDays(1))) { examList.add(testDate.toString() + "=" + t.utilizationForDay(testDate, clk) + " "); testDate = testDate.plusDays(1); } utilMap.put(e, examList); } request.setAttribute("exams", exams); request.setAttribute("utilList", utilMap); RequestDispatcher rd = request.getRequestDispatcher("/admin/manage-exams.jsp"); rd.forward(request, response); }
From source file:com.publictransitanalytics.scoregenerator.datalayer.directories.GTFSReadingServiceTypeCalendar.java
private void parseCalendarFile(final Reader calendarReader, final Multimap<LocalDate, String> serviceTypesMap) throws IOException { final CSVParser calendarParser = new CSVParser(calendarReader, CSVFormat.DEFAULT.withHeader()); final List<CSVRecord> calendarRecords = calendarParser.getRecords(); LocalDate earliestDate = null; LocalDate latestDate = null;//from w w w . jav a 2 s .c o m for (final CSVRecord record : calendarRecords) { final String serviceType = record.get("service_id"); final LocalDate start = LocalDate.parse(record.get("start_date"), DateTimeFormatter.BASIC_ISO_DATE); if (earliestDate == null || start.isBefore(earliestDate)) { earliestDate = start; } final LocalDate end = LocalDate.parse(record.get("end_date"), DateTimeFormatter.BASIC_ISO_DATE); if (latestDate == null || end.isAfter(latestDate)) { latestDate = end; } final EnumSet<DayOfWeek> daysOfWeek = EnumSet.noneOf(DayOfWeek.class); if (record.get("monday").equals("1")) { daysOfWeek.add(DayOfWeek.MONDAY); } if (record.get("tuesday").equals("1")) { daysOfWeek.add(DayOfWeek.TUESDAY); } if (record.get("wednesday").equals("1")) { daysOfWeek.add(DayOfWeek.WEDNESDAY); } if (record.get("thursday").equals("1")) { daysOfWeek.add(DayOfWeek.THURSDAY); } if (record.get("friday").equals("1")) { daysOfWeek.add(DayOfWeek.FRIDAY); } if (record.get("saturday").equals("1")) { daysOfWeek.add(DayOfWeek.SATURDAY); } if (record.get("sunday").equals("1")) { daysOfWeek.add(DayOfWeek.SUNDAY); } LocalDate targetDate = start; while (!targetDate.isAfter(end)) { if (daysOfWeek.contains(targetDate.getDayOfWeek())) { serviceTypesMap.put(targetDate, serviceType); } targetDate = targetDate.plusDays(1); } } }