List of usage examples for org.joda.time Interval contains
public boolean contains(long millisInstant)
From source file:beans.utilidades.MetodosGenerales.java
public boolean fechaDentroDeRangoMas1Dia(Date inicioRango, Date finRango, Date fecBuscada) { //determinar si una fecha esta dentro de un rango; true = fecha en el rango //se suma 1 dia a la fecha final para que incluya el ultimo dia Interval interval = new Interval(new DateTime(inicioRango), new DateTime(finRango).plusDays(1)); return interval.contains(new DateTime(fecBuscada)); }
From source file:beans.utilidades.MetodosGenerales.java
private boolean fechaDentroDeRango(Date inicioRango, Date finRango, Date fecBuscada) { //determinar si una fecha esta dentro de un rango; true = fecha en el rango //no es necesario aumentar el dia final por que se evaluan ambos limites de ambos rangos Interval interval = new Interval(new DateTime(inicioRango), new DateTime(finRango)); return interval.contains(new DateTime(fecBuscada)); }
From source file:com.danhaywood.isis.wicket.fullcalendar.collectioncontents.DateAssociationEventsProvider.java
License:Apache License
public Collection<Event> getEvents(final DateTime start, final DateTime end) { final Interval interval = new Interval(start, end); final Predicate<Event> withinInterval = new Predicate<Event>() { public boolean apply(Event input) { return interval.contains(input.getStart()); }//from ww w .j a v a 2s.co m }; final Collection<Event> values = eventById.values(); return Collections2.filter(values, withinInterval); }
From source file:com.eucalyptus.simpleworkflow.common.client.WorkflowTimer.java
License:Open Source License
static List<WorkflowStarter> markAndGetRepeatingStarters() { try {/*from ww w . j ava 2 s .com*/ final List<WorkflowStarter> starters = Lists.newArrayList(); listRepeatingWorkflows().stream().forEach((impl) -> { try { final Repeating ats = Ats.inClassHierarchy(impl).get(Repeating.class); if (Topology.isEnabled(ats.dependsOn())) { final Long lastRun = lastExecution.get(impl); if (lastRun != null) { final DateTime now = new DateTime(System.currentTimeMillis()); final DateTime sleepBegin = now.minusSeconds(ats.sleepSeconds()); final Interval interval = new Interval(sleepBegin, now); if (!interval.contains(new DateTime(lastRun))) { if (lastExecution.replace(impl, lastRun, System.currentTimeMillis())) { starters.add(ats.value().newInstance()); } } } } } catch (InstantiationException ex) { ; } catch (IllegalAccessException ex) { ; } }); return starters; } catch (final Exception ex) { return Lists.newArrayList(); } }
From source file:com.fusesource.examples.horo.model.StarSign.java
License:Apache License
public boolean appliesTo(ReadableDateTime dateTime) { Validate.notNull(dateTime);/*from www .j av a 2s . c o m*/ int year = dateTime.getYear(); Interval signInterval = new Interval(start.toLocalDate(year).toDateMidnight(), end.toLocalDate(year).toDateMidnight().plusDays(1)); return signInterval.contains(dateTime); }
From source file:com.google.sampling.experiential.server.EventMatcher.java
License:Open Source License
private boolean compareDateRange(String range, Event event) { Iterable<String> iterable = Splitter.on("-").split(range); Iterator<String> iter = iterable.iterator(); if (!iter.hasNext()) { throw new IllegalArgumentException("Illformed Date Range: " + range); }//from w w w .j a va 2 s . co m String firstDate = iter.next(); String secondDate = null; if (iter.hasNext()) { secondDate = iter.next(); } DateMidnight startDate = newDateMidnightFromString(firstDate); DateMidnight endDate = null; if (secondDate != null && !secondDate.isEmpty()) { endDate = newDateMidnightFromString(secondDate); } else { endDate = startDate.plusDays(1); } Interval r2 = new Interval(startDate, endDate); Date eventDate = event.getWhen(); if (eventDate == null) { return false; } DateMidnight eventDateMidnight = new DateMidnight(eventDate.getTime()); return r2.contains(eventDateMidnight); }
From source file:com.gst.portfolio.loanaccount.loanschedule.domain.DefaultScheduledDateGenerator.java
License:Apache License
private boolean intervalListContainsDate(List<Interval> intervalList, LocalDate date) { for (Interval interval : intervalList) { if (interval.contains(date.toDateTime(LocalTime.parse("11:59:59")))) { return true; }//from ww w . j a v a 2s . co m } return false; }
From source file:com.helger.datetime.holiday.CalendarUtil.java
License:Apache License
/** * Searches for the occurrences of a month/day in one chronology within one * gregorian year.//w ww . ja va2 s . c om * * @param nTargetMonth * Target month * @param nTargetDay * Target day * @param nGregorianYear * Gregorian year * @param aTargetChronoUTC * Target chronology * @return the list of gregorian dates. */ @Nonnull public static Set<LocalDate> getDatesFromChronologyWithinGregorianYear(final int nTargetMonth, final int nTargetDay, final int nGregorianYear, final Chronology aTargetChronoUTC) { final Set<LocalDate> aHolidays = new HashSet<LocalDate>(); final LocalDate aFirstGregorianDate = PDTFactory.createLocalDate(nGregorianYear, DateTimeConstants.JANUARY, 1); final LocalDate aLastGregorianDate = PDTFactory.createLocalDate(nGregorianYear, DateTimeConstants.DECEMBER, 31); final LocalDate aFirstTargetDate = new LocalDate( aFirstGregorianDate.toDateTimeAtStartOfDay(PDTConfig.getDateTimeZoneUTC()).getMillis(), aTargetChronoUTC); final LocalDate aLastTargetDate = new LocalDate( aLastGregorianDate.toDateTimeAtStartOfDay(PDTConfig.getDateTimeZoneUTC()).getMillis(), aTargetChronoUTC); final Interval aInterv = new Interval( aFirstTargetDate.toDateTimeAtStartOfDay(PDTConfig.getDateTimeZoneUTC()), aLastTargetDate.plusDays(1).toDateTimeAtStartOfDay(PDTConfig.getDateTimeZoneUTC())); for (int nTargetYear = aFirstTargetDate.getYear(); nTargetYear <= aLastTargetDate .getYear(); ++nTargetYear) { final LocalDate aLocalDate = new LocalDate(nTargetYear, nTargetMonth, nTargetDay, aTargetChronoUTC); if (aInterv.contains(aLocalDate.toDateTimeAtStartOfDay(PDTConfig.getDateTimeZoneUTC()))) { aHolidays.add(convertToGregorianDate(aLocalDate)); } } return aHolidays; }
From source file:com.jjlharrison.jollyday.util.CalendarUtil.java
License:Apache License
/** * Searches for the occurrences of a month/day in one chronology within one * gregorian year./*from w w w .ja v a 2 s . c o m*/ * * @param targetMonth * @param targetDay * @param gregorianYear * @param targetChrono * @return the list of gregorian dates. */ private Set<LocalDate> getDatesFromChronologyWithinGregorianYear(int targetMonth, int targetDay, int gregorianYear, Chronology targetChrono) { Set<LocalDate> holidays = new HashSet<LocalDate>(); LocalDate firstGregorianDate = new LocalDate(gregorianYear, DateTimeConstants.JANUARY, 1, ISOChronology.getInstance()); LocalDate lastGregorianDate = new LocalDate(gregorianYear, DateTimeConstants.DECEMBER, 31, ISOChronology.getInstance()); LocalDate firstTargetDate = new LocalDate(firstGregorianDate.toDateTimeAtStartOfDay().getMillis(), targetChrono); LocalDate lastTargetDate = new LocalDate(lastGregorianDate.toDateTimeAtStartOfDay().getMillis(), targetChrono); Interval interv = new Interval(firstTargetDate.toDateTimeAtStartOfDay(), lastTargetDate.plusDays(1).toDateTimeAtStartOfDay()); int targetYear = firstTargetDate.getYear(); for (; targetYear <= lastTargetDate.getYear();) { LocalDate d = new LocalDate(targetYear, targetMonth, targetDay, targetChrono); if (interv.contains(d.toDateTimeAtStartOfDay())) { holidays.add(convertToISODate(d)); } targetYear++; } return holidays; }
From source file:com.marand.thinkmed.medications.administration.impl.AdministrationTaskCreatorImpl.java
License:Open Source License
private List<NewTaskRequestDto> createTasksForVariableDaysTherapy(final String patientId, final VariableSimpleTherapyDto therapy, final Interval taskCreationInterval, final AdministrationTaskCreateActionEnum action) { final Map<DateTime, TherapyDoseDto> timesWithDosesMap = new HashMap<>(); for (final TimedSimpleDoseElementDto timedDoseElement : therapy.getTimedDoseElements()) { getTimedDoseForVariableDaysTherapy(therapy, taskCreationInterval, action, timedDoseElement, timedDoseElement.getDate()).forEach(e -> timesWithDosesMap.put(e.getFirst(), e.getSecond())); }/*from w ww. j a v a2s . co m*/ final DateTime lastAdministrationDateTime = timesWithDosesMap.entrySet().stream().map(Map.Entry::getKey) .max(Comparator.naturalOrder()).orElse(null); final boolean therapyContinuesAfterLastDefinedDose = lastAdministrationDateTime != null && lastAdministrationDateTime.isBefore(taskCreationInterval.getEnd()); if (therapyContinuesAfterLastDefinedDose) { //repeat last day final DateTime lastDayStart = lastAdministrationDateTime.withTimeAtStartOfDay(); final List<TimedSimpleDoseElementDto> lastDayDoses = therapy.getTimedDoseElements().stream() .filter(t -> t.getDate().withTimeAtStartOfDay().equals(lastDayStart)) .collect(Collectors.toList()); DateTime nextDay = lastDayStart.plusDays(1); while (taskCreationInterval.contains(nextDay)) { for (final TimedSimpleDoseElementDto timedDoseElement : lastDayDoses) { getTimedDoseForVariableDaysTherapy(therapy, taskCreationInterval, action, timedDoseElement, nextDay).forEach(e -> timesWithDosesMap.put(e.getFirst(), e.getSecond())); } nextDay = nextDay.plusDays(1); } } return timesWithDosesMap.keySet().stream().sorted(Comparator.naturalOrder()) .filter(administrationTime -> !administrationTime.isAfter(taskCreationInterval.getEnd())) .map(administrationTime -> createMedicationTaskRequest(patientId, therapy, AdministrationTypeEnum.START, administrationTime, timesWithDosesMap.get(administrationTime))) .collect(Collectors.toList()); }