Java Code Examples for org.apache.commons.lang.time.DateUtils#addHours()

The following examples show how to use org.apache.commons.lang.time.DateUtils#addHours() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseQueryMetricHandler.java    From datawave with Apache License 2.0 7 votes vote down vote up
public QueryMetricsSummaryHtmlResponse processQueryMetricsHtmlSummary(List<T> queryMetrics) throws IOException {
    
    QueryMetricsSummaryHtmlResponse summary = new QueryMetricsSummaryHtmlResponse();
    Date now = new Date();
    Date hour1 = DateUtils.addHours(now, -1);
    Date hour6 = DateUtils.addHours(now, -6);
    Date hour12 = DateUtils.addHours(now, -12);
    Date day1 = DateUtils.addDays(now, -1);
    Date day7 = DateUtils.addDays(now, -7);
    Date day30 = DateUtils.addDays(now, -30);
    Date day60 = DateUtils.addDays(now, -60);
    Date day90 = DateUtils.addDays(now, -90);
    
    for (T metric : queryMetrics) {
        try {
            binSummary(metric, summary, hour1, hour6, hour12, day1, day7, day30, day60, day90);
        } catch (Exception e1) {
            log.error(e1.getMessage());
        }
    }
    
    return summary;
}
 
Example 2
Source File: BaseQueryMetricHandler.java    From datawave with Apache License 2.0 6 votes vote down vote up
public QueryMetricsSummaryResponse processQueryMetricsSummary(List<T> queryMetrics) throws IOException {
    
    QueryMetricsSummaryResponse summary = new QueryMetricsSummaryResponse();
    Date now = new Date();
    Date hour1 = DateUtils.addHours(now, -1);
    Date hour6 = DateUtils.addHours(now, -6);
    Date hour12 = DateUtils.addHours(now, -12);
    Date day1 = DateUtils.addDays(now, -1);
    Date day7 = DateUtils.addDays(now, -7);
    Date day30 = DateUtils.addDays(now, -30);
    Date day60 = DateUtils.addDays(now, -60);
    Date day90 = DateUtils.addDays(now, -90);
    
    for (T metric : queryMetrics) {
        try {
            binSummary(metric, summary, hour1, hour6, hour12, day1, day7, day30, day60, day90);
        } catch (Exception e1) {
            log.error(e1.getMessage());
        }
    }
    
    return summary;
}
 
Example 3
Source File: ManageStartEndTime.java    From ambari-logsearch with Apache License 2.0 5 votes vote down vote up
@Override
public synchronized void run() {
  synchronized (ManageStartEndTime.class) {
    startDate = DateUtils.addSeconds(startDate, UPDATE_TIME_IN_SECONDS);
    endDate = DateUtils.addHours(startDate, 1);
  }
}
 
Example 4
Source File: AuthenticationServiceTest.java    From api-layer with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void shouldParseJwtTokenAsQueryResponse() {
    String jwtToken = authService.createJwtToken(USER, DOMAIN, LTPA);

    String dateNow = new Date().toString().substring(0, 16);
    QueryResponse parsedToken = authService.parseJwtToken(jwtToken);

    assertEquals("org.zowe.apiml.security.common.token.QueryResponse", parsedToken.getClass().getTypeName());
    assertEquals(DOMAIN, parsedToken.getDomain());
    assertEquals(USER, parsedToken.getUserId());
    assertEquals(parsedToken.getCreation().toString().substring(0, 16), dateNow);
    Date toBeExpired = DateUtils.addHours(parsedToken.getCreation(), 24);
    assertEquals(parsedToken.getExpiration(), toBeExpired);
}
 
Example 5
Source File: ManageStartEndTime.java    From ambari-logsearch with Apache License 2.0 4 votes vote down vote up
private ManageStartEndTime() {
  endDate = new Date();
  startDate = DateUtils.addHours(endDate, -1);
}
 
Example 6
Source File: MysqlMethodInvocationHandler.java    From Mycat2 with GNU General Public License v3.0 4 votes vote down vote up
private SQLExpr invokeAddDate(SQLMethodInvokeExpr expr, boolean negative) throws SQLNonTransientException {
    List<SQLExpr> parameters = expr.getParameters();
    if (parameters.size() != 2) {
        throwSyntaxError(expr);
    }
    SQLExpr p1 = parameters.get(0);
    SQLExpr p2 = parameters.get(1);
    if (p1 instanceof SQLMethodInvokeExpr) {
        p1 = doInvoke((SQLMethodInvokeExpr) p1);
    }
    if (p1 instanceof SQLCharExpr) {
        String time = ((SQLCharExpr) p1).getText();
        Integer delta = null;
        String unit = null;
        if (p2 instanceof SQLIntegerExpr) {
            delta = (Integer) ((SQLIntegerExpr) p2).getNumber();
            unit = "DAY";
        } else if (p2 instanceof MySqlIntervalExpr) {
            SQLIntegerExpr value = (SQLIntegerExpr) ((MySqlIntervalExpr) p2).getValue();
            delta = (Integer) value.getNumber();
            unit = ((MySqlIntervalExpr) p2).getUnit().name();
        } else {
            throwSyntaxError(p2);
        }
        try {
            Date date = DateUtils.parseDate(time, SUPPORT_PATTERNS);
            Date result;
            delta = negative ? -delta : delta;
            if ("MONTH".equals(unit)) {
                result = DateUtils.addMonths(date, delta);
            } else if ("DAY".equals(unit)) {
                result = DateUtils.addDays(date, delta);
            } else if ("HOUR".equals(unit)) {
                result = DateUtils.addHours(date, delta);
            } else if ("MINUTE".equals(unit)) {
                result = DateUtils.addMinutes(date, delta);
            } else if ("SECOND".equals(unit)) {
                result = DateUtils.addSeconds(date, delta);
            } else {
                return null;
            }
            String ret = DateFormatUtils.format(result, "yyyy-MM-dd HH:mm:ss");
            return new SQLIdentifierExpr(ret);
        } catch (ParseException e) {
            LOGGER.error("",e);
        }
    }
    return null;
}
 
Example 7
Source File: GremlinAdapter.java    From scava with Eclipse Public License 2.0 4 votes vote down vote up
private List<GraphTraversal<Vertex, Vertex>> getFramedValuesByDuration(Duration duration, Date currentTime) throws MetricException {
	List<GraphTraversal<Vertex, Vertex>> verticesList = new ArrayList<>();

	for (int i = 0; i < duration.getCount(); i++) {

		Date timeSliceBegin = DateUtils.addHours(currentTime, (-i * duration.getDuration()));
		Date timeSliceEnd = DateUtils.addHours(currentTime, (-i * duration.getDuration()) - duration.getDuration());

		GraphTraversal<Vertex, Vertex> vertexList = graphTraversalSource.V().where(__.has("TimeStamp", P.lte(timeSliceBegin))).where(__.has("TimeStamp", P.gte(timeSliceEnd))).order()
				.by("TimeStamp", Order.incr);

		verticesList.add(vertexList);

	}

	return verticesList;
}
 
Example 8
Source File: OrderServiceImpl.java    From mmall20180107 with Apache License 2.0 3 votes vote down vote up
public void closeOrder(int hour){

        Date closeTime = DateUtils.addHours(new Date(),-hour);

        List<Order> orderList = orderMapper.selectUnPayOrder(Const.OrderStatusEnum.NO_PAY.getCode(),DateTimeUtil.dateToStr(closeTime));

        for(Order order:orderList){

            List<OrderItem> orderItemList = orderItemMapper.selectByOrderNo(order.getOrderNo());

            for(OrderItem orderItem:orderItemList){

                Integer stock = productMapper.selectStockByProductId(orderItem.getProductId());

                if(stock==null){
                    continue;
                }

                Product product = new Product();
                product.setId(orderItem.getProductId());
                product.setStock(stock+orderItem.getQuantity());

                productMapper.updateByPrimaryKeySelective(product);

            }


        }






    }