List of usage examples for org.joda.time DateTime toLocalDate
public LocalDate toLocalDate()
LocalDate
with the same date and chronology. From source file:json.sipaServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w ww . j ava 2 s.co m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); response.setContentType("text/html;charset=UTF-8"); CalendarDates2 cal; SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat nor = new SimpleDateFormat("dd-MM-yyyy"); DateTime fin; CalendarDTO c[] = new CalendarDTO[1344]; // capasidad de 1344 int t = 0; List l = new ArrayList(); try { cal = new CalendarDates2("SEGURIDAD"); while (cal.getDatos().getResultSet().next()) { c[t] = new CalendarDTO(); c[t].setId(t); c[t].setStart("" + cal.getDatos().getResultSet().getDate("Incextr")); fin = DateTime.parse(cal.getDatos().getResultSet().getDate("Finextr").toString()); fin = fin.plusDays(1); c[t].setEnd("" + f.format(fin.toLocalDate().toDate())); c[t].setTitle("" + cal.getDatos().getResultSet().getInt("Orden") + " " + cal.getDatos().getResultSet().getString("Responsable").trim()); if (!f.format(cal.getDatos().getResultSet().getDate("Finreal")).equals("2001-01-01")) { c[t].setDescription("<h2 align='center'>" + cal.getDatos().getResultSet().getString("AREA").trim() + " </h2>" + "<h4> Ubicacion Tecnica : </h4>" + cal.getDatos().getResultSet().getString("Denominacion").trim() + "<h4> Responsable : </h4>" + cal.getDatos().getResultSet().getString("PtoTrbRes").trim() + "<h4> Operarios :</h4>" + cal.getDatos().getResultSet().getString("ayudantes").trim() + "<h4> TextoBreveOperacion : </h4> <p>" + cal.getDatos().getResultSet().getString("TextoOperacion") + "</p>" + "<h4> TextoBreve : </h4> <p> " + cal.getDatos().getResultSet().getString("Textobreve").trim() + "</p>" + "<h4> Periodo: </h4> <p> " + nor.format(cal.getDatos().getResultSet().getDate("Incextr")) + " AL " + nor.format(cal.getDatos().getResultSet().getDate("Finextr")) + "</p>" + "<h4> Estado : </h4>" + cal.getDatos().getResultSet().getString("Estado").trim() + "<h4> Finaliz el : </h4> <p>" + nor.format(cal.getDatos().getResultSet().getDate("Finreal")) + "</p>"); } else { c[t].setDescription("<h2 align='center'>" + cal.getDatos().getResultSet().getString("AREA").trim() + " </h2>" + "<h4> Ubicacion Tecnica : </h4>" + cal.getDatos().getResultSet().getString("Denominacion").trim() + "<h4> Responsable : </h4>" + cal.getDatos().getResultSet().getString("PtoTrbRes").trim() + "<h4> Operarios :</h4>" + cal.getDatos().getResultSet().getString("ayudantes").trim() + "<h4> TextoBreveOperacion : </h4> <p>" + cal.getDatos().getResultSet().getString("TextoOperacion") + "</p>" + "<h4> TextoBreve : </h4> <p> " + cal.getDatos().getResultSet().getString("Textobreve").trim() + "</p>" + "<h4> Periodo: </h4> <p> " + nor.format(cal.getDatos().getResultSet().getDate("Incextr")) + " AL " + nor.format(cal.getDatos().getResultSet().getDate("Finextr")) + "</p>" + "<h4> Estado : </h4>" + cal.getDatos().getResultSet().getString("Estado").trim() + "<h4> Finaliz el : </h4> <p> </p>"); } if (!f.format(cal.getDatos().getResultSet().getDate("Finreal")).equals("2001-01-01")) { c[t].setColor("white"); c[t].setBorderColor("skyblue"); c[t].setTextColor("black"); } else if (cal.getDatos().getResultSet().getString("AREA").equals("MANTENIMIENTO")) { c[t].setColor("skyblue"); c[t].setBorderColor("skyblue"); c[t].setTextColor("black"); } else if (cal.getDatos().getResultSet().getString("AREA").equals("OPERACION")) { c[t].setColor("black"); c[t].setBorderColor("skyblue"); c[t].setTextColor("white"); } else if (cal.getDatos().getResultSet().getString("AREA").equals("SEGURIDAD")) { c[t].setColor("#ff6347"); c[t].setBorderColor("skyblue"); c[t].setTextColor("black"); } else if (cal.getDatos().getResultSet().getString("AREA").equals("UAT")) { c[t].setColor("gray"); c[t].setBorderColor("skyblue"); c[t].setTextColor("black"); } l.add(c[t]); t++; } // fin while cal.getConexion().close(); } catch (SQLException ex) { Logger.getLogger(CalendarJsonServlet.class.getName()).log(Level.SEVERE, null, ex); } response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); out.write(new Gson().toJson(l)); }
From source file:json.uatServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w ww . j a va2s . c o m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); response.setContentType("text/html;charset=UTF-8"); CalendarDates2 cal; SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat nor = new SimpleDateFormat("dd-MM-yyyy"); DateTime fin; CalendarDTO c[] = new CalendarDTO[1344]; // capasidad de 1344 int t = 0; List l = new ArrayList(); try { cal = new CalendarDates2("UAT"); while (cal.getDatos().getResultSet().next()) { c[t] = new CalendarDTO(); c[t].setId(t); c[t].setStart("" + cal.getDatos().getResultSet().getDate("Incextr")); fin = DateTime.parse(cal.getDatos().getResultSet().getDate("Finextr").toString()); fin = fin.plusDays(1); c[t].setEnd("" + f.format(fin.toLocalDate().toDate())); c[t].setTitle("" + cal.getDatos().getResultSet().getInt("Orden") + " " + cal.getDatos().getResultSet().getString("Responsable").trim()); if (!f.format(cal.getDatos().getResultSet().getDate("Finreal")).equals("2001-01-01")) { c[t].setDescription("<h2 align='center'>" + cal.getDatos().getResultSet().getString("AREA").trim() + " </h2>" + "<h4> Ubicacion Tecnica : </h4>" + cal.getDatos().getResultSet().getString("Denominacion").trim() + "<h4> Responsable : </h4>" + cal.getDatos().getResultSet().getString("PtoTrbRes").trim() + "<h4> Operarios :</h4>" + cal.getDatos().getResultSet().getString("ayudantes").trim() + "<h4> TextoBreveOperacion : </h4> <p>" + cal.getDatos().getResultSet().getString("TextoOperacion") + "</p>" + "<h4> TextoBreve : </h4> <p> " + cal.getDatos().getResultSet().getString("Textobreve").trim() + "</p>" + "<h4> Periodo: </h4> <p> " + nor.format(cal.getDatos().getResultSet().getDate("Incextr")) + " AL " + nor.format(cal.getDatos().getResultSet().getDate("Finextr")) + "</p>" + "<h4> Estado : </h4>" + cal.getDatos().getResultSet().getString("Estado").trim() + "<h4> Finaliz el : </h4> <p>" + nor.format(cal.getDatos().getResultSet().getDate("Finreal")) + "</p>"); } else { c[t].setDescription("<h2 align='center'>" + cal.getDatos().getResultSet().getString("AREA").trim() + " </h2>" + "<h4> Ubicacion Tecnica : </h4>" + cal.getDatos().getResultSet().getString("Denominacion").trim() + "<h4> Responsable : </h4>" + cal.getDatos().getResultSet().getString("PtoTrbRes").trim() + "<h4> Operarios :</h4>" + cal.getDatos().getResultSet().getString("ayudantes").trim() + "<h4> TextoBreveOperacion : </h4> <p>" + cal.getDatos().getResultSet().getString("TextoOperacion") + "</p>" + "<h4> TextoBreve : </h4> <p> " + cal.getDatos().getResultSet().getString("Textobreve").trim() + "</p>" + "<h4> Periodo: </h4> <p> " + nor.format(cal.getDatos().getResultSet().getDate("Incextr")) + " AL " + nor.format(cal.getDatos().getResultSet().getDate("Finextr")) + "</p>" + "<h4> Estado : </h4>" + cal.getDatos().getResultSet().getString("Estado").trim() + "<h4> Finaliz el : </h4> <p> </p>"); } if (!f.format(cal.getDatos().getResultSet().getDate("Finreal")).equals("2001-01-01")) { c[t].setColor("white"); c[t].setBorderColor("skyblue"); c[t].setTextColor("black"); } else if (cal.getDatos().getResultSet().getString("AREA").equals("MANTENIMIENTO")) { c[t].setColor("skyblue"); c[t].setBorderColor("skyblue"); c[t].setTextColor("black"); } else if (cal.getDatos().getResultSet().getString("AREA").equals("OPERACION")) { c[t].setColor("black"); c[t].setBorderColor("skyblue"); c[t].setTextColor("white"); } else if (cal.getDatos().getResultSet().getString("AREA").equals("SEGURIDAD")) { c[t].setColor("#ff6347"); c[t].setBorderColor("skyblue"); c[t].setTextColor("black"); } else if (cal.getDatos().getResultSet().getString("AREA").equals("UAT")) { c[t].setColor("gray"); c[t].setBorderColor("skyblue"); c[t].setTextColor("black"); } l.add(c[t]); t++; } // fin while cal.getConexion().close(); } catch (SQLException ex) { Logger.getLogger(CalendarJsonServlet.class.getName()).log(Level.SEVERE, null, ex); } response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); out.write(new Gson().toJson(l)); }
From source file:li.klass.fhem.util.DateFormatUtil.java
License:Open Source License
public static String formatTime(String input) { try {/*from w ww . j a v a 2 s .c o m*/ if (input.equalsIgnoreCase("Initialized")) { return null; } DateTime dateTime = FHEM_DATE_FORMAT.parseDateTime(input); if (dateTime.toLocalDate().equals(LocalDate.now())) { return ANDFHEM_TIME_FORMAT.print(dateTime); } else { return ANDFHEM_DATE_FORMAT.print(dateTime); } } catch (Exception e) { LOGGER.error("cannot format " + input, e); return input; } }
From source file:me.vertretungsplan.additionalinfo.BaseIcalParser.java
License:Mozilla Public License
@Override public AdditionalInfo getAdditionalInfo() throws IOException { AdditionalInfo info = new AdditionalInfo(); info.setTitle(getTitle());/* www . ja v a 2 s . com*/ String rawdata = httpGet(getIcalUrl(), "UTF-8"); if (shouldStripTimezoneInfo()) { Pattern pattern = Pattern.compile("BEGIN:VTIMEZONE.*END:VTIMEZONE", Pattern.DOTALL); rawdata = pattern.matcher(rawdata).replaceAll(""); } DateTime now = DateTime.now().withTimeAtStartOfDay(); List<ICalendar> icals = Biweekly.parse(rawdata).all(); List<Event> events = new ArrayList<>(); for (ICalendar ical : icals) { for (VEvent event : ical.getEvents()) { Event item = new Event(); TimeZone timezoneStart = getTimeZoneStart(ical, event); if (event.getDescription() != null) { item.description = event.getDescription().getValue(); } if (event.getSummary() != null) { item.summary = event.getSummary().getValue(); } if (event.getDateStart() != null) { item.startDate = new DateTime(event.getDateStart().getValue()); item.startHasTime = event.getDateStart().getValue().hasTime(); } else { continue; } if (event.getDateEnd() != null) { item.endDate = new DateTime(event.getDateEnd().getValue()); item.endHasTime = event.getDateEnd().getValue().hasTime(); } if (event.getLocation() != null) { item.location = event.getLocation().getValue(); } if (event.getUrl() != null) { item.url = event.getUrl().getValue(); } if (event.getRecurrenceRule() == null && item.endDate != null && (item.endDate.compareTo(now) < 0)) { continue; } else if (event.getRecurrenceRule() == null && (item.startDate.compareTo(now) < 0)) { continue; } if (event.getRecurrenceRule() != null && event.getRecurrenceRule().getValue().getUntil() != null && event.getRecurrenceRule().getValue().getUntil().compareTo(now.toDate()) < 0) { continue; } if (event.getRecurrenceRule() != null) { Duration duration = null; if (event.getDateEnd() != null) { duration = new Duration(new DateTime(event.getDateStart().getValue()), new DateTime(event.getDateEnd().getValue())); } DateIterator iterator = event.getDateIterator(timezoneStart); while (iterator.hasNext()) { Date date = iterator.next(); Event reccitem = item.clone(); reccitem.startDate = new DateTime(date); reccitem.endDate = reccitem.startDate.plus(duration); if (item.startDate.equals(reccitem.startDate)) continue; if (item.endDate != null && (item.endDate.compareTo(now) < 0)) { continue; } else if (item.endDate == null && (item.startDate.compareTo(now) < 0)) { continue; } events.add(reccitem); } } if (item.endDate != null && (item.endDate.compareTo(now) < 0)) { continue; } else if (item.endDate == null && (item.startDate.compareTo(now) < 0)) { continue; } events.add(item); } } Collections.sort(events, new Comparator<Event>() { @Override public int compare(Event o1, Event o2) { return o1.startDate.compareTo(o2.startDate); } }); StringBuilder content = new StringBuilder(); int count = 0; DateTimeFormatter fmtDt = DateTimeFormat.shortDateTime().withLocale(Locale.GERMANY); DateTimeFormatter fmtD = DateTimeFormat.shortDate().withLocale(Locale.GERMANY); DateTimeFormatter fmtT = DateTimeFormat.shortTime().withLocale(Locale.GERMANY); for (Event item : events) { if (count >= getMaxItemsCount()) { break; } else if (count != 0) { content.append("<br><br>\n\n"); } DateTime start = item.startDate; if (item.endDate != null) { DateTime end = item.endDate; if (!item.endHasTime) { end = end.minusDays(1); } content.append((item.startHasTime ? fmtDt : fmtD).print(start)); if (!end.equals(start)) { content.append(" - "); if (item.startHasTime && item.endHasTime && end.toLocalDate().equals(start.toLocalDate())) { content.append(fmtT.print(end)); } else { content.append((item.endHasTime ? fmtDt : fmtD).print(end)); } } } else { content.append(fmtDt.print(start)); } content.append("<br>\n"); content.append("<b>"); content.append(item.summary); content.append("</b>"); count++; } info.setText(content.toString()); return info; }
From source file:module.mission.domain.PersonMissionAuthorization.java
License:Open Source License
public AccountabilityType getWorkingAccountabilityType() { final DateTime departure = getMission().getDaparture(); final Person person = getSubject(); return person.getParentAccountabilityStream().filter(new Predicate<Accountability>() { @Override/*www . j a v a 2 s . c om*/ public boolean test(Accountability a) { final LocalDate date = departure.toLocalDate(); if (a.isActive(date)) { if (MissionSystem.REQUIRE_AUTHORIZATION_PREDICATE.test(a) && matchesUnit(a.getParent(), date)) { return true; } } return false; } }).map(a -> a.getAccountabilityType()).findAny().orElse(null); }
From source file:mx.edu.um.portlets.esu.dao.impl.DiaDaoImpl.java
License:Open Source License
@Override public Dia obtiene(DateTime hoy) { log.debug("Obtiene dia {} : {}", new Object[] { hoy, hoy.toLocalDate().toDate() }); Dia dia;// w w w .ja v a2 s .co m try { dia = (Dia) getJdbcTemplate().queryForObject( "select id, version, fecha, leccion, leccionasset, versiculo, versiculoasset, video, " + "dialoga1, dialoga2, dialoga3, dialoga4, comunica1, comunica2, comunica3, comunica4, " + "podcastsemanal, podcastdiario, cerrado from esu_dias where cerrado = true and fecha = ?", new Date[] { hoy.toLocalDate().toDate() }, new DiaMapper()); } catch (org.springframework.dao.EmptyResultDataAccessException e) { log.debug("NO LO ENCONTRE"); dia = null; } // Query query = currentSession().createQuery("select d from Dia d where cerrado is true and d.fecha = :fecha"); // query.setDate("fecha", new java.sql.Date(hoy.toDate().getTime())); // Dia dia = (Dia) query.uniqueResult(); return dia; }
From source file:name.martingeisse.wicket.panel.simple.DateTimeTextFieldPanel.java
License:Open Source License
@Override protected void onBeforeRender() { final Class<?> modelType = getType(); final Object modelObject = getDefaultModelObject(); if (modelType == DateTime.class) { final DateTime modelDateTime = (DateTime) modelObject; originalChronology = modelDateTime.getChronology(); localizedChronology = originalChronology.withZone(MyWicketSession.get().getTimeZone()); final DateTime localizedModelDateTime = modelDateTime.withChronology(localizedChronology); date = localizedModelDateTime.toLocalDate(); time = localizedModelDateTime.toLocalTime(); } else if (modelType == LocalDateTime.class) { final LocalDateTime modelDateTime = (LocalDateTime) modelObject; originalChronology = modelDateTime.getChronology(); localizedChronology = originalChronology; date = modelDateTime.toLocalDate(); time = modelDateTime.toLocalTime(); } else {/*from w ww. jav a2 s .com*/ throw new IllegalStateException("unsupported model type for DateTimeTextFieldPanel: " + modelType); } super.onBeforeRender(); }
From source file:net.solarnetwork.util.JodaDateFormatEditor.java
License:Open Source License
@Override public void setAsText(String text) throws IllegalArgumentException { IllegalArgumentException iae = null; // try patterns one at a time, if all fail to parse then throw exception for (DateTimeFormatter df : this.dateFormatters) { try {/* w ww . j ava 2 s. c om*/ DateTime dt = df.parseDateTime(text); Object val = dt; switch (this.parseMode) { case LocalDate: val = dt.toLocalDate(); break; case LocalTime: val = dt.toLocalTime(); break; default: // leave as DateTime } setValue(val); iae = null; break; } catch (IllegalArgumentException e) { iae = e; } } if (iae != null) { throw iae; } }
From source file:net.sourceforge.fenixedu.domain.serviceRequests.AcademicServiceRequestSituation.java
License:Open Source License
protected void checkParameters(final AcademicServiceRequest academicServiceRequest, final AcademicServiceRequestBean bean) { if (academicServiceRequest == null) { throw new DomainException( "error.serviceRequests.AcademicServiceRequestSituation.academicServiceRequest.cannot.be.null"); }/*from w w w . j a v a 2 s . c o m*/ if (!bean.hasAcademicServiceRequestSituationType()) { throw new DomainException( "error.serviceRequests.AcademicServiceRequestSituation.academicServiceRequestSituationType.cannot.be.null"); } final AcademicServiceRequestSituation activeSituation = academicServiceRequest.getActiveSituation(); if (activeSituation != null) { final DateTime activeSituationDate = activeSituation.getSituationDate(); final DateTime finalSituationDate = bean.getFinalSituationDate(); if (finalSituationDate.toLocalDate().isBefore(activeSituationDate.toLocalDate())) { throw new DomainException( "error.serviceRequests.AcademicServiceRequestSituation.situation.date.is.before"); } if (finalSituationDate.toLocalDate().isEqual(activeSituationDate.toLocalDate()) && finalSituationDate.isBefore(activeSituationDate)) { bean.setFinalSituationDate(activeSituationDate.plusMinutes(1)); } } if (bean.getFinalSituationDate().isAfterNow()) { throw new DomainException( "error.serviceRequests.AcademicServiceRequestSituation.situation.date.is.after"); } if (bean.isToCancelOrReject()) { if (!bean.hasJustification()) { throw new DomainException( "error.serviceRequests.AcademicServiceRequestSituation.justification.cannot.be.null.for.cancelled.and.rejected.situations"); } } }
From source file:net.sourceforge.fenixedu.presentationTier.Action.student.enrollment.bolonha.BolonhaStudentEnrollmentDispatchAction.java
License:Open Source License
@Override protected ActionForward prepareShowDegreeModulesToEnrol(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response, StudentCurricularPlan studentCurricularPlan, ExecutionSemester executionSemester) { final EnrolmentPreConditionResult result = StudentCurricularPlanEnrolmentPreConditions .checkPreConditionsToEnrol(studentCurricularPlan, executionSemester); if (!result.isValid()) { if (result.getEnrolmentPeriod() != null) { DateTime now = DateTime.now().withMillisOfSecond(0); DateTime start = result.getEnrolmentPeriod().getStartDateDateTime(); Period period = new Period(start.getMillis() - now.getMillis()); if (start.toLocalDate().equals(now.toLocalDate())) { request.setAttribute("now", now); request.setAttribute("start", start); request.setAttribute("remaining", FORMATTER.print(period)); }//from w w w . j a v a 2s . co m } addActionMessage(request, result.message(), result.args()); return mapping.findForward("enrollmentCannotProceed"); } return super.prepareShowDegreeModulesToEnrol(mapping, form, request, response, studentCurricularPlan, executionSemester); }