List of usage examples for org.apache.commons.lang.time DateUtils ceiling
public static Date ceiling(Object date, int field)
Ceil this date, leaving the field specified as the most significant field.
For example, if you had the datetime of 28 Mar 2002 13:45:01.231, if you passed with HOUR, it would return 28 Mar 2002 13:00:00.000.
From source file:com.naver.blog.functionalservice.search.QueryParameter.java
private String calcEndDate(TermType termType, Date endDate) { if (endDate != null) { try {/*from w w w. j a v a 2s.c o m*/ Date ceiledEndDate = DateUtils.ceiling(endDate, Calendar.DATE); ceiledEndDate = DateUtils.addMinutes(ceiledEndDate, -1); return DateUtil.formatDate(ceiledEndDate, YYYYMMDDHHMM); } catch (Exception e) { Log.warn(e.getMessage(), e); return null; } } if (termType == null) { return null; } Calendar cal = Calendar.getInstance(); switch (termType) { case IN_ONE_WEEK: case IN_ONE_MONTH: Date todayMidnight = DateUtils.ceiling(new Date(cal.getTimeInMillis()), Calendar.DATE); todayMidnight = DateUtils.addMinutes(todayMidnight, -1); return DateUtil.formatDate(todayMidnight, YYYYMMDDHHMM); default: return null; } }
From source file:org.alfresco.module.org_alfresco_module_rm.audit.RecordsManagementAuditServiceImpl.java
/** * Calculates the end of the given date. * For example, if you had the date time of 12 Aug 2013 12:10:15.158 * the result would be 12 Aug 2013 23:59:59.999. * * @param date The date for which the end should be calculated. * @return Returns the end of the given date. *//*from www . j a v a 2s . c om*/ private Date getEndOfDay(Date date) { return DateUtils.addMilliseconds(DateUtils.ceiling(date == null ? new Date() : date, Calendar.DATE), -1); }
From source file:org.eclipse.dirigible.runtime.metrics.TimeUtils.java
public static Date roundCeilingHour(Date date) { // DateTime bound = dateTimeCeiling(new DateTime(date.getTime()), Period.hours(1)); // return new Date(bound.getMillis()); return DateUtils.ceiling(date, Calendar.HOUR); }
From source file:org.eclipse.smarthome.binding.astro.internal.util.DateTimeUtils.java
/** * Returns the end of day from the calendar object. */// w ww .java 2 s . c om public static Calendar endOfDayDate(Calendar calendar) { Calendar cal = (Calendar) calendar.clone(); cal = DateUtils.ceiling(cal, Calendar.DATE); cal.add(Calendar.MILLISECOND, -1); return cal; }
From source file:org.geoserver.taskmanager.schedule.BatchJobServiceTest.java
@Test public void testBatchJobService() throws SchedulerException { JobKey jobKey = new JobKey(batch.getFullName()); TriggerKey triggerKey = new TriggerKey(batch.getFullName()); //not scheduled yet assertTrue(scheduler.checkExists(jobKey)); assertFalse(scheduler.checkExists(triggerKey)); //give it a frequency batch.setFrequency("0 0 * * * ?"); batch.setEnabled(true);/*from w ww .ja v a 2 s .c om*/ bjService.saveAndSchedule(batch); assertTrue(scheduler.checkExists(jobKey)); assertTrue(scheduler.checkExists(triggerKey)); Trigger trigger = scheduler.getTrigger(triggerKey); Date nextFireTime = DateUtils.ceiling(new Date(), Calendar.HOUR); assertEquals(nextFireTime, trigger.getNextFireTime()); //change the frequency batch.setFrequency("0 30 * * * ?"); bjService.saveAndSchedule(batch); assertTrue(scheduler.checkExists(jobKey)); assertTrue(scheduler.checkExists(triggerKey)); trigger = scheduler.getTrigger(triggerKey); nextFireTime = DateUtils.addMinutes(DateUtils.round(new Date(), Calendar.HOUR), 30); assertEquals(nextFireTime, trigger.getNextFireTime()); //de-activate it batch.setEnabled(false); bjService.saveAndSchedule(batch); assertTrue(scheduler.checkExists(jobKey)); assertFalse(scheduler.checkExists(triggerKey)); //delete it batch.setActive(false); bjService.saveAndSchedule(batch); assertFalse(scheduler.checkExists(jobKey)); assertFalse(scheduler.checkExists(triggerKey)); }
From source file:org.ngrinder.infra.report.PeriodicCollectDataToGAService.java
/** * Send the number of executed test.//w w w . ja v a 2 s. com */ @Scheduled(cron = "0 1 1 * * ?") @Transactional public void reportUsage() { if (config.isUsageReportEnabled()) { doRandomDelay(); GoogleAnalytic googleAnalytic = new GoogleAnalytic(ControllerConstants.GOOGLE_ANALYTICS_APP_NAME, config.getVersion(), ControllerConstants.GOOGLE_ANALYTICS_TRACKING_ID); MeasureProtocolRequest measureProtocolRequest = googleAnalytic.getMeasureProtocolRequest(); measureProtocolRequest.setEventCategory("usage"); measureProtocolRequest.setEventAction("executions"); String currentAddress = NetworkUtils.getLocalHostAddress(); Date yesterday = DateUtils.addDays(new Date(), -1); Date start = DateUtils.truncate(yesterday, Calendar.DATE); Date end = DateUtils.addMilliseconds(DateUtils.ceiling(yesterday, Calendar.DATE), -1); googleAnalytic.sendStaticDataToUA(currentAddress, String.valueOf(getUsage(start, end))); } }
From source file:org.openhab.binding.astro.internal.util.DateTimeUtils.java
/** * Returns the end of day julian date from the calendar object. *//*w ww. j av a 2 s . c om*/ public static double endOfDayDateToJulianDate(Calendar calendar) { Calendar cal = (Calendar) calendar.clone(); cal = DateUtils.ceiling(cal, Calendar.DATE); cal.add(Calendar.MILLISECOND, -1); return dateToJulianDate(cal); }