List of usage examples for org.joda.time Interval contains
public boolean contains(long millisInstant)
From source file:org.filteredpush.qc.date.DateUtils.java
License:Apache License
/** * Count the number of leap days present in an event date * //from ww w. j a v a 2 s. c om * @param eventDate to check for leap days * @return number of leap days present in eventDate, 0 if no leap days are present or * if eventDate does not contain a date. */ public static int countLeapDays(String eventDate) { int result = 0; if (!DateUtils.isEmpty(eventDate) && DateUtils.eventDateValid(eventDate)) { Interval interval = extractInterval(eventDate); Integer sYear = interval.getStart().getYear(); Integer eYear = interval.getEnd().getYear(); String startYear = Integer.toString(sYear).trim(); String endYear = Integer.toString(eYear).trim(); String leapDay = startYear + "-02-29"; logger.debug(leapDay); if (DateUtils.eventDateValid(leapDay)) { if (interval.contains(DateUtils.extractInterval(leapDay))) { result = 1; } } // Range spanning more than one year, check last year if (!endYear.equals(startYear)) { leapDay = endYear + "-02-29"; logger.debug(leapDay); if (DateUtils.eventDateValid(leapDay)) { if (interval.contains(DateUtils.extractInterval(leapDay))) { result++; } } } // Ranges of more than two years, check intermediate years if (eYear > sYear + 1) { for (int testYear = sYear + 1; testYear < eYear; testYear++) { leapDay = Integer.toString(testYear).trim() + "-02-29"; logger.debug(leapDay); if (DateUtils.eventDateValid(leapDay)) { if (interval.contains(DateUtils.extractInterval(leapDay))) { result++; } } } } } return result; }
From source file:org.forgerock.openidm.util.DateUtil.java
License:CDDL license
/** * Returns true if the current (now) timestamp is within the specified time interval. The supplied interval string * should contain an ISO 8601 formatted interval string and may be of the formats 'datetime/datetime', * 'datetime/period' or 'period/datetime' * // ww w .j av a 2 s . c o m * @param intervalString a {@link String} object representing an ISO 8601 time interval. * @return true if the instant is within the interval, false otherwise. * @throws IllegalArgumentException if an error occurs while parsing the intervalString. */ public boolean isNowWithinInterval(String intervalString) throws IllegalArgumentException { Interval interval = Interval.parse(intervalString); return interval.contains(DateTime.now()); }
From source file:org.forgerock.openidm.util.DateUtil.java
License:CDDL license
/** * Returns true if the supplied timestamp is within the specified time interval. The supplied interval string * should contain an ISO 8601 formatted interval string and may be of the formats 'datetime/datetime', * 'datetime/period' or 'period/datetime' * /*from ww w .ja v a2 s.c o m*/ * @param timestamp a {@link DateTime} object representing a date time instant. * @param intervalString a {@link String} object representing an ISO 8601 time interval. * @return true if the instant is within the interval, false otherwise. * @throws IllegalArgumentException if an error occurs while parsing the intervalString. */ public boolean isTimestampWithinInterval(DateTime timestamp, String intervalString) throws IllegalArgumentException { Interval interval = Interval.parse(intervalString); return interval.contains(timestamp); }
From source file:org.jasig.cas.client.validation.Saml11TicketValidator.java
License:Apache License
private boolean isValidAssertion(final org.opensaml.saml1.core.Assertion assertion) { final DateTime notBefore = assertion.getConditions().getNotBefore(); final DateTime notOnOrAfter = assertion.getConditions().getNotOnOrAfter(); if (notBefore == null || notOnOrAfter == null) { logger.debug("Assertion has no bounding dates. Will not process."); return false; }//w w w . j av a 2 s .c o m final DateTime currentTime = new DateTime(DateTimeZone.UTC); final Interval validityRange = new Interval(notBefore.minus(this.tolerance), notOnOrAfter.plus(this.tolerance)); if (validityRange.contains(currentTime)) { logger.debug("Current time is within the interval validity."); return true; } if (currentTime.isBefore(validityRange.getStart())) { logger.debug("skipping assertion that's not yet valid..."); return false; } logger.debug("skipping expired assertion..."); return false; }
From source file:org.jasig.portlet.calendar.adapter.CalendarEventsDao.java
License:Apache License
/** * Get a JSON-appropriate representation of each recurrence of an event * within the specified time period.//from ww w. j a v a2 s .c o m * * @param e * @param interval * @param usersConfiguredDateTimeZone * @return * @throws IOException * @throws URISyntaxException * @throws ParseException */ protected Set<CalendarDisplayEvent> getDisplayEvents(VEvent e, Interval interval, Locale locale, DateTimeZone usersConfiguredDateTimeZone) throws IOException, URISyntaxException, ParseException { final VEvent event = (VEvent) e.copy(); DateTime eventStart; DateTime eventEnd = null; if (event.getStartDate().getTimeZone() == null && !event.getStartDate().isUtc()) { if (log.isDebugEnabled()) { log.debug("Identified event " + event.getSummary() + " as a floating event"); } int offset = usersConfiguredDateTimeZone.getOffset(event.getStartDate().getDate().getTime()); eventStart = new DateTime(event.getStartDate().getDate().getTime() - offset, usersConfiguredDateTimeZone); if (event.getEndDate() != null) { eventEnd = new DateTime(event.getEndDate().getDate().getTime() - offset, usersConfiguredDateTimeZone); } } else { eventStart = new DateTime(event.getStartDate().getDate(), usersConfiguredDateTimeZone); if (event.getEndDate() != null) { eventEnd = new DateTime(event.getEndDate().getDate(), usersConfiguredDateTimeZone); } } if (eventEnd == null) { eventEnd = eventStart; } // Multi-day events may begin in the past; make sure to choose a date in range for the first pass... final Date firstDayToProcess = interval.contains(event.getStartDate().getDate().getTime()) ? event.getStartDate().getDate() : interval.getStart().toDate(); DateMidnight startOfTheSpecificDay = new DateMidnight(firstDayToProcess, usersConfiguredDateTimeZone); DateMidnight endOfTheSpecificDay = startOfTheSpecificDay.plusDays(1); final DateTimeFormatter df = getDateFormatter(locale, usersConfiguredDateTimeZone); final DateTimeFormatter tf = getTimeFormatter(locale, usersConfiguredDateTimeZone); final Set<CalendarDisplayEvent> events = new HashSet<CalendarDisplayEvent>(); final Interval eventInterval = new Interval(eventStart, eventEnd); do { final Interval theSpecificDay = new Interval(startOfTheSpecificDay.getMillis(), endOfTheSpecificDay.getMillis(), usersConfiguredDateTimeZone); /* * Test if the event interval abuts the start of the day or is within the day. * This start time check is needed for the corner case where a zero duration interval * is set for midnight. * The start times are tested directly as opposed to using abuts() because that method * also returns true if the intervals abut at the end of the day. We want to associate * instant events that start at midnight with the starting day, not the ending day. */ if (theSpecificDay.getStart().isEqual(eventStart) || theSpecificDay.overlaps(eventInterval)) { final CalendarDisplayEvent json = new CalendarDisplayEvent(event, eventInterval, theSpecificDay, df, tf); events.add(json); } startOfTheSpecificDay = startOfTheSpecificDay.plusDays(1); endOfTheSpecificDay = endOfTheSpecificDay.plusDays(1); } while (!startOfTheSpecificDay.isAfter(eventEnd) && interval.contains(startOfTheSpecificDay)); return events; }
From source file:org.jasig.portlet.calendar.processor.RssContentProcessorImpl.java
License:Apache License
public Set<VEvent> getEvents(Interval interval, SyndFeed feed) { Set<VEvent> events = new HashSet<VEvent>(); try {/*from ww w.j a va2s . c o m*/ @SuppressWarnings("unchecked") List<SyndEntry> entries = (List<SyndEntry>) feed.getEntries(); for (SyndEntry entry : entries) { PropertyList props = new PropertyList(); // Attempt to use the pubDate element as the start date for this // event. RSS feeds don't really give us anything to use // for an end date. Date start = null; if (entry.getPublishedDate() != null) { start = entry.getPublishedDate(); } // we only want to add this feed if it's in the desired time period if (start != null && interval.contains(start.getTime())) { props.add(new DtStart(new DateTime(start), true)); props.add(new Summary(entry.getTitle())); props.add(new Description(entry.getDescription().getValue())); // use the RSS item Guid as the Uid for this event String guid = null; if (entry instanceof Item && ((Item) entry).getGuid() != null) { guid = ((Item) entry).getGuid().getValue(); props.add(new Uid(guid)); } // try to find a link for this event if (entry.getLink() != null) { try { props.add(new Url(new URI(entry.getLink()))); } catch (URISyntaxException e1) { } } // construct and add the new calendar event VEvent event = new VEvent(props); events.add(event); } } } catch (IllegalArgumentException e) { log.error(e.getMessage(), e); } // return the list of matching calendar events return events; }
From source file:org.jevis.commons.dataprocessing.function.AggrigatorFunction.java
License:Open Source License
@Override public List<JEVisSample> getResult(Process mainTask) { List<JEVisSample> result = new ArrayList<>(); List<List<JEVisSample>> allSamples = new ArrayList<>(); for (Process task : mainTask.getSubProcesses()) { allSamples.add(task.getResult()); System.out.println("Add input result: " + allSamples.size()); }/*from w ww.ja va 2 s .co m*/ List<DateTime> allTimestamps = getAllTimestamps(allSamples); if (allTimestamps.isEmpty()) { return result; } List<Interval> intervals = ProcessOptions.getIntervals(mainTask, allTimestamps.get(0), allTimestamps.get(allTimestamps.size() - 1)); System.out.println("intervals: " + intervals.size()); int lastPos = 0; for (Interval interval : intervals) { List<JEVisSample> samplesInPeriod = new ArrayList<>(); System.out.println("interval: " + interval); for (List<JEVisSample> samples : allSamples) { for (int i = lastPos; i < samples.size(); i++) { try { if (interval.contains(samples.get(i).getTimestamp())) { // System.out.println("add sample: " + samples.get(i)); samplesInPeriod.add(samples.get(i)); } else if (samples.get(i).getTimestamp().isAfter(interval.getEnd())) { lastPos = i; break; } } catch (JEVisException ex) { System.out.println("JEVisExeption while going trou sample: " + ex.getMessage()); } } double sum = 0; for (JEVisSample sample : samplesInPeriod) { try { sum += sample.getValueAsDouble(); } catch (JEVisException ex) { Logger.getLogger(AggrigatorFunction.class.getName()).log(Level.SEVERE, null, ex); } } JEVisSample resultSum = new VirtuelSample(interval.getStart(), sum, mainTask.getJEVisDataSource(), new VirtualAttribute(null)); result.add(resultSum); try { System.out.println( "resultSum: " + resultSum.getTimestamp() + " " + resultSum.getValueAsDouble()); } catch (JEVisException ex) { Logger.getLogger(AggrigatorFunction.class.getName()).log(Level.SEVERE, null, ex); } } } return result; }
From source file:org.jevis.commons.dataprocessing.function.ImpulsFunction.java
License:Open Source License
@Override public List<JEVisSample> getResult(Process mainTask) { List<JEVisSample> result = new ArrayList<>(); if (mainTask.getSubProcesses().size() > 1) { System.out.println("Impuscleaner cannot work with more than one imput, using first only."); } else if (mainTask.getSubProcesses().size() < 1) { System.out.println("Impuscleaner, no input nothing to do"); }//from w w w. j ava 2 s.c o m List<JEVisSample> samples = mainTask.getSubProcesses().get(0).getResult(); DateTime firstTS = DateTime.now(); DateTime lastTS = DateTime.now(); try { firstTS = samples.get(0).getTimestamp(); lastTS = samples.get(samples.size()).getTimestamp(); } catch (JEVisException ex) { Logger.getLogger(ImpulsFunction.class.getName()).log(Level.SEVERE, null, ex); } List<Interval> intervals = ProcessOptions.getIntervals(mainTask, firstTS, lastTS); int lastPos = 0; for (Interval interval : intervals) { List<JEVisSample> samplesInPeriod = new ArrayList<>(); for (int i = lastPos; i < samples.size(); i++) { try { if (interval.contains(samples.get(i).getTimestamp())) { // System.out.println("add sample: " + samples.get(i)); samplesInPeriod.add(samples.get(i)); } else if (samples.get(i).getTimestamp().isAfter(interval.getEnd())) { lastPos = i; break; } } catch (JEVisException ex) { System.out.println("JEVisExeption while going trou sample: " + ex.getMessage()); } } //TODO: thi sis an dummy for JEVisSample bestmatch = null; for (JEVisSample sample : samplesInPeriod) { long bestDiff = 99999999999999999l; try { long middelMili = ((interval.getEndMillis() - interval.getStartMillis()) / 2) + interval.getStartMillis(); long diff = Math.abs(sample.getTimestamp().getMillis() - middelMili); // System.out.println("Diff for: " + sample.getTimestamp() + " -> " + diff); if (bestmatch != null) { if (bestDiff < diff) { bestDiff = diff; bestmatch = sample; } } else { bestmatch = sample; bestDiff = diff; } } catch (JEVisException ex) { System.out.println("JEVisExeption while going trou sample2: " + ex.getMessage()); } } if (bestmatch != null) { System.out.println("Best match: " + bestmatch); result.add(bestmatch); } } return result; }
From source file:org.jevis.commons.dataprocessing.function.ImpulsFunction.java
License:Open Source License
public List<JEVisSample> getResult(ProcessOptions options, List<List<JEVisSample>> allSamples) { List<JEVisSample> result = new ArrayList<>(); for (List<JEVisSample> samples : allSamples) { try {/*from w w w . j av a 2 s. com*/ _durations = ProcessOptions.buildIntervals(Period.minutes(15), _offset, samples.get(0).getTimestamp(), samples.get(samples.size() - 1).getTimestamp()); } catch (JEVisException ex) { Logger.getLogger(ImpulsFunction.class.getName()).log(Level.SEVERE, null, ex); } //Samples list is sorted by default int lastPos = 0; for (Interval interval : _durations) { // System.out.println("Interval: " + interval); List<JEVisSample> samplesInPeriod = new ArrayList<>(); for (int i = lastPos; i < samples.size(); i++) { try { if (interval.contains(samples.get(i).getTimestamp())) { // System.out.println("add sample: " + samples.get(i)); samplesInPeriod.add(samples.get(i)); } else if (samples.get(i).getTimestamp().isAfter(interval.getEnd())) { lastPos = i; break; } } catch (JEVisException ex) { System.out.println("JEVisExeption while going trou sample: " + ex.getMessage()); } } //TODO: thi sis an dummy for JEVisSample bestmatch = null; for (JEVisSample sample : samplesInPeriod) { long bestDiff = 99999999999999999l; try { long middelMili = ((interval.getEndMillis() - interval.getStartMillis()) / 2) + interval.getStartMillis(); long diff = Math.abs(sample.getTimestamp().getMillis() - middelMili); // System.out.println("Diff for: " + sample.getTimestamp() + " -> " + diff); if (bestmatch != null) { if (bestDiff < diff) { bestDiff = diff; bestmatch = sample; } } else { bestmatch = sample; bestDiff = diff; } } catch (JEVisException ex) { System.out.println("JEVisExeption while going trou sample2: " + ex.getMessage()); } } if (bestmatch != null) { System.out.println("Best match: " + bestmatch); result.add(bestmatch); } } } return result; }
From source file:org.jevis.commons.dataprocessing.processor.AggrigatorProcessor.java
License:Open Source License
@Override public List<JEVisSample> getResult(Task mainTask) { List<JEVisSample> result = new ArrayList<>(); ///* w w w . ja v a2s . c om*/ // // List<Interval> durations = ProcessController.buildIntervals(Period.days(1), ProcessController.getOffset(), samples.get(0).getTimestamp(), samples.get(samples.size() - 1).getTimestamp()); List<Map<DateTime, JEVisSample>> sampleMaps = new ArrayList<>(); List<List<JEVisSample>> allSamples = new ArrayList<>(); for (Task task : mainTask.getSubTasks()) { allSamples.add(task.getResult()); System.out.println("Add input result: " + allSamples.size()); } List<DateTime> allTimestamps = getAllTimestamps(allSamples); List<Interval> intervals = Options.getIntervals(mainTask, allTimestamps.get(0), allTimestamps.get(allTimestamps.size() - 1)); System.out.println("intervals: " + intervals.size()); int lastPos = 0; for (Interval interval : intervals) { List<JEVisSample> samplesInPeriod = new ArrayList<>(); System.out.println("interval: " + interval); for (List<JEVisSample> samples : allSamples) { for (int i = lastPos; i < samples.size(); i++) { try { if (interval.contains(samples.get(i).getTimestamp())) { // System.out.println("add sample: " + samples.get(i)); samplesInPeriod.add(samples.get(i)); } else if (samples.get(i).getTimestamp().isAfter(interval.getEnd())) { lastPos = i; break; } } catch (JEVisException ex) { System.out.println("JEVisExeption while going trou sample: " + ex.getMessage()); } } double sum = 0; for (JEVisSample sample : samplesInPeriod) { try { sum += sample.getValueAsDouble(); } catch (JEVisException ex) { Logger.getLogger(AggrigatorProcessor.class.getName()).log(Level.SEVERE, null, ex); } } JEVisSample resultSum = new VirtuelSample(interval.getStart(), sum, mainTask.getJEVisDataSource(), new VirtualAttribute(null)); result.add(resultSum); try { System.out.println( "resultSum: " + resultSum.getTimestamp() + " " + resultSum.getValueAsDouble()); } catch (JEVisException ex) { Logger.getLogger(AggrigatorProcessor.class.getName()).log(Level.SEVERE, null, ex); } } } return result; }