Example usage for org.joda.time Interval contains

List of usage examples for org.joda.time Interval contains

Introduction

In this page you can find the example usage for org.joda.time Interval contains.

Prototype

public boolean contains(long millisInstant) 

Source Link

Document

Does this time interval contain the specified millisecond instant.

Usage

From source file:com.sos.scheduler.model.objects.JodaTools.java

License:Apache License

public static DateTime getDayInIntervalOrNull(Interval interval, int day) {
    DateTime currentDate = getStartOfMonth(interval.getStart());
    DateTime result = getDayInMonth(currentDate, day);
    while (!interval.contains(result)) {
        currentDate = currentDate.plusMonths(1);
        result = getDayInMonth(currentDate, day);
        if (!result.isBefore(interval.getEnd()))
            return null;
    }//  ww  w. j a  v  a 2s .co m
    return result;
}

From source file:com.sos.scheduler.model.objects.JSObjAt.java

License:Apache License

@Override
public RunTimeElements getRunTimeElements(Interval timeRange) {
    RunTimeElements result = new RunTimeElements(timeRange);
    if (timeRange.contains(getDtAt())) {
        // The at element does not have a subsequent period element, therefore we use IGNORE_HOLIDAY anyway.
        RunTimeElement e = new RunTimeElement(getDtAt(), WhenHoliday.IGNORE_HOLIDAY);
        result.add(e);//from   w  w w.  j  a v a 2 s .  co  m
    }
    return result;
}

From source file:com.sos.scheduler.model.objects.JSObjDate.java

License:Apache License

@Override
public RunTimeElements getRunTimeElements(Interval timeRange) {
    RunTimeElements result = new RunTimeElements(timeRange);
    Iterator<Period> it = getPeriod().iterator();
    while (it.hasNext()) {
        Period p = it.next();//w  w w .  ja  va2s. c om
        JSObjPeriod period = new JSObjPeriod(objFactory);
        period.setObjectFieldsFrom(p);
        DateTime singleStart = period.getDtSingleStartOrNull(getDtDate());
        if (singleStart != null && timeRange.contains(singleStart)) {
            result.add(new RunTimeElement(singleStart, period.getWhenHoliday()));
        }
    }
    //      Collections.sort(result, DateTimeComparator.getInstance());
    return result;
}

From source file:com.sos.scheduler.model.objects.JSObjDay.java

License:Apache License

@Override
public RunTimeElements getRunTimeElements(Interval timeRange) {
    RunTimeElements result = new RunTimeElements(timeRange);
    RunTimeElements work = getNextSingleStarts(timeRange.getStart());
    for (RunTimeElement runtime : work.values()) {
        DateTime date = runtime.getStartDate();
        if (timeRange.contains(date)) {
            while (timeRange.contains(date)) {
                result.add(new RunTimeElement(date, runtime.getWhenHoliday()));
                date = date.plusWeeks(1);
            }//from w w  w  .  j  a v  a  2  s.  com
        }
    }
    //      Collections.sort(result, DateTimeComparator.getInstance());
    return result;
}

From source file:com.sos.scheduler.model.objects.JSObjHolidays.java

License:Apache License

private List<DateTime> getDtHoliday(Interval timeRange) {
    List<DateTime> result = new ArrayList<DateTime>();
    Iterator<Object> it = getWeekdaysOrHolidayOrInclude().iterator();
    while (it.hasNext()) {
        Object o = it.next();//from  ww  w  .ja v  a  2  s.  c o m
        if (o instanceof Holiday) {
            Holiday h = (Holiday) o;
            JSObjHoliday holiday = new JSObjHoliday(objFactory);
            holiday.setObjectFieldsFrom(h);
            DateTime d = holiday.getDtHoliday();
            if (timeRange.contains(d))
                result.add(d);
        }
    }
    return result;
}

From source file:com.sos.scheduler.model.objects.JSObjHolidays.java

License:Apache License

/**
 * \brief move the calculated start dates if it is demanded by holidays definiton 
 * \detail/*from  w  w w  . ja  va2s  .  co m*/
 *
 * @param runTimes
 * @return
 */
public List<DateTime> getStartDatesAwareHolidays(RunTimeElements runTimes) {
    List<DateTime> result = new ArrayList<DateTime>();
    Interval timeRange = runTimes.getTimeRange();
    if (getHolidays(timeRange).size() == 0)
        return runTimes.getStartTimes();

    for (RunTimeElement runTime : runTimes.values()) {
        if (isHoliday(runTime.getStartDate())) {
            switch (runTime.getWhenHoliday()) {
            case SUPPRESS:
                break;
            case IGNORE_HOLIDAY:
                if (!result.contains(runTime.getStartDate()))
                    result.add(runTime.getStartDate());
                break;
            case NEXT_NON_HOLIDAY:
                DateTime nextStart = getNextNonHoliday(runTime.getStartDate());
                if (timeRange.contains(nextStart) && !result.contains(nextStart))
                    result.add(nextStart);
                break;
            case PREVIOUS_NON_HOLIDAY:
                DateTime previousStart = getPreviousNonHoliday(runTime.getStartDate());
                if (timeRange.contains(previousStart) && !result.contains(previousStart))
                    result.add(previousStart);
                break;
            }
        }
    }

    return result;
}

From source file:com.sos.scheduler.model.objects.JSObjHolidaysWeekdaysDay.java

License:Apache License

public List<DateTime> getDtHolidays(Interval timeRange) {
    List<DateTime> result = new ArrayList<DateTime>();
    List<DateTime> work = getNextSingleStarts(timeRange.getStart());
    for (DateTime date : work) {
        if (timeRange.contains(date)) {
            while (timeRange.contains(date)) {
                result.add(date);//from   w ww  .  j  ava  2  s  .  c o  m
                date = date.plusWeeks(1);
            }
        }
    }
    Collections.sort(result, DateTimeComparator.getInstance());
    return result;
}

From source file:com.sos.scheduler.model.objects.JSObjMonthdaysDay.java

License:Apache License

@Override
public RunTimeElements getRunTimeElements(Interval timeRange) {
    RunTimeElements result = new RunTimeElements(timeRange);
    Iterator<Integer> it = getDay().iterator();
    while (it.hasNext()) {
        int day = it.next();
        DateTime date = JodaTools.getDayInIntervalOrNull(timeRange, day);
        while (date != null) {
            Iterator<Period> itP = getPeriod().iterator();
            while (itP.hasNext()) {
                Period p = itP.next();
                JSObjPeriod period = new JSObjPeriod(objFactory);
                period.setObjectFieldsFrom(p);
                DateTime start = period.getDtSingleStartOrNull(date);
                if (start != null && timeRange.contains(start))
                    result.add(new RunTimeElement(start, period.getWhenHoliday()));
            }//  ww  w .  j av  a 2 s. co  m
            DateTime start = JodaTools.getStartOfMonth(date.plusMonths(1));
            if (!timeRange.contains(start))
                break;
            Interval i = new Interval(start, timeRange.getEnd());
            date = JodaTools.getDayInIntervalOrNull(i, day);
        }
    }
    //         Collections.sort(result, DateTimeComparator.getInstance());
    return result;
}

From source file:com.sos.scheduler.model.objects.JSObjPeriod.java

License:Apache License

public boolean isInPeriod(DateTime timeStamp) {
    if (hasSingleStart())
        return true;
    Interval p = getPeriodOrNull(timeStamp);
    return p.contains(timeStamp);
}

From source file:com.sos.scheduler.model.objects.JSObjPeriod.java

License:Apache License

@Override
public RunTimeElements getRunTimeElements(Interval timeRange) {
    RunTimeElements result = new RunTimeElements(timeRange);
    DateTime dt = getDtSingleStartOrNull(timeRange.getStart());
    if (dt != null) {
        result = new RunTimeElements(timeRange);
        if (!timeRange.contains(dt))
            dt = dt.plusDays(1);/*ww  w  . ja  v a 2s .  c  o m*/
        while (true) {
            if (!timeRange.contains(dt))
                break;
            result.add(new RunTimeElement(dt, getWhenHoliday()));
            dt = dt.plusDays(1);
        }
        //         Collections.sort(result, DateTimeComparator.getInstance());
    }
    return result;
}