List of usage examples for org.apache.commons.lang.time DateUtils setSeconds
public static Date setSeconds(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 ww . j a v a2 s . c om 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 ww . j ava 2s .c o m*/ 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. j a v a 2s . 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: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"; }/* w w w. j a v a 2 s . c om*/ 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) {/*from w w w. j a va 2 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: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);// w w w. j ava 2 s. co 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); } }
From source file:org.camunda.bpm.engine.test.api.history.HistoryCleanupTest.java
private Date updateTime(Date now, Date newTime) { Date result = now;//from w ww . j a v a2s . 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.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. * //ww w . j a v a 2 s.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(); } }