List of usage examples for java.time LocalTime plus
@Override
public LocalTime plus(TemporalAmount amountToAdd)
From source file:Main.java
public static void main(String[] args) { LocalTime l = LocalTime.now(); LocalTime s = l.plus(Duration.ofHours(1)); System.out.println(s);//from w w w.j ava2 s . c om }
From source file:com.gigglinggnus.controllers.StudentMakeAppointmentController.java
/** * * @param request servlet request//from w w w . ja va 2 s .c o m * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { EntityManager em = (EntityManager) request.getSession().getAttribute("em"); String msg = request.getParameter("msg"); User user = (User) (request.getSession().getAttribute("user")); Clock clk = (Clock) (request.getSession().getAttribute("clock")); if (msg.equals("lookup_student")) { String studId = request.getParameter("studentId"); List<Exam> exams = user.getRegistrableExams(); JSONObject json = new JSONObject(); json.put("students_idNumber", studId); json.put("firstName", user.getFirstName()); json.put("lastName", user.getLastName()); JSONArray jExams = new JSONArray(); for (Exam exam : exams) { JSONObject elem = new JSONObject(); String examId = exam.getExamId(); String termId = exam.getTerm().getTermId(); String start = exam.getInterval().getStart().atZone(ZoneId.systemDefault()).toLocalDate() .toString(); String end = exam.getInterval().getEnd().atZone(ZoneId.systemDefault()).toLocalDate().toString(); elem.put("examId", examId); elem.put("termId", termId); if (exam instanceof CourseExam) { String courseId = ((CourseExam) exam).getCourse().getCourseId(); elem.put("courseId", courseId); elem.put("examType", "Course"); } else { elem.put("courseId", "N/A"); elem.put("examType", "AdHoc"); } elem.put("start", start); elem.put("end", end); jExams.put(elem); } json.put("exams", jExams); response.getWriter().write(json.toString()); } else if (msg.equals("exam_available_timeslots")) { String examId = request.getParameter("examId"); String dateStr = request.getParameter("date"); Exam exam = em.find(Exam.class, examId); LocalDate apptDate = LocalDate.parse(dateStr); List<LocalTime> timeslots = exam.getTimeslotsForDay(apptDate); JSONObject json = new JSONObject(); json.put("examId", examId); JSONArray jTimeSlots = new JSONArray(); for (LocalTime timeslot : timeslots) { String start = timeslot.toString(); String end = timeslot.plus(exam.getDuration()).toString(); JSONObject elem = new JSONObject(); elem.put("start", start); elem.put("end", end); jTimeSlots.put(elem); } json.put("timeSlots", jTimeSlots); response.getWriter().write(json.toString()); } else if (msg.equals("submit-appointment")) { String studId = request.getParameter("studentId"); String examId = request.getParameter("examId"); String stDate = request.getParameter("examDate"); String stTime = request.getParameter("startTime") + ":00"; String stSeat = request.getParameter("seatType"); Exam exam = em.find(Exam.class, examId); LocalDate lDate = LocalDate.parse(stDate); LocalTime lTime = LocalTime.parse(stTime); Instant inst = ZonedDateTime.of(lDate, lTime, ZoneId.systemDefault()).toInstant(); JSONObject json = new JSONObject(); try { em.getTransaction().begin(); user.makeAppointment(exam, inst, clk); em.getTransaction().commit(); json.put("success", "Appointment Made!"); response.getWriter().write(json.toString()); } catch (Exception e) { em.getTransaction().rollback(); json.put("error", e.toString()); response.getWriter().write(json.toString()); } } else { JSONObject json = new JSONObject(); json.put("error", msg); response.getWriter().write(json.toString()); } }
From source file:com.gigglinggnus.controllers.AdminMakeAppointmentController.java
/** * * @param request servlet request//from w ww . ja v a2 s .c o m * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { EntityManager em = (EntityManager) request.getSession().getAttribute("em"); String msg = request.getParameter("msg"); User user = (User) (request.getSession().getAttribute("user")); Clock clk = (Clock) (request.getSession().getAttribute("clock")); if (msg.equals("lookup_student")) { String studId = request.getParameter("studentId"); User student = em.find(User.class, studId); List<Exam> exams = student.getRegistrableExams(); JSONObject json = new JSONObject(); json.put("students_idNumber", studId); json.put("firstName", student.getFirstName()); json.put("lastName", student.getLastName()); JSONArray jExams = new JSONArray(); for (Exam exam : exams) { JSONObject elem = new JSONObject(); String examId = exam.getExamId(); String termId = exam.getTerm().getTermId(); String start = exam.getInterval().getStart().atZone(ZoneId.systemDefault()).toLocalDate() .toString(); String end = exam.getInterval().getEnd().atZone(ZoneId.systemDefault()).toLocalDate().toString(); elem.put("examId", examId); elem.put("termId", termId); if (exam instanceof CourseExam) { String courseId = ((CourseExam) exam).getCourse().getCourseId(); elem.put("courseId", courseId); elem.put("examType", "Course"); } else { elem.put("courseId", "N/A"); elem.put("examType", "AdHoc"); } elem.put("start", start); elem.put("end", end); jExams.put(elem); } json.put("exams", jExams); response.getWriter().write(json.toString()); } else if (msg.equals("exam_available_timeslots")) { String examId = request.getParameter("examId"); String dateStr = request.getParameter("date"); Exam exam = em.find(Exam.class, examId); LocalDate apptDate = LocalDate.parse(dateStr); List<LocalTime> timeslots = exam.getTimeslotsForDay(apptDate); JSONObject json = new JSONObject(); json.put("examId", examId); JSONArray jTimeSlots = new JSONArray(); for (LocalTime timeslot : timeslots) { String start = timeslot.toString(); String end = timeslot.plus(exam.getDuration()).toString(); JSONObject elem = new JSONObject(); elem.put("start", start); elem.put("end", end); jTimeSlots.put(elem); } json.put("timeSlots", jTimeSlots); response.getWriter().write(json.toString()); } else if (msg.equals("submit-appointment")) { String studId = request.getParameter("studentId"); String examId = request.getParameter("examId"); String stDate = request.getParameter("examDate"); String stTime = request.getParameter("startTime") + ":00"; String stSeat = request.getParameter("seatType"); User student = em.find(User.class, studId); Exam exam = em.find(Exam.class, examId); LocalDate lDate = LocalDate.parse(stDate); LocalTime lTime = LocalTime.parse(stTime); Instant inst = ZonedDateTime.of(lDate, lTime, ZoneId.systemDefault()).toInstant(); JSONObject json = new JSONObject(); try { em.getTransaction().begin(); if (stSeat.equals("normal")) { user.makeAppointment(student, Seating.NORMAL, exam, inst, clk); em.getTransaction().commit(); json.put("success", "Appointment Made!"); response.getWriter().write(json.toString()); } else if (stSeat.equals("setaside")) { user.makeAppointment(student, Seating.SETASIDE, exam, inst, clk); em.getTransaction().commit(); json.put("success", "Appointment Made!"); response.getWriter().write(json.toString()); } else { em.getTransaction().rollback(); json.put("error", "invalid choice of seating"); response.getWriter().write(json.toString()); } } catch (Exception e) { em.getTransaction().rollback(); json.put("error", e.toString()); response.getWriter().write(json.toString()); } } else { JSONObject json = new JSONObject(); json.put("error", msg); response.getWriter().write(json.toString()); } }
From source file:fll.scheduler.TournamentSchedule.java
/** * Output the detailed schedule for a team for the day. * //from ww w. j a va 2 s . c o m * @throws DocumentException */ private void outputTeamSchedule(final SchedParams params, final Document detailedSchedules, final TeamScheduleInfo si) throws DocumentException { final Paragraph para = new Paragraph(); para.add(new Chunk( String.format("Detailed schedule for Team #%d - %s", si.getTeamNumber(), si.getTeamName()), TEAM_TITLE_FONT)); para.add(Chunk.NEWLINE); para.add(new Chunk(String.format("Organization: %s", si.getOrganization()), TEAM_TITLE_FONT)); para.add(Chunk.NEWLINE); para.add(new Chunk("Division: ", TEAM_HEADER_FONT)); para.add(new Chunk(si.getAwardGroup(), TEAM_VALUE_FONT)); para.add(Chunk.NEWLINE); for (final String subjectiveStation : subjectiveStations) { para.add(new Chunk(subjectiveStation + ": ", TEAM_HEADER_FONT)); final LocalTime start = si.getSubjectiveTimeByName(subjectiveStation).getTime(); final LocalTime end = start.plus(params.getStationByName(subjectiveStation).getDuration()); para.add(new Chunk(String.format("%s - %s", formatTime(start), formatTime(end)), TEAM_VALUE_FONT)); para.add(Chunk.NEWLINE); } for (int round = 0; round < getNumberOfRounds(); ++round) { para.add(new Chunk(String.format(PERF_HEADER_FORMAT, round + 1) + ": ", TEAM_HEADER_FONT)); final LocalTime start = si.getPerfTime(round); final LocalTime end = start.plus(Duration.ofMinutes(params.getPerformanceMinutes())); para.add(new Chunk(String.format("%s - %s %s %d", formatTime(start), formatTime(end), si.getPerfTableColor(round), si.getPerfTableSide(round)), TEAM_VALUE_FONT)); para.add(Chunk.NEWLINE); } para.add(Chunk.NEWLINE); para.add(new Chunk( "Performance rounds must start on time, and will start without you. Please ensure your team arrives at least 5 minutes ahead of scheduled time, and checks in.", TEAM_HEADER_FONT)); para.add(Chunk.NEWLINE); para.add(new Chunk( "Note that there may be more judging and a head to head round after this judging, please see the main tournament schedule for these details.", TEAM_HEADER_FONT)); para.add(Chunk.NEWLINE); para.add(Chunk.NEWLINE); para.add(Chunk.NEWLINE); para.setKeepTogether(true); detailedSchedules.add(para); }
From source file:fll.scheduler.TournamentSchedule.java
/** * Compute the general schedule and return it as a string *///from w w w. j av a 2 s. co m public String computeGeneralSchedule() { LocalTime minPerf = null; LocalTime maxPerf = null; // division -> date final Map<String, LocalTime> minSubjectiveTimes = new HashMap<>(); final Map<String, LocalTime> maxSubjectiveTimes = new HashMap<>(); for (final TeamScheduleInfo si : _schedule) { final String judgingStation = si.getJudgingGroup(); for (final SubjectiveTime stime : si.getSubjectiveTimes()) { final LocalTime currentMin = minSubjectiveTimes.get(judgingStation); if (null == currentMin) { minSubjectiveTimes.put(judgingStation, stime.getTime()); } else { if (stime.getTime().isBefore(currentMin)) { minSubjectiveTimes.put(judgingStation, stime.getTime()); } } final LocalTime currentMax = maxSubjectiveTimes.get(judgingStation); if (null == currentMax) { maxSubjectiveTimes.put(judgingStation, stime.getTime()); } else { if (stime.getTime().isAfter(currentMax)) { maxSubjectiveTimes.put(judgingStation, stime.getTime()); } } } for (int i = 0; i < getNumberOfRounds(); ++i) { if (null != si.getPerfTime(i)) { if (null == minPerf || si.getPerfTime(i).isBefore(minPerf)) { minPerf = si.getPerfTime(i); } if (null == maxPerf || si.getPerfTime(i).isAfter(maxPerf)) { maxPerf = si.getPerfTime(i); } } } } // print out the general schedule final Formatter output = new Formatter(); final Set<String> stations = new HashSet<String>(); stations.addAll(minSubjectiveTimes.keySet()); stations.addAll(maxSubjectiveTimes.keySet()); for (final String station : stations) { final LocalTime earliestStart = minSubjectiveTimes.get(station); final LocalTime latestStart = maxSubjectiveTimes.get(station); final Duration subjectiveDuration = Duration.ofMinutes(SolverParams.DEFAULT_SUBJECTIVE_MINUTES); final LocalTime latestEnd = latestStart.plus(subjectiveDuration); output.format( "Subjective times for judging station %s: %s - %s (assumes default subjective time of %d minutes)%n", station, formatTime(earliestStart), formatTime(latestEnd), SolverParams.DEFAULT_SUBJECTIVE_MINUTES); } if (null != minPerf && null != maxPerf) { final Duration performanceDuration = Duration.ofMinutes(SolverParams.DEFAULT_PERFORMANCE_MINUTES); final LocalTime performanceEnd = maxPerf.plus(performanceDuration); output.format("Performance times: %s - %s (assumes default performance time of %d minutes)%n", formatTime(minPerf), formatTime(performanceEnd), SolverParams.DEFAULT_PERFORMANCE_MINUTES); } return output.toString(); }