List of usage examples for org.apache.commons.lang.time DateUtils setHours
public static Date setHours(Date date, int amount)
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 w w w. j av a 2s . co 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 www.ja v a 2 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);// w ww .jav a2 s. c om 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);//www . ja v a 2s.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"; }//from w ww . j a v a2 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) {/* ww w .jav a2 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); }//from w ww . j a v a 2 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:net.audumla.climate.bom.BOMSimpleHistoricalClimateObserver.java
private void loadHistoricalData(String url) { CSVReader reader = new CSVReader( BOMDataLoader.instance().getData(BOMDataLoader.HTTP, BOMDataLoader.BOMHTTP, url)); // ArrayList<HistoricalData> history = new ArrayList<HistoricalData>(); String[] data;//from w w w. j a v a2 s.co m boolean pastHeader = false; try { while ((data = reader.readNext()) != null) { if (pastHeader) { // [, JulianDate, Minimum temperature (C), Maximum temperature (C), Rainfall (mm), Evaporation (mm), // Sunshine (hours), Direction of maximum wind gust , Speed of maximum wind gust (km/h), Time of // maximum wind gust, 9am Temperature (C), 9am relative humidity (%), 9am cloud amount (oktas), 9am // wind direction, 9am wind speed (km/h), 9am MSL pressure (hPa), 3pm Temperature (C), 3pm relative // humidity (%), 3pm cloud amount (oktas), 3pm wind direction, 3pm wind speed (km/h), 3pm MSL // pressure (hPa)] try { Date date = historyDateFormatter.parse(data[1]); Date dateM1 = DateUtils.addDays(date, -1); WritableClimateData cdNow = ClimateDataFactory .convertToWritableClimateData(historicalData.get(date)); if (cdNow == null) { cdNow = ClimateDataFactory.newWritableClimateData(this, getSource()); // now cdNow.setTime(date); historicalData.put(date, ClimateDataFactory.convertToReadOnlyClimateData(cdNow)); } WritableClimateData cdNowM1 = ClimateDataFactory .convertToWritableClimateData(historicalData.get(dateM1)); if (cdNowM1 == null) { cdNowM1 = ClimateDataFactory.newWritableClimateData(this, getSource()); // now cdNowM1.setTime(dateM1); historicalData.put(dateM1, ClimateDataFactory.convertToReadOnlyClimateData(cdNowM1)); } cdNow.setTime(date); // 2013-02-1 try { cdNow.setMinimumTemperature(SafeParse.parseDouble(data[2])); } catch (Exception e) { LOG.debug("Error setting historical field", e); } try { cdNow.setMaximumTemperature(SafeParse.parseDouble(data[3])); } catch (Exception e) { LOG.debug("Error setting historical field", e); } try { Double rain = SafeParse.parseDouble(data[4]); if (rain != null) { cdNowM1.setRainfall(rain); cdNowM1.setRainfallProbability(cdNowM1.getRainfall() > 0 ? 100d : 0d); } } catch (Exception e) { LOG.debug("Error setting historical field", e); } try { cdNow.setEvaporation(SafeParse.parseDouble(data[5])); } catch (Exception e) { LOG.debug("Error setting historical field", e); } try { cdNow.setSunshineHours(SafeParse.parseDouble(data[6])); } catch (Exception e) { LOG.debug("Error setting historical field", e); } WritableClimateObservation obs9 = ClimateDataFactory.newWritableClimateObservation(this, getSource()); WritableClimateObservation obs15 = ClimateDataFactory.newWritableClimateObservation(this, getSource()); obs9.setTime(DateUtils.setHours(date, 9)); obs15.setTime(DateUtils.setHours(date, 15)); int count = 0; try { obs9.setTemperature(SafeParse.parseDouble(data[10])); ++count; } catch (Exception e) { LOG.debug("Error setting historical field", e); } try { obs9.setHumidity(SafeParse.parseDouble(data[11])); ++count; } catch (Exception e) { LOG.debug("Error setting historical field", e); } try { obs9.setWindSpeed(SafeParse.parseDouble(data[14])); obs9.setWindDirection(data[13]); obs9.setWindSpeedHeight(10.0); ++count; } catch (Exception e) { LOG.debug("Error setting historical field", e); } if (count > 0) { cdNow.addObservation(obs9); } count = 0; try { obs15.setTemperature(SafeParse.parseDouble(data[16])); ++count; } catch (Exception e) { LOG.debug("Error setting historical field", e); } try { obs15.setHumidity(SafeParse.parseDouble(data[17])); ++count; } catch (Exception e) { LOG.debug("Error setting historical field", e); } try { obs15.setWindSpeed(SafeParse.parseDouble(data[20])); obs15.setWindSpeedHeight(10.0); obs15.setWindDirection(data[19]); ++count; } catch (Exception e) { LOG.debug("Error setting historical field", e); } if (count > 0) { cdNow.addObservation(obs15); } } catch (ParseException e) { LOG.error("Unable to parse date for historical record [" + getSource().toString() + "] - " + Arrays.toString(data), e); } } else { if (data.length > 1 && data[1].contains("Date")) { pastHeader = true; } } } } catch (IOException e) { LOG.error("Unable to load DAILY_OBSERVATION Data [" + getSource().toString() + "]", e); } }
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)); }