List of usage examples for java.util GregorianCalendar setTime
public final void setTime(Date date)
Date
. From source file:org.openvpms.archetype.util.DateRulesTestCase.java
/** * Tests the {@link DateRules#getTomorrow()} method. */// w w w. j ava2 s . c om @Test public void testGetTomorrow() { GregorianCalendar calendar = new GregorianCalendar(); calendar.setTime(new Date()); calendar.add(Calendar.DAY_OF_MONTH, 1); Date expected = DateUtils.truncate(calendar.getTime(), Calendar.DAY_OF_MONTH); assertEquals(expected, DateRules.getTomorrow()); }
From source file:org.zephyrsoft.sdb2.model.statistics.SongStatistics.java
private Date wipeTime(Date date) { GregorianCalendar cal = new GregorianCalendar(); cal.setTime(date); cal.set(Calendar.HOUR, 0);//from w ww. jav a 2 s. com cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); return cal.getTime(); }
From source file:MyServlet.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { GregorianCalendar calendar = new GregorianCalendar(); Date date1 = new Date(); calendar.setTime(date1); int hour = calendar.get(Calendar.HOUR_OF_DAY); if (hour < 9 || hour > 17) { chain.doFilter(request, response); } else {//from w w w . j a va 2 s . com response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<HTML>"); out.println("<HEAD>"); out.println("<TITLE>"); out.println("Get Back to Work!"); out.println("</TITLE>"); out.println("</HEAD>"); out.println("<BODY>"); out.println("<H1>Get Back to Work!</H1>"); out.println("Sorry, that resource is not available now."); out.println("</BODY>"); out.println("</HTML>"); } }
From source file:TextFileTest.java
/** * Writes employee data to a print writer * @param out the print writer/* w w w .j a va2 s . c o m*/ */ public void writeData(PrintWriter out) { GregorianCalendar calendar = new GregorianCalendar(); calendar.setTime(hireDay); out.println(name + "|" + salary + "|" + calendar.get(Calendar.YEAR) + "|" + (calendar.get(Calendar.MONTH) + 1) + "|" + calendar.get(Calendar.DAY_OF_MONTH)); }
From source file:org.apache.lens.cube.metadata.JAXBUtils.java
/** * Get XMLGregorianCalendar from Date./*from w ww .ja v a 2s. c o m*/ * * Useful for converting from java code to XML spec. * * @param d Date value * @return XML value */ public static XMLGregorianCalendar getXMLGregorianCalendar(Date d) { if (d == null) { return null; } GregorianCalendar c1 = new GregorianCalendar(); c1.setTime(d); try { return DatatypeFactory.newInstance().newXMLGregorianCalendar(c1); } catch (DatatypeConfigurationException e) { log.warn("Error converting date " + d, e); return null; } }
From source file:TestReservasSalas.java
@Test public void testDisponibilidadSala() throws OperationFailedException { Establecimiento e = new Establecimiento(1, "El toque", "123.456.789-1", "calle falsa 123", new Time(700), new Time(1900), 0, "Usaquen", "1234567", "34301293809213820921"); logica.registrarEstablecimiento(e);//from ww w. j a v a 2 s .co m Sala s = new Sala(1, logica.consultarEstablecimiento(1), "1000", "Sala de Orcas"); logica.registrarSala(s); Date d = new Date(); GregorianCalendar gc = new GregorianCalendar(); gc.setTime(d); Time t = new Time(gc.getTime().getTime()); assertTrue(logica.verificarDisponibilidadSala(d, t, s.getIdSala(), 1)); Reservacion r = new Reservacion(1, s, d, t, 1); //s.getReservacions().add(r); String resp = logica.registrarReserva(e.getIdEstablecimiento(), s.getIdSala(), d, t, 2); assertFalse(logica.verificarDisponibilidadSala(d, t, s.getIdSala(), 1)); List<Reservacion> l = logica.consultarReservacionesPorSala(s.getIdSala()); System.out.println(l.get(0).getFecha().toString()); Cliente c = new Cliente(1016040342, "ORCA"); logica.registrarCliente(c); for (Reservacion rs : l) { if (rs.getFecha().equals(r.getFecha())) r = rs; } r.setIdReservacion(0); if (resp.equals("0")) logica.crearEnsayoAlquiler(c.getIdCliente(), r, "ensayaremos mucho"); }
From source file:de.arago.rike.task.action.StartTask.java
@Override public void execute(IDataWrapper data) throws Exception { if (data.getRequestAttribute("id") != null) { String user = SecurityHelper.getUserEmail(data.getUser()); if (TaskHelper.getTasksInProgressForUser(user).size() < Integer .parseInt(GlobalConfig.get(WORKFLOW_WIP_LIMIT))) { Task task = TaskHelper.getTask(data.getRequestAttribute("id")); if (!TaskHelper.canDoTask(user, task) || task.getStatusEnum() != Task.Status.OPEN) { return; }// w w w .j a va 2 s . com task.setOwner(user); task.setStart(new Date()); task.setStatus(Task.Status.IN_PROGRESS); if (GlobalConfig.get(WORKFLOW_TYPE).equalsIgnoreCase("arago Technologies")) { GregorianCalendar c = new GregorianCalendar(); c.setTime(task.getStart()); c.add(Calendar.DAY_OF_MONTH, Integer.parseInt(GlobalConfig.get(WORKFLOW_DAYS_TO_FINISH_TASK))); task.setDueDate(c.getTime()); } TaskHelper.save(task); StatisticHelper.update(); data.setSessionAttribute("task", task); HashMap<String, Object> notificationParam = new HashMap<String, Object>(); notificationParam.put("id", task.getId().toString()); data.setEvent("TaskUpdateNotification", notificationParam); ActivityLogHelper.log( " started Task #" + task.getId() + " <a href=\"/web/guest/rike/-/show/task/" + task.getId() + "\">" + StringEscapeUtils.escapeHtml(task.getTitle()) + "</a> ", task.getStatus(), user, data, task.toMap()); } } }
From source file:RandomFileTest.java
/** Writes employee data to a data output @param out the data output/* ww w . j a v a 2s . com*/ */ public void writeData(DataOutput out) throws IOException { DataIO.writeFixedString(name, NAME_SIZE, out); out.writeDouble(salary); GregorianCalendar calendar = new GregorianCalendar(); calendar.setTime(hireDay); out.writeInt(calendar.get(Calendar.YEAR)); out.writeInt(calendar.get(Calendar.MONTH) + 1); out.writeInt(calendar.get(Calendar.DAY_OF_MONTH)); }
From source file:uk.nhs.cfh.dsp.srth.demographics.person.utils.PersonUtilsServiceImpl.java
/** * Gets the age years relative to reference point. * * @param anchorTime the anchor time/*w ww.j av a 2 s . c o m*/ * @param testTime the test time * * @return the age years relative to reference point */ public synchronized int getAgeYearsRelativeToReferencePoint(Calendar anchorTime, Calendar testTime) { Date refDate = anchorTime.getTime(); Date testDate = testTime.getTime(); int ageYears = 0; GregorianCalendar gc = new GregorianCalendar(); gc.setTime(testDate); // lopp through years incrementing age if test time is before reference time while (testDate.before(refDate)) { // increment gc gc.add(Calendar.YEAR, 1); // reset test date testDate = gc.getTime(); // increment age ageYears++; } return ageYears; }
From source file:org.ow2.petals.cloud.vacation.web.services.VacationClient.java
private VacationUpdateRequest createUpdateRequest(final PendingVacationRequest pendingRequest) { final VacationUpdateRequest request = serviceOF.createVacationUpdateRequest(); request.setDayNumber(pendingRequest.getDayNumber()); request.setEnquirer(pendingRequest.getEnquirer()); request.setReason(pendingRequest.getReason()); final GregorianCalendar cal = new GregorianCalendar(); cal.setTime(pendingRequest.getStartDate()); request.setStartDate(dtf.newXMLGregorianCalendar(cal)); request.setVacationRequestId(pendingRequest.getId()); return request; }