List of usage examples for org.apache.commons.lang3.time DateUtils addHours
public static Date addHours(final Date date, final int amount)
From source file:AIR.Common.Utilities.Dates.java
public static Date convertXST_EST(Date sourceDateTime, int offset) { // int offset = AppConfigSingleton.Instance.TimeZoneOffset; // NOTE: Larry wants to ignore the daylight saving // if (DateTime.Today.IsDaylightSavingTime()) // offset += 1; return DateUtils.addHours(sourceDateTime, offset); }
From source file:AIR.Common.Utilities.Dates.java
public static Date convertEST_XST(Date sourceDateTime, int offset) { // int offset = AppConfigSingleton.Instance.TimeZoneOffset; // NOTE: Larry wants to ignore the daylight saving // if (DateTime.Today.IsDaylightSavingTime()) // offset += 1; return DateUtils.addHours(sourceDateTime, offset * -1); }
From source file:gov.nih.nci.caintegrator.common.DateUtil.java
/** * Check for timeout. Tests if the provided date occurred the provided number * of hours before now.//from ww w .j a v a2s . co m * @param date the date to check for timeout. * @param numHours the number of hours until timeout occurs. * @return boolean */ public static boolean isTimeout(Date date, int numHours) { return DateUtils.addHours(date, numHours).before(new Date()); }
From source file:net.larry1123.elec.util.logger.FileManager.java
public static long getSplitTime() { long set = System.currentTimeMillis(); try {/* ww w .ja v a 2s .c o m*/ Date currentTime = DateUtils.parseDate(getDateFormatFromMilli(System.currentTimeMillis()), DateFormatUtils.SMTP_DATETIME_FORMAT.getPattern()); Date currentSplit = DateUtils.parseDate(getDateFormatFromMilli(getConfig().getCurrentSplit()), DateFormatUtils.SMTP_DATETIME_FORMAT.getPattern()); Date test; switch (getConfig().getSplit()) { case HOUR: test = DateUtils.addHours(currentTime, 1); test = DateUtils.setMinutes(test, 0); test = DateUtils.setSeconds(test, 0); test = DateUtils.setMilliseconds(test, 0); if (test.after(currentSplit)) { set = getConfig().getCurrentSplit(); } break; case DAY: if (!DateUtils.isSameDay(currentTime, currentSplit)) { set = getConfig().getCurrentSplit(); } break; case WEEK: test = DateUtils.ceiling(currentTime, Calendar.WEEK_OF_MONTH); if (test.after(currentSplit)) { set = getConfig().getCurrentSplit(); } break; case MONTH: test = DateUtils.ceiling(currentTime, Calendar.MONTH); if (test.after(currentSplit)) { set = getConfig().getCurrentSplit(); } break; case NONE: default: set = 0; break; } } catch (ParseException e) { set = 0; } return set; }
From source file:com.gargoylesoftware.htmlunit.SgmlPageTest.java
/** * Do not cleanup WebResponse between pages if it is cached. * @throws Exception if the test fails// w w w .j av a2s .c o m */ @Test public void onlyCacheToCleanUpWebResponse() throws Exception { try (final WebClient webClient = getWebClient()) { webClient.getOptions().setMaxInMemory(3); final List<NameValuePair> headers = new ArrayList<>(); headers.add( new NameValuePair("Expires", StringUtils.formatHttpDate(DateUtils.addHours(new Date(), 1)))); getMockWebConnection().setDefaultResponse("something", 200, "Ok", "text/html", headers); startWebServer(getMockWebConnection()); webClient.getPage(URL_FIRST); webClient.getPage(URL_FIRST); } }
From source file:com.gargoylesoftware.htmlunit.AbstractPageTest.java
/** * Do not cleanup WebResponse between pages if it is cached. * @throws Exception if the test fails// w ww. j a va 2 s . com */ @Test public void onlyCacheToCleanUpWebResponse() throws Exception { try (final WebClient webClient = getWebClient()) { webClient.getOptions().setMaxInMemory(3); final List<NameValuePair> headers = new ArrayList<>(); headers.add( new NameValuePair("Expires", StringUtils.formatHttpDate(DateUtils.addHours(new Date(), 1)))); getMockWebConnection().setDefaultResponse("something", 200, "Ok", "unknown_type", headers); startWebServer(getMockWebConnection()); webClient.getPage(URL_FIRST); webClient.getPage(URL_FIRST); } }
From source file:com.inkubator.common.util.DateTimeUtil.java
/** * * Get or return Past or Future date based on parameter</p> * <p>//from w ww . j a va 2 s . co m * <b>Parameter amount :</b> use negative symbol to get past date, use * positive symbol to get future date. Parameter amount combination with * parameter constantParameter. </p> * <p> * <b>Parameter constantParameter :</b> the type of times that will be * added. Example : CommonUtilConstant.DATE_FORMAT_MONTH</p> * <p> * <b>ConstantParameter type :</b></p> * <ul> * <li>CommonUtilConstant.DATE_FORMAT_MILLISECOND = millisecond</li> * <li>CommonUtilConstant.DATE_FORMAT_SECOND = second</li> * <li>CommonUtilConstant.DATE_FORMAT_MINUTES = minutes</li> * <li>CommonUtilConstant.DATE_FORMAT_HOURS = hours</li> * <li>CommonUtilConstant.DATE_FORMAT_DAY = day</li> * <li>CommonUtilConstant.DATE_FORMAT_WEEK = week</li> * <li>CommonUtilConstant.DATE_FORMAT_MONTH = month</li> * <li>CommonUtilConstant.DATE_FORMAT_YEAR = year</li> * </ul> * * @return Date type of past or future date * @param inputParam Date reference to calculate * @param timeDifference Integer reference, can be negative value like -7 or * positive value like 7 * @param constantParameter String reference,see the CommonUtilConstant */ public static Date getDateFrom(Date inputParam, int timeDifference, String constantParameter) { Date returnDate = null; if (constantParameter.equalsIgnoreCase(CommonUtilConstant.DATE_FORMAT_DAY)) { returnDate = DateUtils.addDays(inputParam, timeDifference); } if (constantParameter.equalsIgnoreCase(CommonUtilConstant.DATE_FORMAT_HOURS)) { returnDate = DateUtils.addHours(inputParam, timeDifference); } if (constantParameter.equalsIgnoreCase(CommonUtilConstant.DATE_FORMAT_MILLISECOND)) { returnDate = DateUtils.addMilliseconds(inputParam, timeDifference); } if (constantParameter.equalsIgnoreCase(CommonUtilConstant.DATE_FORMAT_MINUTES)) { returnDate = DateUtils.addMinutes(inputParam, timeDifference); } if (constantParameter.equalsIgnoreCase(CommonUtilConstant.DATE_FORMAT_MONTH)) { returnDate = DateUtils.addMonths(inputParam, timeDifference); } if (constantParameter.equalsIgnoreCase(CommonUtilConstant.DATE_FORMAT_SECOND)) { returnDate = DateUtils.addSeconds(inputParam, timeDifference); } if (constantParameter.equalsIgnoreCase(CommonUtilConstant.DATE_FORMAT_YEAR)) { returnDate = DateUtils.addYears(inputParam, timeDifference); } if (constantParameter.equalsIgnoreCase(CommonUtilConstant.DATE_FORMAT_WEEK)) { returnDate = DateUtils.addWeeks(inputParam, timeDifference); } return returnDate; }
From source file:com.green.modules.cms.service.LinkService.java
@Transactional(readOnly = false) public Page<Link> find(Page<Link> page, Link link, boolean isDataScopeFilter) { // ??6??//ww w .j a va 2 s.c o m Date updateExpiredWeightDate = (Date) CacheUtils.get("updateExpiredWeightDateByLink"); if (updateExpiredWeightDate == null || (updateExpiredWeightDate != null && updateExpiredWeightDate.getTime() < new Date().getTime())) { linkDao.updateExpiredWeight(); CacheUtils.put("updateExpiredWeightDateByLink", DateUtils.addHours(new Date(), 6)); } DetachedCriteria dc = linkDao.createDetachedCriteria(); dc.createAlias("category", "category"); dc.createAlias("category.site", "category.site"); if (link.getCategory() != null && StringUtils.isNotBlank(link.getCategory().getId()) && !Category.isRoot(link.getCategory().getId())) { Category category = categoryDao.get(link.getCategory().getId()); if (category != null) { dc.add(Restrictions.or(Restrictions.eq("category.id", category.getId()), Restrictions.like("category.parentIds", "%," + category.getId() + ",%"))); dc.add(Restrictions.eq("category.site.id", category.getSite().getId())); link.setCategory(category); } else { dc.add(Restrictions.eq("category.site.id", Site.getCurrentSiteId())); } } else { dc.add(Restrictions.eq("category.site.id", Site.getCurrentSiteId())); } if (StringUtils.isNotEmpty(link.getTitle())) { dc.add(Restrictions.like("title", "%" + link.getTitle() + "%")); } if (link.getCreateBy() != null && StringUtils.isNotBlank(link.getCreateBy().getId())) { dc.add(Restrictions.eq("createBy.id", link.getCreateBy().getId())); } if (isDataScopeFilter) { dc.createAlias("category.office", "categoryOffice").createAlias("createBy", "createBy"); dc.add(dataScopeFilter(UserUtils.getUser(), "categoryOffice", "createBy")); } dc.add(Restrictions.eq(Link.FIELD_DEL_FLAG, link.getDelFlag())); dc.addOrder(Order.desc("weight")); dc.addOrder(Order.desc("updateDate")); return linkDao.find(page, dc); }
From source file:io.cloudex.framework.cloud.entities.VmInstanceTest.java
@Test public void testGetCostHourUsage() { instance.setEnd(DateUtils.addHours(instance.getStart(), 1)); double cost = instance.getCost(); assertEquals(COST, cost, 0); }
From source file:com.hongqiang.shop.modules.cms.service.LinkService.java
public Page<Link> find(Page<Link> page, Link link, boolean isDataScopeFilter) { // ??6??/* w w w.ja v a2 s. com*/ Date updateExpiredWeightDate = (Date) CacheUtils.get("updateExpiredWeightDateByLink"); if (updateExpiredWeightDate == null || (updateExpiredWeightDate != null && updateExpiredWeightDate.getTime() < new Date().getTime())) { linkDao.updateExpiredWeight(); CacheUtils.put("updateExpiredWeightDateByLink", DateUtils.addHours(new Date(), 6)); } DetachedCriteria dc = linkDao.createDetachedCriteria(); dc.createAlias("category", "category"); dc.createAlias("category.site", "category.site"); if (link.getCategory() != null && link.getCategory().getId() != null && !Category.isRoot(link.getCategory().getId())) { Category category = categoryDao.findOne(link.getCategory().getId()); if (category != null) { dc.add(Restrictions.or(Restrictions.eq("category.id", category.getId()), Restrictions.like("category.parentIds", "%," + category.getId() + ",%"))); dc.add(Restrictions.eq("category.site.id", category.getSite().getId())); link.setCategory(category); } else { dc.add(Restrictions.eq("category.site.id", Site.getCurrentSiteId())); } } else { dc.add(Restrictions.eq("category.site.id", Site.getCurrentSiteId())); } if (StringUtils.isNotEmpty(link.getTitle())) { dc.add(Restrictions.like("title", "%" + link.getTitle() + "%")); } if (link.getCreateBy() != null && link.getCreateBy().getId() > 0) { dc.add(Restrictions.eq("createBy.id", link.getCreateBy().getId())); } if (isDataScopeFilter) { dc.createAlias("category.office", "categoryOffice").createAlias("createBy", "createBy"); dc.add(dataScopeFilter(UserUtils.getUser(), "categoryOffice", "createBy")); } dc.add(Restrictions.eq(Link.DEL_FLAG, link.getDelFlag())); dc.addOrder(Order.desc("weight")); dc.addOrder(Order.desc("updateDate")); return linkDao.find(page, dc); }