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

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

Introduction

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

Prototype

public static Date setMinutes(Date date, int amount) 

Source Link

Document

Sets the minute 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:ch.ksfx.model.AssetPricingTimeRange.java

@Transient
public Date getStartDate() {
    if (name.equalsIgnoreCase("max")) {
        return new Date(0l);
    }/*from   www.  j av a 2  s.c o  m*/

    Date fromDate = new Date();

    if (offsetMin == 0) {
        fromDate = DateUtils.setMinutes(fromDate, 0);
        fromDate = DateUtils.setSeconds(fromDate, 0);
        fromDate = DateUtils.setHours(fromDate, 0);
    } else {
        fromDate = DateUtils.addMinutes(fromDate, offsetMin * -1);
    }

    return fromDate;
}

From source file:com.exxonmobile.ace.hybris.core.btg.condition.operand.valueproviders.OrganizationTotalSpentInCurrencyLastYearOperandValueProvider.java

@Override
public Object getValue(final BTGOrganizationTotalSpentInCurrencyLastYearOperandModel operand,
        final UserModel user, final BTGConditionEvaluationScope evaluationScope) {
    if (user instanceof B2BCustomerModel) {
        final B2BUnitModel unit = getB2bUnitService()
                .getRootUnit(getB2bUnitService().getParent((B2BCustomerModel) user));

        Date startDateInclusive = DateUtils.addYears(new Date(), -1);
        startDateInclusive = DateUtils.setHours(startDateInclusive, 0);
        startDateInclusive = DateUtils.setMinutes(startDateInclusive, 0);
        startDateInclusive = DateUtils.setSeconds(startDateInclusive, 0);
        startDateInclusive = DateUtils.setMonths(startDateInclusive, Calendar.JANUARY);
        startDateInclusive = DateUtils.setDays(startDateInclusive, 1);

        final Date endDateNonInclusive = DateUtils.addYears(startDateInclusive, 1);

        final double total = getTotalSpentByBranch(unit, operand.getCurrency(), startDateInclusive,
                endDateNonInclusive, operand.getProductCatalogId(), operand.getCategoryCode());
        return Double.valueOf(total);
    }//from  w w  w. java2 s.c om
    return Double.valueOf(0);
}

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 a  2  s  . c o 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:net.audumla.climate.MockObserverClassDefinition.java

public MockObserverClassDefinition() {
    Date now = new Date();
    now = DateUtils.setDays(now, 1);/*from  w ww  .j a  va 2 s .com*/
    now = DateUtils.setMonths(now, 1);
    now = DateUtils.setYears(now, 2010);
    now = DateUtils.setHours(now, 0);
    now = DateUtils.setMinutes(now, 0);

    source = ClimateDataSourceFactory.getInstance().newInstance();
    source.setName("Mock");
    source.setElevation(20d);
    source.setLatitude(-37.84);
    source.setLongitude(144.98);

    for (int i = 0; i < 28; ++i) {
        WritableClimateData data = ClimateDataFactory.newWritableClimateData(this, getSource());
        dataList.put(DateUtils.getFragmentInDays(now, Calendar.MONTH), data);
        data.setTime(now);

        if (i < 25) {
            data.setDataSource(ClimateDataSourceFactory.decorateInstance(source));
            data.getDataSource().setType(ClimateDataSource.ClimateDataSourceType.DAILY_OBSERVATION);
            data.setAverageWindSpeed(10.0d + (i / 10d));
            data.setMaximumTemperature(10.0d + (i / 10d));
            data.setMinimumTemperature(10.0d - (i / 10d));
            data.setMinimumHumidity(60d - i);
            data.setMaximumHumidity(60d + i);
            data.setRainfall(i / 10d);
            data.setRainfallProbability(data.getRainfall() > 0 ? 100d : 0d);
            data.setSunshineHours(6d + (i / 15d));
            // data.setSolarRadiation(5 + (i / 5d));
            data.setWindSpeedHeight(10.0);
        } else {
            data.setDataSource(ClimateDataSourceFactory.decorateInstance(source));
            data.getDataSource().setType(ClimateDataSource.ClimateDataSourceType.DAILY_FORECAST);
            data.setAverageWindSpeed(10.0 + (i / 10d));
            data.setMaximumTemperature(10.0 + (i / 10d));
            data.setMinimumTemperature(10.0 - (i / 10d));
            data.setRainfall(i / 10d);
            data.setRainfallProbability(data.getRainfall() > 0 ? 80d : 0d);
            data.setSunshineHours(6d + (i / 15d));
            data.setWindSpeedHeight(10.0d);
            data.setMinimumHumidity(60d - i);
            data.setMaximumHumidity(60d + i);
        }

        if (i > 22 && i < 25) {
            now = DateUtils.setHours(now, 0);
            now = DateUtils.setMinutes(now, 0);
            for (int n = 1; n < 48; ++n) {
                WritableClimateObservation obs = ClimateDataFactory.newWritableClimateObservation(this,
                        getSource());
                obs.setDataSource(ClimateDataSourceFactory.decorateInstance(source));
                obs.getDataSource().setType(ClimateDataSource.ClimateDataSourceType.PERIODIC_OBSERVATION);
                obs.setTime(now);
                obs.setWindSpeedHeight(10.0);
                obs.setWindSpeed(data.getAverageWindSpeed() / 48d);
                if (n > 10 && n < 21) {
                    obs.setRainfall(data.getRainfall() * (n / 20d));
                } else {
                    obs.setRainfall(0d);
                }
                obs.setTemperature(data.getMinimumTemperature()
                        + (((data.getMinimumTemperature() - data.getMaximumTemperature()) / 48d) * n));
                obs.setHumidity(data.getMinimumHumidity()
                        + (((data.getMinimumHumidity() - data.getMaximumHumidity()) / 48d) * n));
                obs.setRainfallProbablity(obs.getRainfall() > 0 ? 100d : 0d);
                data.addObservation(obs);
                now = DateUtils.addMinutes(now, 30);
            }
        }

        now = DateUtils.addDays(now, 1);

    }
}

From source file:com.exxonmobile.ace.hybris.core.btg.OrganizationOrdersReportingJob.java

private List<OrganizationOrderStatisticsModel> getOrganizationOrderStatistics(final B2BUnitModel unit,
        final CurrencyModel currency, Date today, final String category) {
    String queryString = " select {stats:pk} from {OrganizationOrderStatistics as stats}   "
            + " where {stats:currency} = ?currency and {stats:unit} = ?unit                      "
            + " and {stats:date} >= ?today and {stats:date} < ?tomorrow                    ";
    if (StringUtils.isNotEmpty(category)) {
        queryString += " and {category} = ?category";
    }/* www.j a  v a 2 s .co  m*/

    today = DateUtils.setHours(today, 0);
    today = DateUtils.setMinutes(today, 0);
    today = DateUtils.setSeconds(today, 0);
    Date tomorrow = DateUtils.addDays(today, 1);
    tomorrow = DateUtils.setHours(tomorrow, 0);
    tomorrow = DateUtils.setMinutes(tomorrow, 0);
    tomorrow = DateUtils.setSeconds(tomorrow, 0);

    final Map<String, Object> attr = new HashMap<String, Object>(4);
    attr.put(OrderModel.CURRENCY, currency);
    attr.put("unit", unit);
    attr.put("today", today);
    attr.put("tomorrow", tomorrow);
    attr.put("category", category);

    final FlexibleSearchQuery query = new FlexibleSearchQuery(queryString);
    query.getQueryParameters().putAll(attr);
    final SearchResult<OrganizationOrderStatisticsModel> searchResult = flexibleSearchService.search(query);
    return searchResult.getResult();

}

From source file:com.exxonmobile.ace.hybris.core.btg.OrganizationOrdersReportingJob.java

protected Double getTotalOrdersForBranch(final Set<B2BUnitModel> branch, final CurrencyModel currency,
        Date today) {//www  . java2  s  .  c om
    final String queryString = " select sum({order:totalPrice}) from {Order as order}                  "
            + " where {order:currency} = ?currency and {order:unit} in (?branch)                       "
            + " and {order:date} >= ?today and {order:date} < ?tomorrow    AND {order:versionID} is null   ";

    today = DateUtils.setHours(today, 0);
    today = DateUtils.setMinutes(today, 0);
    today = DateUtils.setSeconds(today, 0);
    Date tomorrow = DateUtils.addDays(today, 1);
    tomorrow = DateUtils.setHours(tomorrow, 0);
    tomorrow = DateUtils.setMinutes(tomorrow, 0);
    tomorrow = DateUtils.setSeconds(tomorrow, 0);

    final Map<String, Object> attr = new HashMap<String, Object>(4);
    attr.put(OrderModel.CURRENCY, currency);
    attr.put("branch", branch);
    attr.put("today", today);
    attr.put("tomorrow", tomorrow);

    final FlexibleSearchQuery query = new FlexibleSearchQuery(queryString);
    query.getQueryParameters().putAll(attr);
    query.setResultClassList(Collections.singletonList(Double.class));
    final SearchResult<Double> total = flexibleSearchService.search(query);
    final Double orderTotal = total.getResult().iterator().hasNext() ? total.getResult().iterator().next()
            : Double.valueOf(0D);
    return (orderTotal != null ? orderTotal : Double.valueOf(0D));

}

From source file:gov.nih.nci.ess.ae.DomainToGridObjectConverter.java

private TSDateTime convert(Date day, TimeValue time) {
    if (time == null || time.isBlank()) {
        return convert(day);
    }//  w w w .java2 s. com
    day = day == null ? new Date(0) : day;
    // My apologies for the less readable expression below.
    return convert(
            DateUtils
                    .setMinutes(
                            DateUtils.setHours(day,
                                    time.isAM() ? (time.getHour() == 12 ? 0 : time.getHour())
                                            : (time.getHour() == 12 ? 12 : time.getHour() + 12)),
                            time.getMinute()));
}

From source file:com.exxonmobile.ace.hybris.core.btg.OrganizationOrdersReportingJob.java

protected Double getTotalOfOrderEntriesFilteredByProductCategory(final Set<B2BUnitModel> branch,
        final CurrencyModel currency, Date today, final String categoryCode) {
    final String queryString = " SELECT sum({entry:totalPrice}) from           "
            + " {OrderEntry AS entry                                              "
            + " JOIN Order AS order ON {order.pk} = {entry:order}                 "
            + " AND {order:versionId} IS NULL                                     "
            + " AND {order:date} >= ?today and {order:date} < ?tomorrow           "
            + " AND {order:unit} IN (?branch)                             "
            + " AND {order:currency} = ?currency                           "
            + " JOIN Product AS p ON {p.PK} = {entry:product}                     "
            + " JOIN CategoryProductRelation AS rel ON {p.PK} = {rel.target}      "
            + " JOIN Category AS cat ON {cat.PK} = {rel.source}                   "
            + " AND {cat.code} = ?category                                        "
            + " }                                                               ";
    today = DateUtils.setHours(today, 0);
    today = DateUtils.setMinutes(today, 0);
    today = DateUtils.setSeconds(today, 0);
    Date tomorrow = DateUtils.addDays(today, 1);
    tomorrow = DateUtils.setHours(tomorrow, 0);
    tomorrow = DateUtils.setMinutes(tomorrow, 0);
    tomorrow = DateUtils.setSeconds(tomorrow, 0);

    final Map<String, Object> attr = new HashMap<String, Object>(5);
    attr.put(OrderModel.CURRENCY, currency);
    attr.put("branch", branch);
    attr.put("today", today);
    attr.put("tomorrow", tomorrow);
    attr.put("category", categoryCode);

    final FlexibleSearchQuery query = new FlexibleSearchQuery(queryString);
    query.getQueryParameters().putAll(attr);
    query.setResultClassList(Collections.singletonList(Double.class));
    final SearchResult<Double> total = flexibleSearchService.search(query);
    final Double orderTotal = total.getResult().iterator().hasNext() ? total.getResult().iterator().next()
            : Double.valueOf(0D);
    return (orderTotal != null ? orderTotal : Double.valueOf(0D));

}

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);/* ww  w. j a va2 s. c  o m*/
    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);
    }
}