Example usage for java.util Date setTime

List of usage examples for java.util Date setTime

Introduction

In this page you can find the example usage for java.util Date setTime.

Prototype

public void setTime(long time) 

Source Link

Document

Sets this Date object to represent a point in time that is time milliseconds after January 1, 1970 00:00:00 GMT.

Usage

From source file:jef.tools.DateUtils.java

/**
 * ???? {@link #dayBegin(Date)}?//from   w  ww .  j a v a2  s.  c om
 * 
 * @param d
 *            
 * @return 
 * @see #dayBegin(Date)
 */
public final static void truncate(Date d) {
    d.setTime(org.apache.commons.lang.time.DateUtils.truncate(d, Calendar.DATE).getTime());
}

From source file:jef.tools.DateUtils.java

/**
 * ?1
 * 
 * @throws
 */
public static void prevMillis(Date d) {
    d.setTime(d.getTime() - 1);
}

From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.mappings.CswRecordMapperFilterVisitor.java

@Override
public Object visit(PropertyIsGreaterThan filter, Object extraData) {
    Expression expr1 = visit(filter.getExpression1(), extraData);
    Expression expr2 = visit(filter.getExpression2(), expr1);

    // work around since Solr Provider doesn't support greater on temporal  (DDF-311)
    if (isTemporalQuery(expr1, expr2)) {
        // also not supported by provider (DDF-311)
        //TODO: work around 1: return getFactory(extraData).after(expr1, expr2);
        Object val = null;
        Expression other = null;/* w w  w  .  j av a 2 s .  c om*/
        if (expr2 instanceof Literal) {
            val = ((Literal) expr2).getValue();
            other = expr1;
        } else if (expr1 instanceof Literal) {
            val = ((Literal) expr1).getValue();
            other = expr2;
        }

        if (val != null) {
            Date orig = (Date) val;
            orig.setTime(orig.getTime() + 1);
            Instant start = new DefaultInstant(new DefaultPosition(orig));
            Instant end = new DefaultInstant(new DefaultPosition(new Date()));
            DefaultPeriod period = new DefaultPeriod(start, end);
            Literal literal = getFactory(extraData).literal(period);
            return getFactory(extraData).during(other, literal);
        }
    }
    return getFactory(extraData).greater(expr1, expr2);
}

From source file:org.codice.ddf.spatial.ogc.csw.catalog.endpoint.mappings.CswRecordMapperFilterVisitor.java

@Override
public Object visit(PropertyIsLessThanOrEqualTo filter, Object extraData) {
    Expression expr1 = visit(filter.getExpression1(), extraData);
    Expression expr2 = visit(filter.getExpression2(), expr1);

    // work around since solr provider doesn't support lessOrEqual on temporal (DDF-311)
    if (isTemporalQuery(expr1, expr2)) {
        // work around #1 fails, solr provider doesn't support tEquals either (DDF-311)
        //TEquals tEquals = getFactory(extraData).tequals(expr1, expr2);
        //Before before = getFactory(extraData).before(expr1, expr2);
        //return getFactory(extraData).or(tEquals, before);

        Object val = null;
        Expression other = null;/*  ww w  . j a  va2 s.  co m*/

        if (expr2 instanceof Literal) {
            val = ((Literal) expr2).getValue();
            other = expr1;
        } else if (expr1 instanceof Literal) {
            val = ((Literal) expr1).getValue();
            other = expr2;
        }

        if (val != null) {
            Date orig = (Date) val;
            orig.setTime(orig.getTime() + 1);
            Literal literal = getFactory(extraData).literal(orig);
            return getFactory(extraData).before(other, literal);
        }
    }
    return getFactory(extraData).lessOrEqual(expr1, expr2);
}

From source file:org.polymap.rhei.field.DateTimeFormField.java

public IFormField setValue(Object value) {
    Date date = (Date) value;
    Calendar cal = Calendar.getInstance(Locale.GERMANY);
    cal.setTime(date);/*w  ww .j  av a  2  s  .c o  m*/

    // modify the orig value; otherwise millis may differ as DateTime field
    // does not support millis
    cal.set(Calendar.MILLISECOND, 0);
    date.setTime(cal.getTimeInMillis());

    datetime.setDate(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DATE));
    datetime.setTime(cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND));

    // the above calls does not seem to fire events
    site.fireEvent(DateTimeFormField.this, IFormFieldListener.VALUE_CHANGE,
            loadedValue == null && date.equals(nullValue) ? null : date);
    return this;
}

From source file:es.tid.fiware.rss.expenditureLimit.processing.test.ProcessingLimitServiceTest.java

/**
 * Check that the acummulated is set to 0 and added a negative value (refund)
 *//*from w w w  . j  av a  2s.  co m*/
@Test
public void updateResetControls() {
    try {
        DbeTransaction tx = ProcessingLimitServiceTest.generateTransaction();
        // Set user for testing
        tx.setTxEndUserId("userIdUpdate");
        tx.setTcTransactionType(Constants.REFUND_TYPE);
        tx.setFtChargedTotalAmount(new BigDecimal(2));
        List<DbeExpendControl> controls = controlService.getExpendDataForUserAppProvCurrencyObCountry(
                tx.getTxEndUserId(), tx.getBmService(), tx.getTxAppProvider(), tx.getBmCurrency(),
                tx.getBmObMop().getBmObCountry());
        DbeExpendControl control = controls.get(0);
        // Reset period
        Date date = new Date();
        date.setTime((new Date()).getTime() - 100000000);
        control.setDtNextPeriodStart(date);
        DefaultTransactionDefinition def = new DefaultTransactionDefinition();
        def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
        TransactionStatus status = transactionManager.getTransaction(def);
        controlService.createOrUpdate(control);
        transactionManager.commit(status);
        limitService.updateLimit(tx);
        List<DbeExpendControl> controls2 = controlService.getExpendDataForUserAppProvCurrencyObCountry(
                tx.getTxEndUserId(), tx.getBmService(), tx.getTxAppProvider(), tx.getBmCurrency(),
                tx.getBmObMop().getBmObCountry());
        for (DbeExpendControl controlAux : controls2) {
            if (control.getId().getTxElType().equalsIgnoreCase(controlAux.getId().getTxElType())) {
                Assert.assertTrue(controlAux.getFtExpensedAmount().compareTo(new BigDecimal(-2)) == 0);
            }
        }

    } catch (RSSException e) {
        Assert.fail("Exception not expected" + e.getMessage());
    }
}

From source file:wssec.TestWSSecurityTimestamp.java

/**
 * This is a test for processing an Timestamp where the "Created" element is in the future.
 * This Timestamp should be rejected./*  w w  w  .  ja  v a2  s.c  om*/
 */
public void testFutureCreated() throws Exception {

    Document doc = unsignedEnvelope.getAsDocument();
    WSSecHeader secHeader = new WSSecHeader();
    secHeader.insertSecurityHeader(doc);

    Element timestampElement = doc.createElementNS(WSConstants.WSU_NS,
            WSConstants.WSU_PREFIX + ":" + WSConstants.TIMESTAMP_TOKEN_LN);

    DateFormat zulu = new XmlSchemaDateFormat();
    Element elementCreated = doc.createElementNS(WSConstants.WSU_NS,
            WSConstants.WSU_PREFIX + ":" + WSConstants.CREATED_LN);
    Date createdDate = new Date();
    long currentTime = createdDate.getTime() + 300000;
    createdDate.setTime(currentTime);
    elementCreated.appendChild(doc.createTextNode(zulu.format(createdDate)));
    timestampElement.appendChild(elementCreated);

    secHeader.getSecurityHeader().appendChild(timestampElement);

    if (LOG.isDebugEnabled()) {
        String outputString = org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(doc);
        LOG.debug(outputString);
    }

    //
    // Do some processing
    //
    Vector wsResult = verify(doc);
    WSSecurityEngineResult actionResult = WSSecurityUtil.fetchActionResult(wsResult, WSConstants.TS);
    assertTrue(actionResult != null);

    Timestamp receivedTimestamp = (Timestamp) actionResult.get(WSSecurityEngineResult.TAG_TIMESTAMP);
    assertTrue(receivedTimestamp != null);

    MyHandler myHandler = new MyHandler();
    if (myHandler.publicVerifyTimestamp(receivedTimestamp, 300)) {
        fail("The timestamp validation should have failed");
    }
}

From source file:jef.tools.DateUtils.java

/**
 * ??/??//from ww w  .  ja va  2  s . c o  m
 * 
 * @param d
 *            
 * @param field
 *            ??field. Calendar?
 * @return ?
 */
public final static void truncate(Date d, int field) {
    d.setTime(org.apache.commons.lang.time.DateUtils.truncate(d, field).getTime());
}

From source file:jef.tools.DateUtils.java

/**
 * /*from w  w w  .  j  a  v  a 2s . c  om*/
 */
public static void addMinute(Date d, int value) {
    d.setTime(d.getTime() + value * TimeUnit.MINUTE.ms);
}

From source file:jef.tools.DateUtils.java

/**
 * ?/* w ww  .  ja  v a2  s.c o m*/
 */
public static void addHour(Date d, int value) {
    d.setTime(d.getTime() + value * TimeUnit.HOUR.ms);
}