List of usage examples for org.apache.commons.lang.time DateUtils setMinutes
public static Date setMinutes(Date date, int amount)
From source file:gov.nih.nci.ess.sr.ExpeditedToSafetyReportConverterImpl.java
private TSDateTime convert(Date day, TimeValue time) { if (time == null || time.isBlank()) { return convert(day); }//from www .j ava 2 s. com day = day == null ? new Date(0) : day; // My apologies for the less readable expression below. return convert( DateUtils .setMinutes( DateUtils.setHours(day, time.isAM() ? (time.getHour() == 12 ? 0 : time.getHour()) : (time.getHour() == 12 ? 12 : time.getHour() + 12)), time.getMinute())); }
From source file:org.camunda.bpm.engine.test.api.history.HistoryCleanupTest.java
@Test public void testLessThanThresholdOutsideBatchWindowAfterMidnight() { //given//from ww w .j a v a2 s . c om prepareData(5); //we're outside batch window, batch window passes midnight Date date = new Date(); ClockUtil.setCurrentTime(DateUtils.setMinutes(DateUtils.setHours(date, 1), 10)); //01:10 processEngineConfiguration.setHistoryCleanupBatchWindowStartTime("23:00"); processEngineConfiguration.setHistoryCleanupBatchWindowEndTime("01:00"); processEngineConfiguration.initHistoryCleanup(); //when String jobId = historyService.cleanUpHistoryAsync().getId(); managementService.executeJob(jobId); //then JobEntity jobEntity = getJobEntity(jobId); HistoryCleanupJobHandlerConfiguration configuration = getConfiguration(jobEntity); //job rescheduled till next batch window start Date nextRun = getNextRunWithinBatchWindow(ClockUtil.getCurrentTime()); assertTrue(jobEntity.getDuedate().equals(nextRun)); assertTrue(nextRun.after(ClockUtil.getCurrentTime())); //countEmptyRuns canceled assertEquals(0, configuration.getCountEmptyRuns()); //nothing was removed assertResult(5); }
From source file:org.camunda.bpm.engine.test.api.history.HistoryCleanupTest.java
@Test public void testLessThanThresholdOutsideBatchWindowBeforeMidnight() { //given//from ww w .ja va 2 s .c o m prepareData(5); //we're outside batch window, batch window passes midnight Date date = new Date(); ClockUtil.setCurrentTime(DateUtils.setMinutes(DateUtils.setHours(date, 22), 10)); //22:10 processEngineConfiguration.setHistoryCleanupBatchWindowStartTime("23:00"); processEngineConfiguration.setHistoryCleanupBatchWindowEndTime("01:00"); processEngineConfiguration.initHistoryCleanup(); //when String jobId = historyService.cleanUpHistoryAsync().getId(); managementService.executeJob(jobId); //then JobEntity jobEntity = getJobEntity(jobId); HistoryCleanupJobHandlerConfiguration configuration = getConfiguration(jobEntity); //job rescheduled till next batch window start Date nextRun = getNextRunWithinBatchWindow(ClockUtil.getCurrentTime()); assertTrue(jobEntity.getDuedate().equals(nextRun)); assertTrue(nextRun.after(ClockUtil.getCurrentTime())); //countEmptyRuns cancelled assertEquals(0, configuration.getCountEmptyRuns()); //nothing was removed assertResult(5); }
From source file:org.camunda.bpm.engine.test.api.history.HistoryCleanupTest.java
@Test public void testLessThanThresholdWithinBatchWindowBeforeMidnight() { //given/*from w ww .ja v a2 s.co m*/ prepareData(5); //we're within batch window, but batch window passes midnight Date date = new Date(); ClockUtil.setCurrentTime(DateUtils.setMinutes(DateUtils.setHours(date, 23), 10)); //23:10 processEngineConfiguration.setHistoryCleanupBatchWindowStartTime("23:00"); processEngineConfiguration.setHistoryCleanupBatchWindowEndTime("01:00"); processEngineConfiguration.initHistoryCleanup(); //when String jobId = historyService.cleanUpHistoryAsync().getId(); ExecuteJobHelper.executeJob(jobId, processEngineConfiguration.getCommandExecutorTxRequired()); //then JobEntity jobEntity = getJobEntity(jobId); HistoryCleanupJobHandlerConfiguration configuration = getConfiguration(jobEntity); //job rescheduled till current time + delay Date nextRun = getNextRunWithDelay(ClockUtil.getCurrentTime(), 0); assertTrue(jobEntity.getDuedate().equals(nextRun) || jobEntity.getDuedate().after(nextRun)); Date nextRunMax = DateUtils.addSeconds(ClockUtil.getCurrentTime(), HistoryCleanupJobHandlerConfiguration.MAX_DELAY); assertTrue(jobEntity.getDuedate().before(nextRunMax)); //countEmptyRuns incremented assertEquals(1, configuration.getCountEmptyRuns()); //data is still removed assertResult(0); }
From source file:org.camunda.bpm.engine.test.api.history.HistoryCleanupTest.java
@Test public void testLessThanThresholdWithinBatchWindowAfterMidnight() { //given/*from ww w .j a va2 s .co m*/ prepareData(5); //we're within batch window, but batch window passes midnight Date date = new Date(); ClockUtil.setCurrentTime(DateUtils.setMinutes(DateUtils.setHours(date, 0), 10)); //00:10 processEngineConfiguration.setHistoryCleanupBatchWindowStartTime("23:00"); processEngineConfiguration.setHistoryCleanupBatchWindowEndTime("01:00"); processEngineConfiguration.initHistoryCleanup(); //when String jobId = historyService.cleanUpHistoryAsync().getId(); ExecuteJobHelper.executeJob(jobId, processEngineConfiguration.getCommandExecutorTxRequired()); //then JobEntity jobEntity = getJobEntity(jobId); HistoryCleanupJobHandlerConfiguration configuration = getConfiguration(jobEntity); //job rescheduled till current time + delay Date nextRun = getNextRunWithDelay(ClockUtil.getCurrentTime(), 0); assertTrue(jobEntity.getDuedate().equals(nextRun) || jobEntity.getDuedate().after(nextRun)); Date nextRunMax = DateUtils.addSeconds(ClockUtil.getCurrentTime(), HistoryCleanupJobHandlerConfiguration.MAX_DELAY); assertTrue(jobEntity.getDuedate().before(nextRunMax)); //countEmptyRuns incremented assertEquals(1, configuration.getCountEmptyRuns()); //data is still removed assertResult(0); }
From source file:org.camunda.bpm.engine.test.api.history.HistoryCleanupTest.java
private Date updateTime(Date now, Date newTime) { Date result = now;/*from www .j a v a 2s . c o m*/ Calendar newTimeCalendar = Calendar.getInstance(); newTimeCalendar.setTime(newTime); result = DateUtils.setHours(result, newTimeCalendar.get(Calendar.HOUR_OF_DAY)); result = DateUtils.setMinutes(result, newTimeCalendar.get(Calendar.MINUTE)); result = DateUtils.setSeconds(result, newTimeCalendar.get(Calendar.SECOND)); result = DateUtils.setMilliseconds(result, newTimeCalendar.get(Calendar.MILLISECOND)); return result; }
From source file:org.openbravo.financial.FinancialUtils.java
/** * Method to get the conversion rate defined at system level. If there is not a conversion rate * defined on the given Organization it is searched recursively on its parent organization until * one is found. If no conversion rate is found null is returned. * /* w ww . ja v a 2s . co m*/ * @param date * Date conversion is being performed. * @param fromCurrency * Currency to convert from. * @param toCurrency * Currency to convert to. * @param org * Organization of the document that needs to be converted. * @return a valid ConversionRate for the given parameters, null if none is found. */ public static ConversionRate getConversionRate(Date date, Currency fromCurrency, Currency toCurrency, Organization org, Client client) { ConversionRate conversionRate; // Conversion rate records do not get into account timestamp. Date dateWithoutTimestamp = DateUtils .setHours(DateUtils.setMinutes(DateUtils.setSeconds(DateUtils.setMilliseconds(date, 0), 0), 0), 0); // Readable Client Org filters to false as organization is filtered explicitly. OBContext.setAdminMode(false); try { final OBCriteria<ConversionRate> obcConvRate = OBDal.getInstance().createCriteria(ConversionRate.class); obcConvRate.add(Restrictions.eq(ConversionRate.PROPERTY_ORGANIZATION, org)); obcConvRate.add(Restrictions.eq(ConversionRate.PROPERTY_CLIENT, client)); obcConvRate.add(Restrictions.eq(ConversionRate.PROPERTY_CURRENCY, fromCurrency)); obcConvRate.add(Restrictions.eq(ConversionRate.PROPERTY_TOCURRENCY, toCurrency)); obcConvRate.add(Restrictions.le(ConversionRate.PROPERTY_VALIDFROMDATE, dateWithoutTimestamp)); obcConvRate.add(Restrictions.ge(ConversionRate.PROPERTY_VALIDTODATE, dateWithoutTimestamp)); obcConvRate.setFilterOnReadableClients(false); obcConvRate.setFilterOnReadableOrganization(false); conversionRate = (ConversionRate) obcConvRate.uniqueResult(); if (conversionRate != null) { return conversionRate; } if ("0".equals(org.getId())) { return null; } else { return getConversionRate(date, fromCurrency, toCurrency, OBContext.getOBContext().getOrganizationStructureProvider(client.getId()).getParentOrg(org), client); } } catch (Exception e) { log4j.error("Exception calculating conversion rate.", e); return null; } finally { OBContext.restorePreviousMode(); } }
From source file:org.sonar.batch.MavenProjectBuilder.java
Date loadAnalysisDate(Configuration configuration) { String formattedDate = configuration.getString(CoreProperties.PROJECT_DATE_PROPERTY); if (formattedDate == null) { return new Date(); }/*from w ww. j a v a2 s . com*/ DateFormat format = new SimpleDateFormat("yyyy-MM-dd"); try { // see SONAR-908 make sure that a time is defined for the date. Date date = DateUtils.setHours(format.parse(formattedDate), 0); return DateUtils.setMinutes(date, 1); } catch (ParseException e) { throw new SonarException( "The property " + CoreProperties.PROJECT_DATE_PROPERTY + " does not respect the format yyyy-MM-dd (for example 2008-05-23) : " + formattedDate, e); } }
From source file:oscar.oscarEncounter.oscarConsultationRequest.pageUtil.EctConsultationFormRequestAction.java
@Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { EctConsultationFormRequestForm frm = (EctConsultationFormRequestForm) form; String appointmentHour = frm.getAppointmentHour(); String appointmentPm = frm.getAppointmentPm(); if (appointmentPm.equals("PM") && Integer.parseInt(appointmentHour) < 12) { appointmentHour = Integer.toString(Integer.parseInt(appointmentHour) + 12); } else if (appointmentHour.equals("12") && appointmentPm.equals("AM")) { appointmentHour = "0"; }//from w w w. j av a2 s .co m String sendTo = frm.getSendTo(); String submission = frm.getSubmission(); String providerNo = frm.getProviderNo(); String demographicNo = frm.getDemographicNo(); String requestId = ""; boolean newSignature = request.getParameter("newSignature") != null && request.getParameter("newSignature").equalsIgnoreCase("true"); String signatureId = ""; String signatureImg = frm.getSignatureImg(); if (StringUtils.isBlank(signatureImg)) { signatureImg = request.getParameter("newSignatureImg"); if (signatureImg == null) signatureImg = ""; } ConsultationRequestDao consultationRequestDao = (ConsultationRequestDao) SpringUtils .getBean("consultationRequestDao"); ConsultationRequestExtDao consultationRequestExtDao = (ConsultationRequestExtDao) SpringUtils .getBean("consultationRequestExtDao"); ProfessionalSpecialistDao professionalSpecialistDao = (ProfessionalSpecialistDao) SpringUtils .getBean("professionalSpecialistDao"); String[] format = new String[] { "yyyy-MM-dd", "yyyy/MM/dd" }; if (submission.startsWith("Submit")) { try { if (newSignature) { LoggedInInfo loggedInInfo = LoggedInInfo.loggedInInfo.get(); DigitalSignature signature = DigitalSignatureUtils.storeDigitalSignatureFromTempFileToDB( loggedInInfo, signatureImg, Integer.parseInt(demographicNo)); if (signature != null) { signatureId = "" + signature.getId(); } } ConsultationRequest consult = new ConsultationRequest(); Date date = DateUtils.parseDate(frm.getReferalDate(), format); consult.setReferralDate(date); consult.setServiceId(new Integer(frm.getService())); consult.setSignatureImg(signatureId); consult.setLetterheadName(frm.getLetterheadName()); consult.setLetterheadAddress(frm.getLetterheadAddress()); consult.setLetterheadPhone(frm.getLetterheadPhone()); consult.setLetterheadFax(frm.getLetterheadFax()); if (frm.getAppointmentYear() != null && !frm.getAppointmentYear().equals("")) { date = DateUtils.parseDate(frm.getAppointmentYear() + "-" + frm.getAppointmentMonth() + "-" + frm.getAppointmentDay(), format); consult.setAppointmentDate(date); date = DateUtils.setHours(date, new Integer(appointmentHour)); date = DateUtils.setMinutes(date, new Integer(frm.getAppointmentMinute())); consult.setAppointmentTime(date); } consult.setReasonForReferral(frm.getReasonForConsultation()); consult.setClinicalInfo(frm.getClinicalInformation()); consult.setCurrentMeds(frm.getCurrentMedications()); consult.setAllergies(frm.getAllergies()); consult.setProviderNo(frm.getProviderNo()); consult.setDemographicId(new Integer(frm.getDemographicNo())); consult.setStatus(frm.getStatus()); consult.setStatusText(frm.getAppointmentNotes()); consult.setSendTo(frm.getSendTo()); consult.setConcurrentProblems(frm.getConcurrentProblems()); consult.setUrgency(frm.getUrgency()); consult.setSiteName(frm.getSiteName()); Boolean pWillBook = false; if (frm.getPatientWillBook() != null) { pWillBook = frm.getPatientWillBook().equals("1"); } consult.setPatientWillBook(pWillBook); if (frm.getFollowUpDate() != null && !frm.getFollowUpDate().equals("")) { date = DateUtils.parseDate(frm.getFollowUpDate(), format); consult.setFollowUpDate(date); } consultationRequestDao.persist(consult); Integer specId = new Integer(frm.getSpecialist()); ProfessionalSpecialist professionalSpecialist = professionalSpecialistDao.find(specId); if (professionalSpecialist != null) { consult.setProfessionalSpecialist(professionalSpecialist); consultationRequestDao.merge(consult); } MiscUtils.getLogger().info("saved new consult id " + consult.getId()); requestId = String.valueOf(consult.getId()); Enumeration e = request.getParameterNames(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); if (name.startsWith("ext_")) { String value = request.getParameter(name); consultationRequestExtDao .persist(createExtEntry(requestId, name.substring(name.indexOf("_") + 1), value)); } } // now that we have consultation id we can save any attached docs as well // format of input is D2|L2 for doc and lab String[] docs = frm.getDocuments().split("\\|"); for (int idx = 0; idx < docs.length; ++idx) { if (docs[idx].length() > 0) { if (docs[idx].charAt(0) == 'D') EDocUtil.attachDocConsult(providerNo, docs[idx].substring(1), requestId); else if (docs[idx].charAt(0) == 'L') ConsultationAttachLabs.attachLabConsult(providerNo, docs[idx].substring(1), requestId); } } } catch (ParseException e) { MiscUtils.getLogger().error("Invalid Date", e); } request.setAttribute("transType", "2"); } else if (submission.startsWith("Update")) { requestId = frm.getRequestId(); try { if (newSignature) { LoggedInInfo loggedInInfo = LoggedInInfo.loggedInInfo.get(); DigitalSignature signature = DigitalSignatureUtils.storeDigitalSignatureFromTempFileToDB( loggedInInfo, signatureImg, Integer.parseInt(demographicNo)); if (signature != null) { signatureId = "" + signature.getId(); } else { signatureId = signatureImg; } } else { signatureId = signatureImg; } ConsultationRequest consult = consultationRequestDao.find(new Integer(requestId)); Date date = DateUtils.parseDate(frm.getReferalDate(), format); consult.setReferralDate(date); consult.setServiceId(new Integer(frm.getService())); consult.setSignatureImg(signatureId); consult.setProviderNo(frm.getProviderNo()); consult.setLetterheadName(frm.getLetterheadName()); consult.setLetterheadAddress(frm.getLetterheadAddress()); consult.setLetterheadPhone(frm.getLetterheadPhone()); consult.setLetterheadFax(frm.getLetterheadFax()); Integer specId = new Integer(frm.getSpecialist()); ProfessionalSpecialist professionalSpecialist = professionalSpecialistDao.find(specId); consult.setProfessionalSpecialist(professionalSpecialist); if (frm.getAppointmentYear() != null && !frm.getAppointmentYear().equals("")) { date = DateUtils.parseDate(frm.getAppointmentYear() + "-" + frm.getAppointmentMonth() + "-" + frm.getAppointmentDay(), format); consult.setAppointmentDate(date); date = DateUtils.setHours(date, new Integer(appointmentHour)); date = DateUtils.setMinutes(date, new Integer(frm.getAppointmentMinute())); consult.setAppointmentTime(date); } consult.setReasonForReferral(frm.getReasonForConsultation()); consult.setClinicalInfo(frm.getClinicalInformation()); consult.setCurrentMeds(frm.getCurrentMedications()); consult.setAllergies(frm.getAllergies()); consult.setDemographicId(new Integer(frm.getDemographicNo())); consult.setStatus(frm.getStatus()); consult.setStatusText(frm.getAppointmentNotes()); consult.setSendTo(frm.getSendTo()); consult.setConcurrentProblems(frm.getConcurrentProblems()); consult.setUrgency(frm.getUrgency()); consult.setSiteName(frm.getSiteName()); Boolean pWillBook = false; if (frm.getPatientWillBook() != null) { pWillBook = frm.getPatientWillBook().equals("1"); } consult.setPatientWillBook(pWillBook); if (frm.getFollowUpDate() != null && !frm.getFollowUpDate().equals("")) { date = DateUtils.parseDate(frm.getFollowUpDate(), format); consult.setFollowUpDate(date); } consultationRequestDao.merge(consult); consultationRequestExtDao.clear(Integer.parseInt(requestId)); Enumeration e = request.getParameterNames(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); if (name.startsWith("ext_")) { String value = request.getParameter(name); consultationRequestExtDao .persist(createExtEntry(requestId, name.substring(name.indexOf("_") + 1), value)); } } } catch (ParseException e) { MiscUtils.getLogger().error("Error", e); } request.setAttribute("transType", "1"); } else if (submission.equalsIgnoreCase("And Print Preview")) { requestId = frm.getRequestId(); } frm.setRequestId(""); request.setAttribute("teamVar", sendTo); if (submission.endsWith("And Print Preview")) { request.setAttribute("reqId", requestId); if (OscarProperties.getInstance().isConsultationFaxEnabled()) { return mapping.findForward("printIndivica"); } else if (IsPropertiesOn.propertiesOn("CONSULT_PRINT_PDF")) { return mapping.findForward("printpdf"); } else if (IsPropertiesOn.propertiesOn("CONSULT_PRINT_ALT")) { return mapping.findForward("printalt"); } else { return mapping.findForward("print"); } } else if (submission.endsWith("And Fax")) { request.setAttribute("reqId", requestId); if (OscarProperties.getInstance().isConsultationFaxEnabled()) { return mapping.findForward("faxIndivica"); } else { return mapping.findForward("fax"); } } else if (submission.endsWith("esend")) { // upon success continue as normal with success message // upon failure, go to consultation update page with message try { doHl7Send(Integer.parseInt(requestId)); WebUtils.addResourceBundleInfoMessage(request, "oscarEncounter.oscarConsultationRequest.ConfirmConsultationRequest.msgCreatedUpdateESent"); } catch (Exception e) { logger.error("Error contacting remote server.", e); WebUtils.addResourceBundleErrorMessage(request, "oscarEncounter.oscarConsultationRequest.ConfirmConsultationRequest.msgCreatedUpdateESendError"); ParameterActionForward forward = new ParameterActionForward(mapping.findForward("failESend")); forward.addParameter("de", demographicNo); forward.addParameter("requestId", requestId); return forward; } } ParameterActionForward forward = new ParameterActionForward(mapping.findForward("success")); forward.addParameter("de", demographicNo); return forward; }