List of usage examples for java.sql Date getTime
public long getTime()
From source file:org.rti.zcore.dar.report.ZEPRSUtils.java
public static int getNewbornAge(Date birthDate) { Calendar cal = new GregorianCalendar(); long now = cal.getTimeInMillis(); long ageInMillis = now - birthDate.getTime(); // for some strange reason, dividing by the number of millis // in a year directly does not produce the proper result, so // instead I divide by the number of millis in a day, then // divide again by the number of days in a year Long age = new Long((ageInMillis / (1000 * 60 * 60 * 24))); return age.intValue(); }
From source file:no.polaric.aprsdb.MyDBSession.java
/** * Get an APRS item at a given point in time. *///w w w .j av a 2s . co m public AprsPoint getItem(String src, java.util.Date at) throws java.sql.SQLException { _log.debug("MyDbSession", "getItem: " + src + ", " + df.format(at)); PreparedStatement stmt = getCon().prepareStatement( " SELECT * FROM \"PosReport\"" + " WHERE src=? AND time <= ?" + " ORDER BY time DESC LIMIT 1", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); stmt.setString(1, src); stmt.setTimestamp(2, new Timestamp(at.getTime())); ResultSet rs = stmt.executeQuery(); String name[] = src.split("@", 2); AprsPoint x = null; if (name.length > 1) { Station owner = _api.getDB().getStation(name[1], null); x = new AprsObject(owner, name[0]); } else x = new Station(src); if (rs.next()) x.update( rs.getDate("time"), new AprsHandler.PosData(getRef(rs, "position"), rs.getInt("course"), rs.getInt("speed"), rs.getString("symbol").charAt(0), rs.getString("symtab").charAt(0)), null, null); return x; }
From source file:org.kuali.kra.committee.bo.CommitteeSchedule.java
/** * This method is BO persistent accessor method, which adds Time to Date on each call. * In support to UI./*from w ww . j av a 2 s. co m*/ * @return */ public Timestamp getTime() { java.util.Date dt = new java.util.Date(this.time.getTime()); dt = DateUtils.round(dt, Calendar.DAY_OF_MONTH); if (viewTime != null) { dt = new java.util.Date(0); // 12/31/1969 19:00:00 dt = DateUtils.round(dt, Calendar.DAY_OF_MONTH); dt = DateUtils.addMinutes(dt, viewTime.findMinutes()); // to set it to 1970-01-01 //dt = DateUtils.addMinutes(dt, viewTime.findMinutes()); //dt = DateUtils.addMinutes(dt, getViewTime().findMinutes()); this.time = new Timestamp(dt.getTime()); } return time; }
From source file:org.mifos.accounts.productdefinition.struts.actionforms.SavingsPrdActionForm.java
private void validateStartDateAgainstNextYearDate(ActionErrors errors, Date changedStartDate) { Calendar currentDateCalendar = new DateTimeService().getCurrentDateTime().toGregorianCalendar(); int year = currentDateCalendar.get(Calendar.YEAR); int month = currentDateCalendar.get(Calendar.MONTH); int day = currentDateCalendar.get(Calendar.DAY_OF_MONTH); Calendar nextCalendar = new GregorianCalendar(year + 1, month, day); Date nextYearDate = new Date(nextCalendar.getTimeInMillis()); if (DateUtils.getDateWithoutTimeStamp(changedStartDate.getTime()).compareTo(nextYearDate) > 0) { addError(errors, "startDate", ProductDefinitionConstants.INVALIDSTARTDATE); }//w w w. j a v a 2 s . c o m }
From source file:org.kuali.kfs.module.purap.document.service.impl.CreditMemoServiceImpl.java
/** * @see org.kuali.kfs.module.purap.document.service.CreditMemoService#markPaid(org.kuali.kfs.module.purap.document.CreditMemoDocument, * java.sql.Date)//w w w . j a v a2 s . co m */ @Override public void markPaid(VendorCreditMemoDocument cm, Date processDate) { LOG.debug("markPaid() started"); cm.setCreditMemoPaidTimestamp(new Timestamp(processDate.getTime())); purapService.saveDocumentNoValidation(cm); }
From source file:org.kuali.kfs.module.tem.document.service.impl.CorporateCardExtractionServiceImpl.java
/** * Builds the PaymentDetail for the given reimbursable travel & entertainment document * @param document the reimbursable travel & entertainment document to create a payment for * @param processRunDate the date when the extraction is occurring * @return a PaymentDetail to add to the PaymentGroup *//* w w w .ja v a 2 s .c o m*/ protected PaymentDetail buildPaymentDetail(TEMReimbursementDocument document, Date processRunDate) { if (LOG.isDebugEnabled()) { LOG.debug("buildPaymentDetail() started"); } PaymentDetail pd = new PaymentDetail(); if (StringUtils.isNotEmpty(document.getDocumentHeader().getOrganizationDocumentNumber())) { pd.setOrganizationDocNbr(document.getDocumentHeader().getOrganizationDocumentNumber()); } pd.setCustPaymentDocNbr(document.getDocumentNumber()); pd.setInvoiceDate(new java.sql.Date(processRunDate.getTime())); pd.setOrigInvoiceAmount(getPaymentAmount(document)); pd.setInvTotDiscountAmount(KualiDecimal.ZERO); pd.setInvTotOtherCreditAmount(KualiDecimal.ZERO); pd.setInvTotOtherDebitAmount(KualiDecimal.ZERO); pd.setInvTotShipAmount(KualiDecimal.ZERO); pd.setNetPaymentAmount(getPaymentAmount(document)); pd.setPrimaryCancelledPayment(Boolean.FALSE); pd.setFinancialDocumentTypeCode(getAchCheckDocumentType(document)); pd.setFinancialSystemOriginCode(KFSConstants.ORIGIN_CODE_KUALI); pd.setPurchaseOrderNbr(document.getTravelDocumentIdentifier()); pd.setOrganizationDocNbr(document.getTravelDocumentIdentifier()); int line = 0; PaymentNoteText pnt = new PaymentNoteText(); pnt.setCustomerNoteLineNbr(new KualiInteger(line++)); final String travelerId = (!ObjectUtils.isNull(document.getTemProfile()) ? (!ObjectUtils.isNull(document.getTemProfile().getPrincipal()) ? document.getTemProfile().getPrincipal().getPrincipalName() : document.getTemProfile().getCustomerNumber()) : document.getDocumentNumber()); // they got this far without a payee id? that really probably shouldn't happen pnt.setCustomerNoteText("Info: " + travelerId + " " + document.getTemProfile().getPhoneNumber()); pd.addNote(pnt); final String text = document.getDocumentHeader().getDocumentDescription(); if (!StringUtils.isBlank(text)) { pnt = getPaymentSourceHelperService().buildNoteForCheckStubText(text, line); if (LOG.isDebugEnabled()) { LOG.debug("Creating check stub text note: " + pnt.getCustomerNoteText()); } pd.addNote(pnt); } // Handle accounts, but only corporate card accounting lines List<TemSourceAccountingLine> corporateCardLines = new ArrayList<TemSourceAccountingLine>(); for (TemSourceAccountingLine accountingLine : (List<TemSourceAccountingLine>) document .getSourceAccountingLines()) { if (StringUtils.equals(TemConstants.TRAVEL_TYPE_CORP, accountingLine.getCardType())) { corporateCardLines.add(accountingLine); } } final List<PaymentAccountDetail> paymentAccounts = buildPaymentAccountDetails(corporateCardLines); for (PaymentAccountDetail pad : paymentAccounts) { pd.addAccountDetail(pad); } return pd; }
From source file:joshuatee.wx.ModelInterfaceActivity.java
private String ConvertTimeRuntoTimeString(String run_str, String time_str) { int run_int = Integer.parseInt(run_str); int time_int = Integer.parseInt(time_str); int real_time_gmt = run_int + time_int; TimeZone tz = TimeZone.getDefault(); Date now = new Date(System.currentTimeMillis()); int offsetFromUtc = tz.getOffset(now.getTime()) / 1000; int real_time = real_time_gmt + offsetFromUtc / 60 / 60; int hour_of_day = real_time % 24; String am_pm = ""; if (hour_of_day > 11) { am_pm = "pm"; if (hour_of_day > 12) { hour_of_day = hour_of_day - 12; }/* w w w. j a va 2 s . co m*/ } else { am_pm = "am"; } int day = (int) real_time / 24; if (hour_of_day < 0) { hour_of_day = 12 + hour_of_day; am_pm = "pm"; day--; } Calendar calendar = Calendar.getInstance(); int day_of_week = calendar.get(Calendar.DAY_OF_WEEK); int hour_of_day_local = calendar.get(Calendar.HOUR_OF_DAY); if (run_int >= 0 && run_int < -offsetFromUtc / 60 / 60 && (hour_of_day_local - offsetFromUtc / 60 / 60) >= 24) { day++; } String future_day = ""; switch ((day_of_week + day) % 7) { case Calendar.SUNDAY: future_day = "Sun"; break; case Calendar.MONDAY: future_day = "Mon"; break; case Calendar.TUESDAY: future_day = "Tue"; break; case Calendar.WEDNESDAY: future_day = "Wed"; break; case Calendar.THURSDAY: future_day = "Thu"; break; case Calendar.FRIDAY: future_day = "Fri"; break; case 0: future_day = "Sat"; break; } //return future_day + " "+hour_of_day.toString()+ am_pm; return future_day + " " + Integer.toString(hour_of_day) + am_pm; }
From source file:org.kuali.coeus.common.committee.impl.bo.CommitteeScheduleBase.java
/** * This method is BO persistent accessor method, which adds Time to Date on each call. * In support to UI.//from www.j ava2 s . com * @return */ public Timestamp getTime() { if (this.time != null) { java.util.Date dt = new java.util.Date(this.time.getTime()); dt = DateUtils.round(dt, Calendar.DAY_OF_MONTH); if (viewTime != null) { dt = new java.util.Date(0); // 12/31/1969 19:00:00 dt = DateUtils.round(dt, Calendar.DAY_OF_MONTH); dt = DateUtils.addMinutes(dt, viewTime.findMinutes()); // to set it to 1970-01-01 //dt = DateUtils.addMinutes(dt, viewTime.findMinutes()); //dt = DateUtils.addMinutes(dt, getViewTime().findMinutes()); this.time = new Timestamp(dt.getTime()); } } return time; }
From source file:org.kuali.kra.common.committee.meeting.MeetingServiceImplBase.java
protected Timestamp addHrMinToDate(Timestamp time, 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 {// w ww .ja v a2 s. c o m // 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:org.kuali.kfs.module.tem.document.service.TravelDocumentServiceTest.java
/** * * This method tests updatePerDiemItemsFor for inserting a per diem into an existing list. *//*from w w w. j a v a2 s. c o m*/ public final void testUpdatePerDiemExpenses_shiftAndAddADay() { PerDiemExpense perDiemExpense = new PerDiemExpense() { @Override public MileageRate getMileageRate(java.sql.Date effectiveDate) { MileageRate rate = new MileageRate(); rate.setRate(new BigDecimal(0.45)); rate.setExpenseTypeCode("MP"); return rate; } }; Date today = dateTimeService.getCurrentSqlDateMidnight(); Calendar cal = Calendar.getInstance(); cal.setTime(today); perDiemExpense.setMiles(20); perDiemExpense.setLodging(new KualiDecimal(75.00)); perDiemExpense.setMileageDate(new Timestamp(today.getTime())); perDiemExpense.setBreakfast(true); perDiemExpense.setLunch(true); perDiemExpense.setDinner(true); PerDiemExpense perDiemExpense2 = this.copyPerDiem(perDiemExpense); cal.add(Calendar.DAY_OF_MONTH, 1); perDiemExpense2.setMileageDate(new Timestamp(cal.getTimeInMillis())); perDiemExpense2.setMiles(30); perDiemExpense2.setLodging(new KualiDecimal(75.00)); perDiemExpense2.setBreakfast(true); perDiemExpense2.setLunch(true); perDiemExpense2.setDinner(true); PerDiemExpense perDiemExpense3 = this.copyPerDiem(perDiemExpense2); cal.add(Calendar.DAY_OF_MONTH, 1); perDiemExpense3.setMileageDate(new Timestamp(cal.getTimeInMillis())); perDiemExpense3.setMiles(40); perDiemExpense3.setLodging(new KualiDecimal(55.00)); perDiemExpense3.setBreakfast(true); perDiemExpense3.setLunch(true); perDiemExpense3.setDinner(true); List<PerDiemExpense> perDiemExpenses = new ArrayList<PerDiemExpense>(); perDiemExpenses.add(perDiemExpense); perDiemExpenses.add(perDiemExpense2); perDiemExpenses.add(perDiemExpense3); Calendar moveBackOneDay = Calendar.getInstance(); moveBackOneDay.setTime(perDiemExpense.getMileageDate()); moveBackOneDay.add(Calendar.DAY_OF_MONTH, -1); Timestamp startDate = new Timestamp(moveBackOneDay.getTimeInMillis()); Timestamp endDate = perDiemExpense2.getMileageDate(); TravelDocument td = new TravelAuthorizationDocument(); td.setDocumentNumber("1"); td.setPrimaryDestinationId(23242); setDocumentHeader(td); travelDocumentService.updatePerDiemItemsFor(td, perDiemExpenses, 1, startDate, endDate); assertEquals(3, perDiemExpenses.size()); assertEquals(startDate, perDiemExpenses.get(0).getMileageDate()); assertEquals(endDate, perDiemExpenses.get(2).getMileageDate()); }