/** * Compare two Date values and return min or max */ public static Date minMaxDate(Date d1, String s, boolean max) { Date d2 = Utils.toDate(s); if(d1 == null) { return d2; } else if(d2 == null) { return d1; } if((max && d1.before(d2)) || (!max && d1.after(d2))) { return d2; } return d1; }
maxDateValue = java.sql.Date.valueOf(maxValueString); if (maxDateValue == null || colDateValue.after(maxDateValue)) { return colDateValue.toString();
@Override protected void checkValues() { if (min.after(max)) { throw new IllegalArgumentException("max must be after min"); } }
@Test public void testUpsertDateValues() throws Exception { long ts = nextTimestamp(); Date now = new Date(System.currentTimeMillis()); ensureTableCreated(getUrl(),TestUtil.PTSDB_NAME,null, ts-2); Properties props = new Properties(); props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 1)); // Execute at timestamp 1 Connection conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props); String dateString = "1999-01-01 02:00:00"; PreparedStatement upsertStmt = conn.prepareStatement("upsert into ptsdb(inst,host,date) values('aaa','bbb',to_date('" + dateString + "'))"); int rowsInserted = upsertStmt.executeUpdate(); assertEquals(1, rowsInserted); upsertStmt = conn.prepareStatement("upsert into ptsdb(inst,host,date) values('ccc','ddd',current_date())"); rowsInserted = upsertStmt.executeUpdate(); assertEquals(1, rowsInserted); conn.commit(); props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 2)); // Execute at timestamp 1 conn = DriverManager.getConnection(PHOENIX_JDBC_URL, props); String select = "SELECT date,current_date() FROM ptsdb"; ResultSet rs = conn.createStatement().executeQuery(select); Date then = new Date(System.currentTimeMillis()); assertTrue(rs.next()); Date date = DateUtil.parseDate(dateString); assertEquals(date,rs.getDate(1)); assertTrue(rs.next()); assertTrue(rs.getDate(1).after(now) && rs.getDate(1).before(then)); assertFalse(rs.next()); }
@Test public void testUpsertDateValues() throws Exception { String tableName = generateUniqueName(); Date now = new Date(EnvironmentEdgeManager.currentTimeMillis()); ensureTableCreated(getUrl(), tableName, TestUtil.PTSDB_NAME, null, null, null); Properties props = new Properties(); Connection conn = DriverManager.getConnection(getUrl(), props); String dateString = "1999-01-01 02:00:00"; PreparedStatement upsertStmt = conn.prepareStatement("upsert into " + tableName + "(inst,host,\"DATE\") values('aaa','bbb',to_date('" + dateString + "'))"); int rowsInserted = upsertStmt.executeUpdate(); assertEquals(1, rowsInserted); upsertStmt = conn.prepareStatement("upsert into " + tableName + "(inst,host,\"DATE\") values('ccc','ddd',current_date())"); rowsInserted = upsertStmt.executeUpdate(); assertEquals(1, rowsInserted); conn.commit(); conn = DriverManager.getConnection(getUrl(), props); String select = "SELECT \"DATE\",current_date() FROM " + tableName; ResultSet rs = conn.createStatement().executeQuery(select); Date then = new Date(EnvironmentEdgeManager.currentTimeMillis()); assertTrue(rs.next()); Date date = DateUtil.parseDate(dateString); assertEquals(date,rs.getDate(1)); assertTrue(rs.next()); assertTrue(rs.getDate(1).after(now) && rs.getDate(1).before(then)); assertFalse(rs.next()); }
assertEquals(null, rs.getString(1)); assertEquals(ROW6, rs.getString(2)); assertTrue(rs.getDate(3).after(now) && rs.getDate(3).before(then)); assertEquals(null, rs.getBigDecimal(4)); assertEquals(null, rs.getString(1)); assertEquals(ROW7, rs.getString(2)); assertTrue(rs.getDate(3).after(now) && rs.getDate(3).before(then)); assertTrue(BigDecimal.valueOf(70).compareTo(rs.getBigDecimal(4)) == 0); assertEquals(null, rs.getString(1)); assertEquals(ROW8, rs.getString(2)); assertTrue(rs.getDate(3).after(now) && rs.getDate(3).before(then)); assertTrue(BigDecimal.valueOf(60).compareTo(rs.getBigDecimal(4)) == 0); assertEquals(null, rs.getString(1)); assertEquals(ROW9, rs.getString(2)); assertTrue(rs.getDate(3).after(now) && rs.getDate(3).before(then)); assertTrue(BigDecimal.valueOf(50).compareTo(rs.getBigDecimal(4)) == 0);
assertTrue(d >= 0.0 && d <= 1.0); Date date = rs.getDate(4); assertTrue(date.after(new Date(System.currentTimeMillis()))); assertEquals("eee",rs.getString(5)); assertEquals("f",rs.getString(6));
assertEquals(null, rs.getString(1)); assertEquals(ROW6, rs.getString(2)); assertTrue(rs.getDate(3).after(now) && rs.getDate(3).before(then)); assertEquals(null, rs.getBigDecimal(4)); assertEquals(null, rs.getString(1)); assertEquals(ROW7, rs.getString(2)); assertTrue(rs.getDate(3).after(now) && rs.getDate(3).before(then)); assertTrue(BigDecimal.valueOf(70).compareTo(rs.getBigDecimal(4)) == 0); assertEquals(null, rs.getString(1)); assertEquals(ROW8, rs.getString(2)); assertTrue(rs.getDate(3).after(now) && rs.getDate(3).before(then)); assertTrue(BigDecimal.valueOf(60).compareTo(rs.getBigDecimal(4)) == 0); assertEquals(null, rs.getString(1)); assertEquals(ROW9, rs.getString(2)); assertTrue(rs.getDate(3).after(now) && rs.getDate(3).before(then)); assertTrue(BigDecimal.valueOf(50).compareTo(rs.getBigDecimal(4)) == 0);
assertEquals(null, rs.getString(1)); assertEquals(ROW6, rs.getString(2)); assertTrue(rs.getDate(3).after(now) && rs.getDate(3).before(then)); assertEquals(null, rs.getBigDecimal(4)); assertEquals(null, rs.getString(1)); assertEquals(ROW7, rs.getString(2)); assertTrue(rs.getDate(3).after(now) && rs.getDate(3).before(then)); assertTrue(BigDecimal.valueOf(70).compareTo(rs.getBigDecimal(4)) == 0); assertEquals(null, rs.getString(1)); assertEquals(ROW8, rs.getString(2)); assertTrue(rs.getDate(3).after(now) && rs.getDate(3).before(then)); assertTrue(BigDecimal.valueOf(60).compareTo(rs.getBigDecimal(4)) == 0); assertEquals(null, rs.getString(1)); assertEquals(ROW9, rs.getString(2)); assertTrue(rs.getDate(3).after(now) && rs.getDate(3).before(then)); assertTrue(BigDecimal.valueOf(50).compareTo(rs.getBigDecimal(4)) == 0); assertEquals(ROW6, rs.getString(1)); assertEquals(null, rs.getString(2)); assertTrue(rs.getDate(3).after(now) && rs.getDate(3).before(then)); assertEquals(null, rs.getBigDecimal(4)); assertEquals(ROW7, rs.getString(1)); assertEquals(null, rs.getString(2)); assertTrue(rs.getDate(3).after(now) && rs.getDate(3).before(then)); assertTrue(BigDecimal.valueOf(70).compareTo(rs.getBigDecimal(4)) == 0);
assertEquals(null, rs.getString(1)); assertEquals(ROW6, rs.getString(2)); assertTrue(rs.getDate(3).after(now) && rs.getDate(3).before(then)); assertEquals(null, rs.getBigDecimal(4)); assertEquals(null, rs.getString(1)); assertEquals(ROW7, rs.getString(2)); assertTrue(rs.getDate(3).after(now) && rs.getDate(3).before(then)); assertTrue(BigDecimal.valueOf(70).compareTo(rs.getBigDecimal(4)) == 0); assertEquals(null, rs.getString(1)); assertEquals(ROW8, rs.getString(2)); assertTrue(rs.getDate(3).after(now) && rs.getDate(3).before(then)); assertTrue(BigDecimal.valueOf(60).compareTo(rs.getBigDecimal(4)) == 0); assertEquals(null, rs.getString(1)); assertEquals(ROW9, rs.getString(2)); assertTrue(rs.getDate(3).after(now) && rs.getDate(3).before(then)); assertTrue(BigDecimal.valueOf(50).compareTo(rs.getBigDecimal(4)) == 0); assertEquals(ROW6, rs.getString(1)); assertEquals(null, rs.getString(2)); assertTrue(rs.getDate(3).after(now) && rs.getDate(3).before(then)); assertEquals(null, rs.getBigDecimal(4)); assertEquals(ROW7, rs.getString(1)); assertEquals(null, rs.getString(2)); assertTrue(rs.getDate(3).after(now) && rs.getDate(3).before(then)); assertTrue(BigDecimal.valueOf(70).compareTo(rs.getBigDecimal(4)) == 0);
@Override protected void checkValues() { if (min.after(max)) { throw new IllegalArgumentException("max must be after min"); } }
public boolean after(org.openurp.edu.base.model.Semester semester) { return beginOn.after(semester.getEndOn()); }
protected List<TransactionArchive> retrieveTransactionArchives(String sourceKemid, Date lastProcessDate, String targetEtranCode) { KualiDecimal totalCashIncomeEtranCode = KualiDecimal.ZERO; List<TransactionArchive> transactionArchiveList = null; Map fieldValues = new HashMap(); fieldValues.put(EndowPropertyConstants.KEMID, sourceKemid); fieldValues.put(EndowPropertyConstants.TRANSACTION_LINE_ENDOWMENT_TRANSACTION_CODE, targetEtranCode); transactionArchiveList = (List) businessObjectService.findMatching(TransactionArchive.class, fieldValues); for (TransactionArchive transactionArchive : transactionArchiveList) { if (!transactionArchive.getPostedDate().after(lastProcessDate)) { transactionArchiveList.remove(transactionArchive); } } return transactionArchiveList; }
public void setExpirationDate(Date expirationDate) { checkUpdateState(); this.expirationDate = expirationDate; if (expirationDate != null && new Date(new java.util.Date().getTime()).after(expirationDate)) { setExpired(true); } else { setExpired(false); } }
/** * Checks to see if the end date is after the begin date * * @param begin * @param end * @param propertyName * @return true if end is after begin, false otherwise */ protected boolean checkEndAfterBegin(Date begin, Date end, String propertyName) { boolean success = true; if (ObjectUtils.isNotNull(begin) && ObjectUtils.isNotNull(end) && !end.after(begin)) { putFieldError(propertyName, KFSKeyConstants.ERROR_ENDING_DATE_NOT_AFTER_BEGIN); success = false; } return success; }
/** * This method checks if customer end date is valid: 1. if a new address is being added, customer end date must be a future date * 2. if inactivating an address, customer end date must be current or future date * * @param endDate * @param canBeTodaysDateFlag * @return True if endDate is valid. */ public boolean checkEndDateIsValid(Date endDate, boolean canBeTodaysDateFlag) { boolean isValid = true; if (ObjectUtils.isNull(endDate)) return isValid; Timestamp today = dateTimeService.getCurrentTimestamp(); today.setTime(DateUtils.truncate(today, Calendar.DAY_OF_MONTH).getTime()); // end date must be todays date or future date if (canBeTodaysDateFlag) { if (endDate.before(today)) { isValid = false; } } // end date must be a future date else { if (!endDate.after(today)) { isValid = false; } } return isValid; }
/** * This method checks to see if the account expiration date is today's date or earlier * * @param newAccount * @return fails if the expiration date is null or after today's date */ protected boolean checkAccountExpirationDateValidTodayOrEarlier(Account newAccount) { // get today's date, with no time component Date todaysDate = new Date(getDateTimeService().getCurrentDate().getTime()); todaysDate.setTime(DateUtils.truncate(todaysDate, Calendar.DAY_OF_MONTH).getTime()); // TODO: convert this to using Wes' Kuali DateUtils once we're using Date's instead of Timestamp // get the expiration date, if any Date expirationDate = newAccount.getAccountExpirationDate(); if (ObjectUtils.isNull(expirationDate)) { putFieldError("accountExpirationDate", KFSKeyConstants.ERROR_DOCUMENT_ACCMAINT_ACCT_CANNOT_BE_CLOSED_EXP_DATE_INVALID); return false; } // when closing an account, the account expiration date must be the current date or earlier expirationDate.setTime(DateUtils.truncate(expirationDate, Calendar.DAY_OF_MONTH).getTime()); if (expirationDate.after(todaysDate)) { putFieldError("accountExpirationDate", KFSKeyConstants.ERROR_DOCUMENT_ACCMAINT_ACCT_CANNOT_BE_CLOSED_EXP_DATE_INVALID); return false; } return true; }
/** * Validates that the total of all non-terminated records is 1 (100%). * * @return true if valid, false otherwise */ private boolean validatePayoutInstructionsPercentTotal() { boolean isValid = true; DateTimeService dateTimeService = SpringContext.getBean(DateTimeService.class); Date currentDate = dateTimeService.getCurrentSqlDate(); KualiDecimal total = KualiDecimal.ZERO; for (KemidPayoutInstruction payoutInstruction : newKemid.getKemidPayoutInstructions()) { if (payoutInstruction.getEndDate() == null || payoutInstruction.getEndDate().after(currentDate)) { total = total.add(payoutInstruction.getPercentOfIncomeToPayToKemid()); } } KualiDecimal one = new KualiDecimal(1); if (one.compareTo(total) != 0) { putFieldError(EndowPropertyConstants.KEMID_PAY_INSTRUCTIONS_TAB, EndowKeyConstants.KEMIDConstants.ERROR_KEMID_TOTAL_OFF_ALL_PAYOUT_RECORDS_MUST_BE_ONE); isValid = false; } return isValid; }