List of usage examples for org.joda.time DateTime minus
public DateTime minus(ReadablePeriod period)
From source file:org.apache.druid.server.audit.SQLAuditManager.java
License:Apache License
private Interval getIntervalOrDefault(Interval interval) { final Interval theInterval; if (interval == null) { DateTime now = DateTimes.nowUtc(); theInterval = new Interval(now.minus(config.getAuditHistoryMillis()), now); } else {/*w w w. j ava 2 s . c o m*/ theInterval = interval; } return theInterval; }
From source file:org.apache.druid.server.coordinator.rules.PeriodDropBeforeRule.java
License:Apache License
@Override public boolean appliesTo(Interval theInterval, DateTime referenceTimestamp) { final DateTime periodAgo = referenceTimestamp.minus(period); return theInterval.getEndMillis() <= periodAgo.getMillis(); }
From source file:org.apache.gobblin.compaction.verify.CompactionTimeRangeVerifier.java
License:Apache License
public Result verify(FileSystemDataset dataset) { final DateTime earliest; final DateTime latest; try {//from w w w .ja va2 s . co m CompactionPathParser.CompactionParserResult result = new CompactionPathParser(state).parse(dataset); DateTime folderTime = result.getTime(); DateTimeZone timeZone = DateTimeZone.forID( this.state.getProp(MRCompactor.COMPACTION_TIMEZONE, MRCompactor.DEFAULT_COMPACTION_TIMEZONE)); DateTime compactionStartTime = new DateTime( this.state.getPropAsLong(CompactionSource.COMPACTION_INIT_TIME), timeZone); PeriodFormatter formatter = new PeriodFormatterBuilder().appendMonths().appendSuffix("m").appendDays() .appendSuffix("d").appendHours().appendSuffix("h").toFormatter(); // Dataset name is like 'Identity/MemberAccount' or 'PageViewEvent' String datasetName = result.getDatasetName(); // get earliest time String maxTimeAgoStrList = this.state.getProp( TimeBasedSubDirDatasetsFinder.COMPACTION_TIMEBASED_MAX_TIME_AGO, TimeBasedSubDirDatasetsFinder.DEFAULT_COMPACTION_TIMEBASED_MAX_TIME_AGO); String maxTimeAgoStr = getMachedLookbackTime(datasetName, maxTimeAgoStrList, TimeBasedSubDirDatasetsFinder.DEFAULT_COMPACTION_TIMEBASED_MAX_TIME_AGO); Period maxTimeAgo = formatter.parsePeriod(maxTimeAgoStr); earliest = compactionStartTime.minus(maxTimeAgo); // get latest time String minTimeAgoStrList = this.state.getProp( TimeBasedSubDirDatasetsFinder.COMPACTION_TIMEBASED_MIN_TIME_AGO, TimeBasedSubDirDatasetsFinder.DEFAULT_COMPACTION_TIMEBASED_MIN_TIME_AGO); String minTimeAgoStr = getMachedLookbackTime(datasetName, minTimeAgoStrList, TimeBasedSubDirDatasetsFinder.DEFAULT_COMPACTION_TIMEBASED_MIN_TIME_AGO); Period minTimeAgo = formatter.parsePeriod(minTimeAgoStr); latest = compactionStartTime.minus(minTimeAgo); if (earliest.isBefore(folderTime) && latest.isAfter(folderTime)) { log.debug("{} falls in the user defined time range", dataset.datasetRoot()); return new Result(true, ""); } } catch (Exception e) { log.error("{} cannot be verified because of {}", dataset.datasetRoot(), ExceptionUtils.getFullStackTrace(e)); return new Result(false, e.toString()); } return new Result(false, dataset.datasetRoot() + " is not in between " + earliest + " and " + latest); }
From source file:org.apache.storm.st.utils.TimeUtil.java
License:Apache License
public static DateTime floor(DateTime dateTime, int sec) { long modValue = dateTime.getMillis() % (1000 * sec); return dateTime.minus(modValue); }
From source file:org.apache.storm.st.utils.TimeUtil.java
License:Apache License
public static DateTime ceil(DateTime dateTime, int sec) { long modValue = dateTime.getMillis() % (1000 * sec); return dateTime.minus(modValue).plusSeconds(sec); }
From source file:org.apereo.portal.events.aggr.PortalEventDimensionPopulatorImpl.java
License:Apache License
final void doPopulateDateDimensions() { final DateTime now = getNow(); final AggregationIntervalInfo startIntervalInfo; final DateTime oldestPortalEventTimestamp = this.portalEventDao.getOldestPortalEventTimestamp(); if (oldestPortalEventTimestamp == null || now.isBefore(oldestPortalEventTimestamp)) { startIntervalInfo = this.intervalHelper.getIntervalInfo(AggregationInterval.YEAR, now.minus(this.dimensionBuffer)); } else {/* w ww. j ava 2 s.c o m*/ startIntervalInfo = this.intervalHelper.getIntervalInfo(AggregationInterval.YEAR, oldestPortalEventTimestamp.minus(this.dimensionBuffer)); } final AggregationIntervalInfo endIntervalInfo; final DateTime newestPortalEventTimestamp = this.portalEventDao.getNewestPortalEventTimestamp(); if (newestPortalEventTimestamp == null || now.isAfter(newestPortalEventTimestamp)) { endIntervalInfo = this.intervalHelper.getIntervalInfo(AggregationInterval.YEAR, now.plus(this.dimensionBuffer)); } else { endIntervalInfo = this.intervalHelper.getIntervalInfo(AggregationInterval.YEAR, newestPortalEventTimestamp.plus(this.dimensionBuffer)); } final DateMidnight start = startIntervalInfo.getStart().toDateMidnight(); final DateMidnight end = endIntervalInfo.getEnd().toDateMidnight(); doPopulateDateDimensions(start, end); }
From source file:org.apereo.portal.events.aggr.PortalEventPurgerImpl.java
License:Apache License
@AggrEventsTransactional public EventProcessingResult doPurgeRawEvents() { if (!this.clusterLockService.isLockOwner(PURGE_RAW_EVENTS_LOCK_NAME)) { throw new IllegalStateException("The cluster lock " + PURGE_RAW_EVENTS_LOCK_NAME + " must be owned by the current thread and server"); }/*from w ww . j a va2 s . c o m*/ final IEventAggregatorStatus eventPurgerStatus = eventAggregationManagementDao .getEventAggregatorStatus(IEventAggregatorStatus.ProcessingType.PURGING, true); //Update status with current server name final String serverName = this.portalInfoProvider.getUniqueServerName(); eventPurgerStatus.setServerName(serverName); eventPurgerStatus.setLastStart(new DateTime()); //Determine date of most recently aggregated data final IEventAggregatorStatus eventAggregatorStatus = eventAggregationManagementDao .getEventAggregatorStatus(IEventAggregatorStatus.ProcessingType.AGGREGATION, false); if (eventAggregatorStatus == null || eventAggregatorStatus.getLastEventDate() == null) { //Nothing has been aggregated, skip purging eventPurgerStatus.setLastEnd(new DateTime()); eventAggregationManagementDao.updateEventAggregatorStatus(eventPurgerStatus); return new EventProcessingResult(0, null, null, true); } boolean complete = true; //Calculate purge end date from most recent aggregation minus the purge delay final DateTime lastAggregated = eventAggregatorStatus.getLastEventDate(); DateTime purgeEnd = lastAggregated.minus(this.purgeDelay); //Determine the DateTime of the oldest event DateTime oldestEventDate = eventPurgerStatus.getLastEventDate(); if (oldestEventDate == null) { oldestEventDate = this.portalEventDao.getOldestPortalEventTimestamp(); } //Make sure purgeEnd is no more than 1 hour after the oldest event date to limit delete scope final DateTime purgeEndLimit = oldestEventDate.plusHours(1); if (purgeEndLimit.isBefore(purgeEnd)) { purgeEnd = purgeEndLimit; complete = false; } final Thread currentThread = Thread.currentThread(); final String currentName = currentThread.getName(); final int events; try { currentThread.setName(currentName + "-" + purgeEnd); //Purge events logger.debug("Starting purge of events before {}", purgeEnd); events = portalEventDao.deletePortalEventsBefore(purgeEnd); } finally { currentThread.setName(currentName); } //Update the status object and store it purgeEnd = purgeEnd.minusMillis(100); //decrement by 100ms since deletePortalEventsBefore uses lessThan and not lessThanEqualTo eventPurgerStatus.setLastEventDate(purgeEnd); eventPurgerStatus.setLastEnd(new DateTime()); eventAggregationManagementDao.updateEventAggregatorStatus(eventPurgerStatus); return new EventProcessingResult(events, oldestEventDate, purgeEnd, complete); }
From source file:org.apereo.portal.events.aggr.PortalEventSessionPurgerImpl.java
License:Apache License
@Override @AggrEventsTransactional//from ww w .j a v a 2s. c o m public EventProcessingResult doPurgeEventSessions() { if (!this.clusterLockService.isLockOwner(PURGE_EVENT_SESSION_LOCK_NAME)) { throw new IllegalStateException("The cluster lock " + PURGE_EVENT_SESSION_LOCK_NAME + " must be owned by the current thread and server"); } final IEventAggregatorStatus eventAggregatorStatus = eventAggregationManagementDao .getEventAggregatorStatus(IEventAggregatorStatus.ProcessingType.AGGREGATION, false); if (eventAggregatorStatus == null || eventAggregatorStatus.getLastEventDate() == null) { return new EventProcessingResult(0, null, null, true); } final DateTime lastEventDate = eventAggregatorStatus.getLastEventDate(); final DateTime sessionPurgeDate = lastEventDate.minus(eventSessionDuration); final int purgeCount = eventSessionDao.purgeEventSessionsBefore(sessionPurgeDate); return new EventProcessingResult(purgeCount, null, sessionPurgeDate, true); }
From source file:org.aselect.server.request.handler.xsaml20.SamlTools.java
License:Open Source License
/** * Set OpenSAML2 library Conditions object for timeRestrictions NotBefore and NotOnOrAfter. * /*from w w w . ja va2 s .com*/ * @param obj * The object to which conditions are to be added * @param refInstant * Reference moment in time * @param maxNotBefore * the max not before * @param maxNotOnOrAfter * the max not on or after * @return valid Object with conditions (if not all timeRestrictions were null) otherwise return same object * unmodified * @throws ValidationException * Thrown if an error occurs while placing conditions * @throws ASelectException */ public static SAMLObject setValidityInterval(SAMLObject obj, DateTime refInstant, Long maxNotBefore, Long maxNotOnOrAfter) throws ASelectException { String sMethod = "setValidityInterval"; ASelectSystemLogger _systemLogger = ASelectSystemLogger.getHandle(); _systemLogger.log(Level.INFO, MODULE, sMethod, "obj->" + obj + ", refInstant->" + refInstant + ", maxNotBefore->" + maxNotBefore + ", maxNotOnOrAfter->" + maxNotOnOrAfter); // Still think this is a bit clumsy, maybe implement some sort of // (command) pattern here or use generics if (obj instanceof Assertion) { Conditions conditions = ((Assertion) obj).getConditions(); if (maxNotBefore != null || maxNotOnOrAfter != null) { XMLObjectBuilderFactory oBuilderFactory = org.opensaml.xml.Configuration.getBuilderFactory(); SAMLObjectBuilder<Conditions> conditionsBuilder = (SAMLObjectBuilder<Conditions>) oBuilderFactory .getBuilder(Conditions.DEFAULT_ELEMENT_NAME); if (maxNotBefore != null) { conditions = (conditions == null) ? conditionsBuilder.buildObject() : conditions; conditions.setNotBefore(refInstant.minus(maxNotBefore.longValue())); } if (maxNotOnOrAfter != null) { conditions = (conditions == null) ? conditionsBuilder.buildObject() : conditions; conditions.setNotOnOrAfter(refInstant.plus(maxNotOnOrAfter.longValue())); } } if (conditions != null) { ((Assertion) obj).setConditions(conditions); _systemLogger.log(Level.INFO, MODULE, sMethod, "Conditions set on Assertion->" + obj); } } else // not instanceof Assertion if (obj instanceof AuthnRequest) { Conditions conditions = ((AuthnRequest) obj).getConditions(); if (maxNotBefore != null || maxNotOnOrAfter != null) { XMLObjectBuilderFactory oBuilderFactory = org.opensaml.xml.Configuration.getBuilderFactory(); SAMLObjectBuilder<Conditions> conditionsBuilder = (SAMLObjectBuilder<Conditions>) oBuilderFactory .getBuilder(Conditions.DEFAULT_ELEMENT_NAME); if (maxNotBefore != null) { conditions = (conditions == null) ? conditionsBuilder.buildObject() : conditions; conditions.setNotBefore(refInstant.minus(maxNotBefore.longValue())); } if (maxNotOnOrAfter != null) { conditions = (conditions == null) ? conditionsBuilder.buildObject() : conditions; conditions.setNotOnOrAfter(refInstant.plus(maxNotOnOrAfter.longValue())); } } if (conditions != null) { ((AuthnRequest) obj).setConditions(conditions); _systemLogger.log(Level.INFO, MODULE, sMethod, "Conditions set on AuthnRequest->" + obj); } } else // not instanceof AuthnRequest if (obj instanceof SubjectConfirmationData) { if (maxNotBefore != null) { ((SubjectConfirmationData) obj).setNotBefore(refInstant.minus(maxNotBefore.longValue())); } if (maxNotOnOrAfter != null) { ((SubjectConfirmationData) obj).setNotOnOrAfter(refInstant.plus(maxNotOnOrAfter.longValue())); } } else // not instanceof SubjectConfirmationData if (obj instanceof LogoutRequest) { if (maxNotOnOrAfter != null) { ((LogoutRequest) obj).setNotOnOrAfter(refInstant.plus(maxNotOnOrAfter.longValue())); } } // not instanceof LogoutRequest return obj; }
From source file:org.codice.ddf.spatial.ogc.wfs.v110.catalog.source.WfsFilterDelegate.java
License:Open Source License
@Override public FilterType relative(String propertyName, long duration) { final DateTime now = new DateTime(); final DateTime start = now.minus(duration); return during(propertyName, start.toDate(), now.toDate()); }