Example usage for org.apache.commons.lang.time DateUtils setMilliseconds

List of usage examples for org.apache.commons.lang.time DateUtils setMilliseconds

Introduction

In this page you can find the example usage for org.apache.commons.lang.time DateUtils setMilliseconds.

Prototype

public static Date setMilliseconds(Date date, int amount) 

Source Link

Document

Sets the miliseconds field to a date returning a new object.

Usage

From source file:de.hybris.platform.accountsummaryaddon.utils.XDate.java

public static Date setToEndOfDay(final Date date) {
    Date newDate = new Date(date.getTime());
    newDate = DateUtils.setHours(newDate, 23);
    newDate = DateUtils.setMinutes(newDate, 59);
    newDate = DateUtils.setSeconds(newDate, 59);
    newDate = DateUtils.setMilliseconds(newDate, 999);
    return newDate;
}

From source file:net.audumla.astronomy.algorithims.AstronomicalTest.java

@Test
public void testDateConversion2() throws Exception {
    TimeZone.setDefault(TimeZone.getTimeZone("Australia/Melbourne"));
    java.util.Date date = new Date();
    date = DateUtils.setYears(date, 2013);
    date = DateUtils.setMinutes(date, 0);
    date = DateUtils.setMonths(date, 0);
    date = DateUtils.setMilliseconds(date, 0);
    date = DateUtils.setSeconds(date, 0);
    date = DateUtils.setDays(date, 1);/*from  w  w  w.  ja v a2 s  . co  m*/
    date = DateUtils.setHours(date, 0);
    JulianDate cDate = new JulianDate(date);
    logger.debug("Algorithms: " + cDate.toDate() + " : " + cDate.toDate().getTime());
    logger.debug("Algorithms: " + date + " : " + date.getTime());
    Assert.assertEquals(cDate.toDate().getTime(), date.getTime(), 1100);

}

From source file:de.tor.tribes.ui.algo.TimeFrameVisualizer.java

private void renderDayMarkers(long pStart, long pEnd, Graphics2D pG2D) {
    Date d = new Date(pStart);
    d = DateUtils.setHours(d, 0);/*from  w  w  w .j  a  va2s  . c  om*/
    d = DateUtils.setMinutes(d, 0);
    d = DateUtils.setSeconds(d, 0);
    d = DateUtils.setMilliseconds(d, 0);

    for (long mark = d.getTime(); mark <= pEnd; mark += DateUtils.MILLIS_PER_HOUR) {
        int markerPos = Math.round((mark - pStart) / DateUtils.MILLIS_PER_MINUTE);
        pG2D.setColor(Color.YELLOW);
        pG2D.fillRect(markerPos, 20, 2, 10);
        pG2D.setColor(Color.WHITE);
        pG2D.setFont(pG2D.getFont().deriveFont(Font.BOLD, 10.0f));
        pG2D.fillRect(markerPos - 5, 15, 12, 10);
        pG2D.setColor(Color.BLACK);
        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date(mark));
        NumberFormat f = NumberFormat.getNumberInstance();
        f.setMinimumIntegerDigits(2);
        f.setMaximumFractionDigits(2);
        pG2D.drawString(f.format(cal.get(Calendar.HOUR_OF_DAY)), markerPos - 5, 23);
    }

    long currentDay = d.getTime();
    while (currentDay < pEnd) {
        currentDay += DateUtils.MILLIS_PER_DAY;
        int markerPos = Math.round((currentDay - pStart) / DateUtils.MILLIS_PER_MINUTE);
        pG2D.setColor(new Color(123, 123, 123));
        pG2D.fillRect(markerPos, 15, 3, 30);
        SimpleDateFormat f = new SimpleDateFormat("dd.MM.yy");
        String dayLabel = f.format(currentDay);
        Rectangle2D labelBounds = pG2D.getFontMetrics().getStringBounds(dayLabel, pG2D);
        pG2D.setColor(Color.YELLOW);
        int labelWidth = (int) labelBounds.getWidth() + 5;
        pG2D.fillRect(markerPos - (int) Math.rint(labelWidth / 2), 15, labelWidth, 10);
        pG2D.setColor(Color.BLACK);
        pG2D.setFont(pG2D.getFont().deriveFont(Font.BOLD, 10.0f));
        pG2D.drawString(dayLabel, markerPos - (int) Math.rint(labelWidth / 2) + 2, 23);
    }
}

From source file:org.camunda.bpm.engine.test.api.history.HistoryCleanupTest.java

private Date getNextRunWithDelay(Date date, int countEmptyRuns) {
    //ignore milliseconds because MySQL does not support them, and it's not important for test
    Date result = DateUtils.setMilliseconds(DateUtils.addSeconds(date,
            Math.min((int) (Math.pow(2., countEmptyRuns) * HistoryCleanupJobHandlerConfiguration.START_DELAY),
                    HistoryCleanupJobHandlerConfiguration.MAX_DELAY)),
            0);//w  ww  .ja  v  a2s . c o  m
    return result;
}

From source file:org.camunda.bpm.engine.test.api.history.HistoryCleanupTest.java

private Date updateTime(Date now, Date newTime) {
    Date result = now;//from   w  w w  . ja  v  a 2  s  .  c o m

    Calendar newTimeCalendar = Calendar.getInstance();
    newTimeCalendar.setTime(newTime);

    result = DateUtils.setHours(result, newTimeCalendar.get(Calendar.HOUR_OF_DAY));
    result = DateUtils.setMinutes(result, newTimeCalendar.get(Calendar.MINUTE));
    result = DateUtils.setSeconds(result, newTimeCalendar.get(Calendar.SECOND));
    result = DateUtils.setMilliseconds(result, newTimeCalendar.get(Calendar.MILLISECOND));
    return result;
}

From source file:org.carewebframework.ui.zk.DateTimebox.java

private void update(boolean open) {
    if (open) {//from   w ww.  j  a v  a  2 s .c  om
        datebox.setConstraint(getConstraint());
        Date date = getDate();
        updateDatebox(date);
        updateTimebox(DateUtil.hasTime(date) ? date : null);
        showError(null);
    } else if (ok) {
        Date date = ZKDateUtil.getTime(datebox, timebox);
        date = timebox.getValue() != null ? DateUtils.setMilliseconds(date, 1) : date;
        setDate(date);
    }
}

From source file:org.openbravo.financial.FinancialUtils.java

/**
 * Method to get the conversion rate defined at system level. If there is not a conversion rate
 * defined on the given Organization it is searched recursively on its parent organization until
 * one is found. If no conversion rate is found null is returned.
 * //from w  ww.  j a va 2s .  c o m
 * @param date
 *          Date conversion is being performed.
 * @param fromCurrency
 *          Currency to convert from.
 * @param toCurrency
 *          Currency to convert to.
 * @param org
 *          Organization of the document that needs to be converted.
 * @return a valid ConversionRate for the given parameters, null if none is found.
 */
public static ConversionRate getConversionRate(Date date, Currency fromCurrency, Currency toCurrency,
        Organization org, Client client) {
    ConversionRate conversionRate;
    // Conversion rate records do not get into account timestamp.
    Date dateWithoutTimestamp = DateUtils
            .setHours(DateUtils.setMinutes(DateUtils.setSeconds(DateUtils.setMilliseconds(date, 0), 0), 0), 0);
    // Readable Client Org filters to false as organization is filtered explicitly.
    OBContext.setAdminMode(false);
    try {
        final OBCriteria<ConversionRate> obcConvRate = OBDal.getInstance().createCriteria(ConversionRate.class);
        obcConvRate.add(Restrictions.eq(ConversionRate.PROPERTY_ORGANIZATION, org));
        obcConvRate.add(Restrictions.eq(ConversionRate.PROPERTY_CLIENT, client));
        obcConvRate.add(Restrictions.eq(ConversionRate.PROPERTY_CURRENCY, fromCurrency));
        obcConvRate.add(Restrictions.eq(ConversionRate.PROPERTY_TOCURRENCY, toCurrency));
        obcConvRate.add(Restrictions.le(ConversionRate.PROPERTY_VALIDFROMDATE, dateWithoutTimestamp));
        obcConvRate.add(Restrictions.ge(ConversionRate.PROPERTY_VALIDTODATE, dateWithoutTimestamp));
        obcConvRate.setFilterOnReadableClients(false);
        obcConvRate.setFilterOnReadableOrganization(false);
        conversionRate = (ConversionRate) obcConvRate.uniqueResult();
        if (conversionRate != null) {
            return conversionRate;
        }
        if ("0".equals(org.getId())) {
            return null;
        } else {
            return getConversionRate(date, fromCurrency, toCurrency,
                    OBContext.getOBContext().getOrganizationStructureProvider(client.getId()).getParentOrg(org),
                    client);
        }
    } catch (Exception e) {
        log4j.error("Exception calculating conversion rate.", e);
        return null;
    } finally {
        OBContext.restorePreviousMode();
    }
}