/** * 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; }
@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(A_VALUE, rs.getString(2)); assertTrue(rs.getDate(3).before(now) ); assertTrue(BigDecimal.valueOf(10).compareTo(rs.getBigDecimal(4)) == 0); assertEquals(null, rs.getString(1)); assertEquals(B_VALUE, rs.getString(2)); assertTrue(rs.getDate(3).before(now) ); assertTrue(BigDecimal.valueOf(26).compareTo(rs.getBigDecimal(4)) == 0); assertEquals(null, rs.getString(1)); assertEquals(C_VALUE, rs.getString(2)); assertTrue(rs.getDate(3).before(now) ); assertTrue(BigDecimal.valueOf(9).compareTo(rs.getBigDecimal(4)) == 0); assertFalse(rs.next()); assertEquals("x", rs.getString(1)); assertEquals(C_VALUE, rs.getString(2)); assertTrue(rs.getDate(3).before(now) ); assertTrue(BigDecimal.valueOf(26).compareTo(rs.getBigDecimal(4)) == 0); 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);
assertEquals(null, rs.getString(1)); assertEquals(A_VALUE, rs.getString(2)); assertTrue(rs.getDate(3).before(now) ); assertTrue(BigDecimal.valueOf(10).compareTo(rs.getBigDecimal(4)) == 0); assertEquals(null, rs.getString(1)); assertEquals(B_VALUE, rs.getString(2)); assertTrue(rs.getDate(3).before(now) ); assertTrue(BigDecimal.valueOf(26).compareTo(rs.getBigDecimal(4)) == 0); assertEquals(null, rs.getString(1)); assertEquals(C_VALUE, rs.getString(2)); assertTrue(rs.getDate(3).before(now) ); assertTrue(BigDecimal.valueOf(9).compareTo(rs.getBigDecimal(4)) == 0); assertFalse(rs.next()); assertEquals("x", rs.getString(1)); assertEquals(C_VALUE, rs.getString(2)); assertTrue(rs.getDate(3).before(now) ); assertTrue(BigDecimal.valueOf(26).compareTo(rs.getBigDecimal(4)) == 0); 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);
assertEquals(null, rs.getString(1)); assertEquals(ROW6, rs.getString(2)); assertTrue(rs.getDate(3).before(now) ); assertEquals(null, rs.getBigDecimal(4)); assertEquals(null, rs.getString(1)); assertEquals(ROW7, rs.getString(2)); assertTrue(rs.getDate(3).before(now) ); assertTrue(BigDecimal.valueOf(7).compareTo(rs.getBigDecimal(4)) == 0); assertEquals(null, rs.getString(1)); assertEquals(ROW8, rs.getString(2)); assertTrue(rs.getDate(3).before(now) ); assertTrue(BigDecimal.valueOf(6).compareTo(rs.getBigDecimal(4)) == 0); assertEquals(null, rs.getString(1)); assertEquals(ROW9, rs.getString(2)); assertTrue(rs.getDate(3).before(now) ); assertTrue(BigDecimal.valueOf(5).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(ROW6, rs.getString(2)); assertTrue(rs.getDate(3).before(now) ); assertEquals(null, rs.getBigDecimal(4)); assertEquals(null, rs.getString(1)); assertEquals(ROW7, rs.getString(2)); assertTrue(rs.getDate(3).before(now) ); assertTrue(BigDecimal.valueOf(7).compareTo(rs.getBigDecimal(4)) == 0); assertEquals(null, rs.getString(1)); assertEquals(ROW8, rs.getString(2)); assertTrue(rs.getDate(3).before(now) ); assertTrue(BigDecimal.valueOf(6).compareTo(rs.getBigDecimal(4)) == 0); assertEquals(null, rs.getString(1)); assertEquals(ROW9, rs.getString(2)); assertTrue(rs.getDate(3).before(now) ); assertTrue(BigDecimal.valueOf(5).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);
public boolean before(org.openurp.edu.base.model.Semester semester) { return endOn.before(semester.getBeginOn()); }
/** * This method returns the effective tax region rate based off the date of transaction passed in * @param dateOfTransaction * @return */ public TaxRegionRate getEffectiveTaxRegionRate(Date dateOfTransaction) { TaxRegionRate selectedTaxRegionRate = null; for (TaxRegionRate taxRegionRate : taxRegionRates) { if (taxRegionRate.getEffectiveDate().before(dateOfTransaction)) { selectedTaxRegionRate = taxRegionRate; } } return selectedTaxRegionRate; } }
/** * Method to calculate the next processing monthly date based on the frequency type * Sets the day in the calendar based on day part of the frequency code. * @param dayOfMonth * @return next processing date */ protected Date calculateNextMonthlyDate(String dayOfMonth, Date currentDate) { int dayInMonthToSet; Calendar calendar = Calendar.getInstance(); calendar.setTime(currentDate); setCalendarWithDays(calendar, dayOfMonth); while (new java.sql.Date(calendar.getTimeInMillis()).before(currentDate)) { calendar.add(Calendar.MONTH, 1); } return new java.sql.Date(calendar.getTimeInMillis()); }
/** * Method to calculate the next processing monthly date based on the frequency type * Sets the day in the calendar based on day part of the frequency code. * @param dayOfMonth * @return next processing date */ protected Date calculateNextMonthlyDate(String dayOfMonth, Date currentDate) { int dayInMonthToSet; Calendar calendar = Calendar.getInstance(); calendar.setTime(currentDate); setCalendarWithDays(calendar, dayOfMonth); while (new java.sql.Date(calendar.getTimeInMillis()).before(currentDate)) { calendar.add(Calendar.MONTH, 1); } return new java.sql.Date(calendar.getTimeInMillis()); }
protected void setExpiration(PasswordCredential credential) { Date nextExpirationDate = new Date(new java.util.Date().getTime()+maxLifeSpanInMillis); if ( credential.getExpirationDate() == null || credential.getExpirationDate().before(nextExpirationDate)) { credential.setExpirationDate(nextExpirationDate); } credential.setExpired(false); } }
@Transient public boolean isUeberfaellig() { if (isBezahlt() == true) { return false; } final DayHolder today = new DayHolder(); return (this.faelligkeit == null || this.faelligkeit.before(today.getDate()) == true); }
/** * @see org.kuali.kfs.sys.document.service.AccountingDocumentRuleHelperService#isValidReversalDate(java.sql.Date, * java.lang.String) */ public boolean isValidReversalDate(Date reversalDate, String errorPropertyName) { java.sql.Date today = SpringContext.getBean(DateTimeService.class).getCurrentSqlDateMidnight(); if (null != reversalDate && reversalDate.before(today)) { GlobalVariables.getMessageMap().putError(errorPropertyName, KFSKeyConstants.ERROR_DOCUMENT_INCORRECT_REVERSAL_DATE); return false; } else { return true; } }
/** * This method determines whether the guidelines are required, based on business rules. * * @param account - the populated Account bo to be evaluated * @return true if guidelines are required, false otherwise */ protected boolean areGuidelinesRequired(Account account) { boolean result = true; if (account.getAccountExpirationDate() != null) { Timestamp today = getDateTimeService().getCurrentTimestamp(); today.setTime(DateUtils.truncate(today, Calendar.DAY_OF_MONTH).getTime()); if (account.getAccountExpirationDate().before(today)) { result = false; } } return result; }
/** * If the reversal date on this document is in need of refreshing, refreshes the reveral date. THIS METHOD MAY CHANGE DOCUMENT STATE! * @return true if the reversal date ended up getting refreshed, false otherwise */ protected boolean refreshReversalDate() { boolean refreshed = false; if ((isAccrualType() || isRecodeType()) && getReversalDate() != null) { java.sql.Date today = SpringContext.getBean(DateTimeService.class).getCurrentSqlDateMidnight(); if (getReversalDate().before(today)) { // set the reversal date on the document setReversalDate(today); refreshed = true; } } return refreshed; }
/** * Checks that if the reveral date for the document is not null, that the reversal date has not already occurred * @see org.kuali.kfs.sys.document.validation.Validation#validate(org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent) */ public boolean validate(AttributedDocumentEvent event) { java.sql.Date today = SpringContext.getBean(DateTimeService.class).getCurrentSqlDateMidnight(); if (null != getJournalVoucherForValidation().getReversalDate() && getJournalVoucherForValidation().getReversalDate().before(today)) { GlobalVariables.getMessageMap().putError(DOCUMENT_ERROR_PREFIX + REVERSAL_DATE, KFSKeyConstants.ERROR_DOCUMENT_INCORRECT_REVERSAL_DATE); return false; } return true; }
public void add(final LiquidityEntryDO entry) { final BigDecimal amount = entry.getAmount(); this.total = NumberHelper.add(total, amount); if (entry.isPaid() == true) { this.paid = NumberHelper.add(paid, amount); counterPaid++; } else { this.open = NumberHelper.add(open, amount); if (entry.getDateOfPayment() != null && entry.getDateOfPayment().before(today) == true) { this.overdue = NumberHelper.add(overdue, amount); } } counter++; }