List of usage examples for java.sql Date getTime
public long getTime()
From source file:org.kuali.coeus.common.committee.impl.meeting.MeetingServiceImplBase.java
protected Timestamp addHrMinToDate(Time12HrFmt viewTime) { java.util.Date dt = new java.util.Date(0); // this is actually 12-31-1969 19:00. its GMT time DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy h:mm a"); try {/*from w ww .j a v a 2s. c om*/ // support localization. dt = dateFormat.parse("01/01/1970 " + viewTime.getTime() + " " + viewTime.getMeridiem()); return new Timestamp(dt.getTime()); } catch (Exception e) { // TODO : not sure to throw runtimeexception or not. // folowing may convert date to 07-02-1970 iftz is gmt+12 or more dt = DateUtils.round(dt, Calendar.DAY_OF_MONTH); return new Timestamp(DateUtils.addMinutes(dt, viewTime.findMinutes()).getTime()); } }
From source file:com.mss.msp.util.DateUtility.java
public Date strToTimeStampObj1(String dateAccessor) { java.util.Date date = null; try {// ww w . ja va 2 s.c om int indDash1 = dateAccessor.indexOf("/", 0); int indDash2 = dateAccessor.indexOf("/", indDash1 + 1); if (indDash1 == -1 || indDash2 == -1) { int _ind1 = dateAccessor.indexOf("-", 0); int _ind2 = dateAccessor.indexOf("-", _ind1 + 1); //returns index of " - " in given String Object if (_ind1 == 4 && (_ind2 == 7 || _ind2 == 6)) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); date = sdf.parse(dateAccessor); dateActual = new java.sql.Date(date.getTime()); } } else { SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd"); date = sdf.parse(usTimeStampToSqlTimeStamp(dateAccessor)); dateActual = new java.sql.Date(date.getTime()); } } catch (ParseException pe) { System.out.println("ParseException in" + pe); } return dateActual; }
From source file:org.kuali.kfs.gl.businessobject.OriginEntryFull.java
protected java.sql.Date parseDate(String sdate, boolean beLenientWithDates) throws ParseException { if ((sdate == null) || (sdate.trim().length() == 0)) { return null; } else {/*from w w w . ja v a 2s . c o m*/ SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT); sdf.setLenient(beLenientWithDates); java.util.Date d = sdf.parse(sdate); return new Date(d.getTime()); } }
From source file:edu.ku.kuali.kra.negotiations.service.NegotiationServiceImpl.java
@Override public List<NegotiationActivityHistoryLineBean> getNegotiationActivityHistoryLineBeans( List<NegotiationActivity> activities) { List<NegotiationActivityHistoryLineBean> beans = new ArrayList<NegotiationActivityHistoryLineBean>(); for (NegotiationActivity activity : activities) { if (activity.getLocation() != null && activity.getActivityType() != null) { NegotiationActivityHistoryLineBean bean = new NegotiationActivityHistoryLineBean(activity); beans.add(bean);// w w w . j ava2 s .c om } } Collections.sort(beans); // now set the effective dates and calculate the location days. Date previousStartDate = null; Date previousEndDate = null; String previousLocation = ""; int counter = 1; List<NegotiationActivityHistoryLineBean> beansToReturn = new ArrayList<NegotiationActivityHistoryLineBean>(); for (NegotiationActivityHistoryLineBean bean : beans) { if (StringUtils.equals(previousLocation, bean.getLocation())) { if (isDateBetween(bean.getStartDate(), previousStartDate, previousEndDate) && isDateBetween(bean.getEndDate(), previousStartDate, previousEndDate)) { // current date range lies within the previous date range setBeanStuff(bean, null, null, "0 Days"); // leave previous alone } else if (isDateBetween(bean.getStartDate(), previousStartDate, previousEndDate) && (bean.getEndDate() != null) && bean.getEndDate().after(previousEndDate)) { // current date range starts within the previous range, but // finishes past it. Date previousEndDatePlusOneDay = new Date( previousEndDate.getTime() + NegotiationActivity.MILLISECS_PER_DAY); previousEndDate = bean.getEndDate(); setBeanStuff(bean, previousEndDatePlusOneDay, bean.getEndDate(), NegotiationActivity.getNumberOfDays(previousEndDatePlusOneDay, bean.getEndDate())); } else { // completely separate range. previousStartDate = bean.getStartDate(); previousEndDate = bean.getEndDate(); setBeanStuff(bean, bean.getStartDate(), bean.getEndDate(), NegotiationActivity.getNumberOfDays(bean.getStartDate(), bean.getEndDate())); } } else { // new location so set the effective date previousStartDate = bean.getStartDate(); previousEndDate = bean.getEndDate(); previousLocation = bean.getLocation(); setBeanStuff(bean, bean.getStartDate(), bean.getEndDate(), NegotiationActivity.getNumberOfDays(bean.getStartDate(), bean.getEndDate())); // BUKC-0150: Negotiation - Line skip on Activity/Location History page (Neg. QA Testing Issue 13) /* * if (!beansToReturn.isEmpty()) { * beansToReturn.add(new NegotiationActivityHistoryLineBean()); * } */ } bean.setLineNumber(String.valueOf(counter)); beansToReturn.add(bean); counter++; } return beansToReturn; }
From source file:org.kuali.kfs.module.tem.service.impl.TravelerServiceImpl.java
/** * @see org.kuali.kfs.module.tem.service.TravelerService#copyKimDataToTemProfile(org.kuali.kfs.module.tem.businessobject.TemProfile, org.kuali.rice.kim.bo.Person, org.kuali.rice.kim.bo.entity.dto.KimEntityInfo) *//*from w w w.j av a 2 s. c om*/ @Override public void copyKimDataToTemProfile(TemProfile profile, Person principal, Entity kimEntity) { // copy principal data if (ObjectUtils.isNotNull(kimEntity)) { profile.setFirstName(principal.getFirstName().toUpperCase()); profile.setMiddleName(principal.getMiddleName().toUpperCase()); profile.setLastName(principal.getLastName().toUpperCase()); } TemProfileAddress profileAddress = new TemProfileAddress(); if (ObjectUtils.isNotNull(profile.getTemProfileAddress())) { profileAddress = profile.getTemProfileAddress(); } profileAddress.setProfileId(profile.getProfileId()); profileAddress.setStreetAddressLine1(StringUtils.upperCase(principal.getAddressLine1Unmasked())); profileAddress.setStreetAddressLine2(StringUtils.upperCase(principal.getAddressLine2Unmasked())); profileAddress.setCityName(StringUtils.upperCase(principal.getAddressCity())); profileAddress.setStateCode(StringUtils.upperCase(principal.getAddressStateProvinceCodeUnmasked())); profileAddress.setZipCode(principal.getAddressPostalCodeUnmasked()); profileAddress.setCountryCode(StringUtils.upperCase(principal.getAddressCountryCodeUnmasked())); profile.setTemProfileAddress(profileAddress); profile.setEmailAddress(StringUtils.upperCase(principal.getEmailAddressUnmasked())); profile.setPhoneNumber(principal.getPhoneNumberUnmasked()); String primaryDeptCode[] = principal.getPrimaryDepartmentCode().split("-"); if (primaryDeptCode != null && primaryDeptCode.length == 2) { profile.setHomeDeptChartOfAccountsCode(primaryDeptCode[0]); profile.setHomeDeptOrgCode(primaryDeptCode[1]); } profile.refreshReferenceObject("homeDeptOrg"); profile.setEmployeeId(principal.getEmployeeId()); // Copy kim info to profile if (ObjectUtils.isNotNull(kimEntity)) { if (ObjectUtils.isNotNull(kimEntity.getBioDemographics())) { String birthDate = kimEntity.getBioDemographics().getBirthDate(); java.util.Date parsedBirthDate = new java.util.Date(); try { parsedBirthDate = new SimpleDateFormat(EntityBioDemographics.BIRTH_DATE_FORMAT) .parse(birthDate); } catch (ParseException pe) { LOG.error("Error parsing EntityBioDemographics birth date: '" + birthDate + "'", pe); } Date dateOfBirth = new Date(parsedBirthDate.getTime()); profile.setDateOfBirth(dateOfBirth); profile.setGender(kimEntity.getBioDemographics().getGenderCode()); } List<EntityCitizenship> citizenships = kimEntity.getCitizenships(); if (ObjectUtils.isNotNull(citizenships) && citizenships.size() > 0) { profile.setCitizenship(citizenships.get(0).getCountryCode()); } } }
From source file:com.eyeq.pivot4j.impl.PivotModelImpl.java
/** * @param connection//w w w.j ava 2 s. c om * @param mdx * @return * @throws OlapException */ protected CellSet executeMdx(OlapConnection connection, String mdx) throws OlapException { if (logger.isDebugEnabled()) { logger.debug(mdx); } Date start = new Date(System.currentTimeMillis()); OlapStatement stmt = connection.createStatement(); CellSet result = stmt.executeOlapQuery(mdx); long duration = System.currentTimeMillis() - start.getTime(); if (logger.isInfoEnabled()) { logger.info(String.format("Query execution time : %d ms", duration)); } fireQueryExecuted(start, duration, mdx); return result; }
From source file:org.rti.zcore.dar.struts.action.FormAction.java
/** * Create record from form./* w w w .j av a 2 s.co m*/ * * @param mapping * @param form * @param request * @param response * @return ActionForward * @throws Exception */ public ActionForward doExecute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // Extract attributes we will need HttpSession session = request.getSession(); Principal user = request.getUserPrincipal(); String username = user.getName(); DynaValidatorForm dynaForm = null; int formId = 0; String formName = mapping.getParameter().trim(); Long formIdL = (Long) DynaSiteObjects.getFormNameMap().get(formName); formId = formIdL.intValue(); ActionMessages errors = new ActionMessages(); SessionSubject sessionPatient = null; Long patientId = null; String eventUuid = null; dynaForm = (DynaValidatorForm) form; Site site = SessionUtil.getInstance(session).getClientSettings().getSite(); Long siteId = site.getId(); // Get a form and flow from the formDef; add them to the encounter Form formDef = (Form) DynaSiteObjects.getForms().get(new Long(formId)); Long formTypeId = formDef.getFormTypeId(); //FormType formType = formDef.getFormType(); EncounterData vo = null; Connection conn = null; try { conn = DatabaseUtils.getZEPRSConnection(username); if (formDef.isRequireReauth()) { try { AuthManager.confirmIdentity(conn, request, user.getName(), request.getParameter("password")); } catch (UserUnauthorizedException e) { errors.add("errors", new ActionMessage("errors.userunauthorized")); saveErrors(request, errors); try { String forwardName = (String) DynaSiteObjects.getFormNames().get(formName); if (forwardName == null) { return mapping.getInputForward(); } else { if (forwardName.equals("demographics")) { return mapping.getInputForward(); } else { return mapping.findForward(forwardName + "Error"); } } } catch (Exception e1) { return mapping.getInputForward(); } } } if (formName.equals("PatientRegistration")) { //ActionMessages errors = new ActionMessages(); // check if there is a duplicate id Object item = dynaForm.get("patient_id_number"); if (item != null) { String zeprsId = (String) item; Boolean status = PatientDAO.checkPatientId(conn, zeprsId); if (status == Boolean.FALSE) { errors.add("errors", new ActionMessage("errors.duplicateId", zeprsId)); } } } if (formName.equals("UserInfo")) { //ActionMessages errors = new ActionMessages(); // check if password at least 8 chars Object item = dynaForm.get("password"); if (item != null) { String password = (String) item; if (password.length() < 8) { errors.add("errors", new ActionMessage("errors.password")); } } // Check for duplicate username if (dynaForm.get("username") != null) { String searchUsername = (String) dynaForm.get("username"); Object userObject; try { userObject = UserDAO.getUser(conn, searchUsername); errors.add("errors", new ActionMessage("errors.duplicate.username", searchUsername)); } catch (ObjectNotFoundException e) { // It's ok - there should not be a user. } } } //resolve the patientId - it has been either pushed via the request or gathered from the sessionPatient if (!formName.equals("PatientRegistration") && formTypeId != 5 && formTypeId != 9) { sessionPatient = (SessionSubject) SessionUtil.getInstance(session).getSessionPatient(); patientId = sessionPatient.getId(); } Long encounterId = null; try { encounterId = (Long) dynaForm.get("id"); } catch (IllegalArgumentException e) { if (request.getParameter("id") != null) { if (!request.getParameter("id").equals("")) { encounterId = Long.valueOf(request.getParameter("id")); } } } Map dynaMap = dynaForm.getMap(); Set encSet = dynaMap.entrySet(); boolean emptyForm = true; //boolean futureDateVisit = false; for (Iterator iterator = encSet.iterator(); iterator.hasNext();) { Map.Entry entry = (Map.Entry) iterator.next(); String key = (String) entry.getKey(); String value = null; try { value = (String) entry.getValue(); } catch (ClassCastException e) { if (entry.getValue().getClass().equals("Integer.class")) { Integer valueInt = (Integer) entry.getValue(); value = valueInt.toString(); } } if ((key.equals("date_visit")) || (key.equals("date_of_record"))) { Date dateVisit = Date.valueOf(value); Date now = DateUtils.getNow(); if (dateVisit.getTime() > now.getTime()) { java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat( Constants.DATE_FORMAT_EXCEL_SHORT); sdf.setTimeZone(TimeZone.getDefault()); Date valueDate = Date.valueOf(value); String formattedDate = sdf.format(valueDate.getTime()); errors.add("errors", new ActionMessage("errors.invalid.dateVisit.future", formattedDate)); saveErrors(request, errors); } } else { if (!value.equals("")) { emptyForm = false; } } } if (emptyForm) { if (formId == 132) { errors.add("errors", new ActionMessage("errors.dispensing.emptyForm")); } else { errors.add("errors", new ActionMessage("errors.emptyForm")); } saveErrors(request, errors); } if (errors.size() > 0) { saveErrors(request, errors); try { String specialFormName = (String) DynaSiteObjects.getFormNames().get("form" + formId); if (specialFormName == null) { return mapping.getInputForward(); } else { if (specialFormName.equals("demographics")) { return mapping.getInputForward(); } else { return mapping.findForward(formName + "Error"); } } } catch (Exception e1) { return mapping.getInputForward(); } } if (formId == 132) { // Patient Dispensary //ActionMessages errors = new ActionMessages(); // loop through the bridge table records int recordsPerEncounter = formDef.getRecordsPerEncounter(); for (int j = 1; j < recordsPerEncounter; j++) { String itemIdFieldName = "PBF" + j + "_item_id"; String quantityDispensedFieldName = "PBF" + j + "_dispensed"; // get the item_id Long itemId = null; Integer quantityDispensed = 0; if (!dynaForm.getMap().get(itemIdFieldName).equals("")) { itemId = Long.valueOf((String) dynaForm.getMap().get(itemIdFieldName)); } if (!dynaForm.getMap().get(quantityDispensedFieldName).equals("")) { quantityDispensed = Integer .valueOf((String) dynaForm.getMap().get(quantityDispensedFieldName)); } Integer currentBalance = 0; Integer possiblebalance = 0; if (itemId != null) { if (DynaSiteObjects.getStatusMap().get("balanceMap") != null) { HashMap<Long, StockReport> balanceMap = (HashMap<Long, StockReport>) DynaSiteObjects .getStatusMap().get("balanceMap"); StockReport stockReport = balanceMap.get(itemId); //tempStockControl = InventoryDAO.getCurrentStockBalance(conn, itemId, siteId.intValue()); if (stockReport != null) { currentBalance = stockReport.getBalanceBF(); } possiblebalance = currentBalance - quantityDispensed; dynaForm.getMap().put("balance", possiblebalance); } processBalanceMessages(conn, errors, itemId, currentBalance, possiblebalance, true); } } if (errors.size() > 0) { saveErrors(request, errors); try { String specialFormName = (String) DynaSiteObjects.getFormNames().get("form" + formId); if (specialFormName == null) { return mapping.getInputForward(); } else { if (specialFormName.equals("demographics")) { return mapping.getInputForward(); } else { return mapping.findForward(formName + "Error"); } } } catch (Exception e1) { return mapping.getInputForward(); } } } if (formId == 161) { // stock_control Integer value = 0; Integer balance = 0; Integer tempStockControlBalance = 0; Long itemId = null; // get the item_id if (!dynaForm.getMap().get("item_id").equals("")) { itemId = Long.valueOf((String) dynaForm.getMap().get("item_id")); } if (DynaSiteObjects.getStatusMap().get("balanceMap") != null) { HashMap<Long, StockReport> balanceMap = (HashMap<Long, StockReport>) DynaSiteObjects .getStatusMap().get("balanceMap"); StockReport stockReport = balanceMap.get(itemId); //tempStockControl = InventoryDAO.getCurrentStockBalance(conn, itemId, siteId.intValue()); if (stockReport != null) { tempStockControlBalance = stockReport.getBalanceBF(); } } // set the last_patient_item_id hidden field //dynaForm.getMap().put("last_patient_item_id", tempStockControl.getLast_patient_item_id()); // change the current stock balance based on the fields in this submission if (!dynaForm.getMap().get("type_of_change").equals("")) { Integer typeOfStock = Integer.valueOf((String) dynaForm.getMap().get("type_of_change")); if (!dynaForm.getMap().get("change_value").equals("")) { value = Integer.valueOf((String) dynaForm.getMap().get("change_value")); } switch (typeOfStock) { // Received case 3263: balance = tempStockControlBalance + value; break; // Issued case 3264: balance = tempStockControlBalance - value; break; // Losses case 3265: balance = tempStockControlBalance - value; break; // Pos. Adjust. case 3266: balance = tempStockControlBalance + value; break; // Neg. Adjust case 3267: balance = tempStockControlBalance - value; break; default: balance = value; break; } } else { balance = value; } processBalanceMessages(conn, errors, itemId, tempStockControlBalance, balance, false); if (errors.size() > 0) { saveErrors(request, errors); try { String specialFormName = (String) DynaSiteObjects.getFormNames().get("form" + formId); if (specialFormName == null) { return mapping.getInputForward(); } else { if (specialFormName.equals("demographics")) { return mapping.getInputForward(); } else { return mapping.findForward(formName + "Error"); } } } catch (Exception e1) { return mapping.getInputForward(); } } // set the balance hidden field dynaForm.getMap().put("balance", balance); // reset the lowStockItems /*if (Constants.LOW_STOCK_WARNING_QUANTITY != null) { List<Task> lowStockItems = null; if (DynaSiteObjects.getStatusMap().get("lowStockItems") != null) { lowStockItems = (List<Task>) DynaSiteObjects.getStatusMap().get("lowStockItems"); } if (lowStockItems != null) { int i = 0; int itemToRemove = 0; for (Task lowStockTask : lowStockItems) { i++; Long lowStockItemId = lowStockTask.getId(); if (itemId.intValue() == lowStockItemId.intValue()) { itemToRemove = i; break; } } if (itemToRemove > 0) { lowStockItems.remove(i-1); } } }*/ } // We need to calculate tempStockControl's balance field a couple of times. StockControl tempStockControl = null; Map formData = dynaForm.getMap(); try { if (formId == 128 || formId == 129 || formId == 130 || formId == 131 || formId == 181) { vo = DarFormDAO.saveForm(conn, formDef, String.valueOf(formId), patientId, formData, encounterId, siteId, username, sessionPatient); } else { vo = PopulatePatientRecord.saveForm(conn, formDef, String.valueOf(formId), patientId, formData, encounterId, siteId, username, sessionPatient); } if (formId == 161) { StockControl sc = (StockControl) vo; Long itemId = sc.getItem_id(); StockControlDAO.prepareStockforAlertList(conn, sc, null, itemId); } if (formId == 132) { // Patient Dispensary // we're processing this item here because we don't really need to do it in EncounterProcessor, // but we do need the id of the recently-saved record. // loop through the bridge table records int recordsPerEncounter = formDef.getRecordsPerEncounter(); for (int j = 1; j < recordsPerEncounter; j++) { String itemIdFieldName = "PBF" + j + "_item_id"; String quantityDispensedFieldName = "PBF" + j + "_dispensed"; // get the item_id Long itemId = null; Integer quantityDispensed = null; if (!formData.get(itemIdFieldName).equals("")) { itemId = Long.valueOf((String) formData.get(itemIdFieldName)); } if (!formData.get(quantityDispensedFieldName).equals("")) { quantityDispensed = Integer.valueOf((String) formData.get(quantityDispensedFieldName)); } if (itemId != null) { //if (tempStockControl == null) { tempStockControl = InventoryDAO.getCurrentStockBalance(conn, itemId, null); //} Integer currentBalance = tempStockControl.getBalance(); HashMap<Long, StockReport> balanceMap = (HashMap<Long, StockReport>) DynaSiteObjects .getStatusMap().get("balanceMap"); StockReport stockReport = balanceMap.get(itemId); if (stockReport != null) { stockReport.setBalanceBF(currentBalance); stockReport.setOnHand(currentBalance); balanceMap.put(itemId, stockReport); } Integer lowStockWarning = Integer.valueOf(Constants.LOW_STOCK_WARNING_QUANTITY); //Integer possiblebalance = currentBalance - quantityDispensed; if (currentBalance <= 0) { // first check if the most recent record for this item is an out-of-stock warning = 3279 try { StockControl outOfStock = InventoryDAO.getMostRecentOutOfStock(conn, itemId, null); // if record exists, we're ok } catch (ObjectNotFoundException e) { try { Date visitDateD = null; if (formData != null) { //String formName = StringManipulation.fixClassname(formDef.getName()); visitDateD = DateUtils.getVisitDate(formData, formName); } else { visitDateD = DateUtils.getNow(); } InventoryDAO.createOutOfStockRecord(conn, formDef, String.valueOf(formId), patientId, siteId, username, sessionPatient, vo, itemId, quantityDispensed, visitDateD); } catch (Exception e2) { log.error(e2); } } } } } // refreshes the StockAlertList. StockControlDAO.setStockAlertList(conn, null); } } catch (Exception e) { log.debug("formData: " + formData); log.error( "Error saving record - formId: " + formId + ", patientId: " + patientId + ", encounterId: " + encounterId + ", siteId: " + siteId + ", username: " + username + " Error: " + e); if (sessionPatient == null) { log.error("Error saving record - null sessionPatient"); } e.printStackTrace(); if (!conn.isClosed()) { conn.close(); conn = null; } request.setAttribute("exception", e); return mapping.findForward("error"); } String menuItemText = null; if (formName.equals("MenuItem")) { menuItemText = StringManipulation.escapeString(dynaForm.get("textLink").toString()); menuItemText = StringManipulation.fixFirstDigit(menuItemText); dynaForm.set("templateKey", Constants.MENUITEM_PROPERTY_PREFIX + "." + menuItemText); } //Forms that don't require patient(including admin forms) don't need the session refreshed since they aren't patient oriented // Submitting the PatientRegistration form does need the TimsSessionSubject initialised. if (formDef.isRequirePatient() == true || formName.equals("PatientRegistration") || formName.equals("PerpetratorDemographics")) { try { SessionPatientDAO.updateSessionPatient(conn, vo.getPatientId(), vo.getEventUuid(), session); // re-initialize a few vars sessionPatient = (SessionSubject) SessionUtil.getInstance(session).getSessionPatient(); eventUuid = sessionPatient.getCurrentEventUuid(); patientId = sessionPatient.getId(); } catch (ObjectNotFoundException e) { // clear out session patient - it's null SessionUtil.getInstance(session).setSessionPatient(null); } } // Reset form form.reset(mapping, request); StrutsUtils.removeFormBean(mapping, request); } catch (ServletException e) { log.error(e); } finally { if (conn != null && !conn.isClosed()) { conn.close(); } } /** * Forwards section - send user to the next form */ return createForward(request, mapping, patientId, eventUuid, dynaForm, session, formId, vo); }
From source file:org.kuali.kfs.module.tem.document.service.TravelDocumentServiceTest.java
/** * * This method tests updatePerDiemItemsFor for inserting multiple per diem expenses (5). */// w w w .j a v a 2s. c o m public final void testUpdatePerDiemExpenses_emptyList() { List<PerDiemExpense> perDiemExpenses = new ArrayList<PerDiemExpense>(); Date today = dateTimeService.getCurrentSqlDateMidnight(); Calendar cal = Calendar.getInstance(); cal.setTime(today); cal.add(Calendar.DATE, 5); Timestamp endDate = new Timestamp(cal.getTimeInMillis()); TravelDocument td = new TravelAuthorizationDocument(); td.setDocumentNumber("1"); td.setPrimaryDestinationId(23242); setDocumentHeader(td); travelDocumentService.updatePerDiemItemsFor(td, perDiemExpenses, 1, new Timestamp(today.getTime()), endDate); assertEquals(6, perDiemExpenses.size()); assertEquals(today, perDiemExpenses.get(0).getMileageDate()); assertEquals(endDate, perDiemExpenses.get(5).getMileageDate()); }
From source file:org.siphon.jssql.SqlExecutor.java
private Timestamp dateToTimeStamp(java.util.Date date) { if (this.isPostgreSQL()) { return new java.sql.Timestamp(date.getTime() + date.getTimezoneOffset() * 60000); } else {/*from w ww .j ava 2s . c o m*/ return new java.sql.Timestamp(date.getTime()); } }
From source file:com.micromux.cassandra.jdbc.JdbcRegressionTest.java
@Test public void testObjectTimestamp() throws Exception { Statement stmt = con.createStatement(); java.util.Date now = new java.util.Date(); // Create the target Column family //String createCF = "CREATE COLUMNFAMILY t74 (id BIGINT PRIMARY KEY, col1 TIMESTAMP)"; String createCF = "CREATE COLUMNFAMILY t74 (id BIGINT PRIMARY KEY, col1 TIMESTAMP)"; stmt.execute(createCF);//from www.j a v a 2 s .c o m stmt.close(); con.close(); // open it up again to see the new CF con = DriverManager .getConnection(String.format("jdbc:cassandra://%s:%d/%s?%s", HOST, PORT, KEYSPACE, OPTIONS)); Statement statement = con.createStatement(); String insert = "INSERT INTO t74 (id, col1) VALUES (?, ?);"; PreparedStatement pstatement = con.prepareStatement(insert); pstatement.setLong(1, 1L); pstatement.setObject(2, new Timestamp(now.getTime()), Types.TIMESTAMP); pstatement.execute(); ResultSet result = statement.executeQuery("SELECT * FROM t74;"); assertTrue(result.next()); assertEquals(1L, result.getLong(1)); // try reading Timestamp directly Timestamp stamp = result.getTimestamp(2); assertEquals(now, stamp); // try reading Timestamp as an object stamp = result.getObject(2, Timestamp.class); assertEquals(now, stamp); System.out.println(resultToDisplay(result, 74, "current date")); }