Java Code Examples for org.joda.time.Interval#contains()

The following examples show how to use org.joda.time.Interval#contains() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Retention.java    From btrbck with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Calculate the instants a snapshot should be retained for, given the
 * current time.
 */
public Set<DateTime> retentionTimes(DateTime now) {
    HashSet<DateTime> result = new HashSet<>();
    Interval interval = new Interval(now.minus(period), now);
    DateTime current = timeUnit.truncate(interval.getStart());
    while (current.isBefore(now)) {
        DateTime endOfUnit = current.plus(timeUnit.getPeriod());
        long step = new Interval(current, endOfUnit).toDurationMillis()
                / snapshotsPerTimeUnit;
        for (int i = 0; i < snapshotsPerTimeUnit; i++) {
            DateTime retentionTime = current.plus(i * step);
            if (interval.contains(retentionTime)) {
                result.add(retentionTime);
            }
        }
        current = endOfUnit;
    }
    return result;
}
 
Example 2
Source File: AcademicServiceRequest.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static Set<AcademicServiceRequest> getAcademicServiceRequests(Person person, Integer year,
        AcademicServiceRequestSituationType situation, Interval interval) {
    Set<AcademicServiceRequest> serviceRequests = new HashSet<AcademicServiceRequest>();
    Set<AcademicProgram> programs =
            AcademicAccessRule.getProgramsAccessibleToFunction(AcademicOperationType.SERVICE_REQUESTS, person.getUser())
                    .collect(Collectors.toSet());
    Collection<AcademicServiceRequest> possible = null;
    if (year != null) {
        possible = AcademicServiceRequestYear.getAcademicServiceRequests(year);
    } else {
        possible = Bennu.getInstance().getAcademicServiceRequestsSet();
    }
    for (AcademicServiceRequest request : possible) {
        if (!programs.contains(request.getAcademicProgram())) {
            continue;
        }
        if (situation != null && !request.getAcademicServiceRequestSituationType().equals(situation)) {
            continue;
        }
        if (interval != null && !interval.contains(request.getActiveSituationDate())) {
            continue;
        }
        serviceRequests.add(request);
    }
    return serviceRequests;
}
 
Example 3
Source File: OnlineDbMVStore.java    From ipst with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public List<OnlineWorkflowDetails> listWorkflows(Interval basecaseInterval) {
    LOGGER.info("Getting list of stored workflows run on basecases within the interval {}", basecaseInterval);
    String dateFormatPattern = "yyyyMMdd_HHmm";
    DateTimeFormatter formatter = DateTimeFormat.forPattern(dateFormatPattern);
    List<OnlineWorkflowDetails> workflowIds = new ArrayList<OnlineWorkflowDetails>();
    File[] files = config.getOnlineDbDir().toFile().listFiles(new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.toLowerCase().startsWith(STORED_WORKFLOW_PREFIX);
        }
    });
    for (File file : files) {
        if (file.isFile()) {
            String workflowId = file.getName().substring(STORED_WORKFLOW_PREFIX.length());
            if (workflowId.length() > dateFormatPattern.length() && workflowId.substring(dateFormatPattern.length(), dateFormatPattern.length() + 1).equals("_")) {
                String basecaseName = workflowId.substring(0, dateFormatPattern.length() - 1);
                DateTime basecaseDate = DateTime.parse(basecaseName, formatter);
                if (basecaseInterval.contains(basecaseDate.getMillis())) {
                    OnlineWorkflowDetails workflowDetails = new OnlineWorkflowDetails(workflowId);
                    workflowDetails.setWorkflowDate(getWorkflowDate(workflowId));
                    workflowIds.add(workflowDetails);
                }
            }
        }
    }
    Collections.sort(workflowIds, new Comparator<OnlineWorkflowDetails>() {
        @Override
        public int compare(OnlineWorkflowDetails wfDetails1, OnlineWorkflowDetails wfDetails2) {
            return wfDetails1.getWorkflowDate().compareTo(wfDetails2.getWorkflowDate());
        }
    });
    LOGGER.info("Found {} workflow(s)", workflowIds.size());
    return workflowIds;
}
 
Example 4
Source File: JodatimeUtilsTest.java    From onetwo with Apache License 2.0 5 votes vote down vote up
@Test
public void testInterval(){
	DateTime start = JodatimeUtils.parse("2016-11-24");
	DateTime end = JodatimeUtils.parse("2016-12-24");
	Interval interval = new Interval(start, end);
	boolean res = interval.contains(start.plusSeconds(1));
	Assertions.assertThat(res).isTrue();
	res = interval.contains(start.minusSeconds(1));
	Assertions.assertThat(res).isFalse();
}
 
Example 5
Source File: WrittenTest.java    From fenixedu-academic with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void checkEvaluationDate(final Date writtenEvaluationDate, final List<ExecutionCourse> executionCoursesToAssociate) {

        for (final ExecutionCourse executionCourse : executionCoursesToAssociate) {
            final long beginDate = executionCourse.getExecutionPeriod().getBeginDate().getTime();
            final long endDate = executionCourse.getExecutionPeriod().getEndDate().getTime();
            final DateTime endDateTime = new DateTime(endDate);
            final Interval interval = new Interval(beginDate, endDateTime.plusDays(1).getMillis());
            if (!interval.contains(writtenEvaluationDate.getTime())) {
                throw new DomainException("error.invalidWrittenTestDate");
            }
        }
    }
 
Example 6
Source File: Session.java    From bateman with MIT License 5 votes vote down vote up
public Trade tradeAt(final DateTime date) {
    for (Trade trade : trades) {
        Interval interval = new Interval(trade.getOpen(), trade.getClose());
        if (interval.contains(date)) {
            return trade;
        }
    }

    return null;
}
 
Example 7
Source File: JodatimeUtils.java    From onetwo with Apache License 2.0 3 votes vote down vote up
/****
 * theTime是否在start和end的时间内
 * @param theTime
 * @param start
 * @param end
 * @return
 * @author way
 */
public static boolean isTimeBetweenInterval(Date theTime, Date start, Date end){
	Objects.requireNonNull(start);
	Objects.requireNonNull(end);
	Interval interval = createInterval(start, end);
	return interval.contains(new DateTime(theTime));
}