Example usage for org.joda.time Interval getStart

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

Introduction

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

Prototype

public DateTime getStart() 

Source Link

Document

Gets the start of this time interval, which is inclusive, as a DateTime.

Usage

From source file:net.sf.jacclog.persistence.jpa.internal.LogEntryRepository.java

License:Apache License

/**
 * Finds all log entries between an interval and ordered by ID. In addition by specifying a starting position and a
 * maximum number of results it restricts the size of the result set.
 * /*  w w  w  .  ja  v  a 2  s.c  o m*/
 * @param interval
 *            A period of time between two dates.
 * @param startPosition
 *            Position of the first result, numbered from 0
 * @param maxResults
 *            Maximum number of results to retrieve
 * @throws IllegalArgumentException
 *             If the interval is null
 * @return A list of log entries
 */
public List<LogEntry> find(final Interval interval, final int startPosition, final int maxResults) {
    if (interval == null) {
        throw new IllegalArgumentException("Argument 'interval' can not be null.");
    }

    return find(interval.getStart().toDate(), interval.getEnd().toDate(), startPosition, maxResults);
}

From source file:net.sf.jacclog.service.analyzer.internal.LogEntryAnalyzer.java

License:Apache License

/**
 * Validates a time interval if it is suitable for an analysis.
 * /*ww  w.  j a v a  2  s  .c o m*/
 * @param interval
 *            Time interval
 */
private void validateInterval(final Interval interval) {
    if (interval == null) {
        throw new IllegalArgumentException("Argument 'interval' can not be null.");
    }

    if (interval.getStart().isAfter(interval.getEndMillis())) {
        throw new IllegalArgumentException("The time interval specify an negative range.");
    }
}

From source file:net.sf.jacclog.service.analyzer.internal.task.AnalysisByIntervalTask.java

License:Apache License

public AnalysisByIntervalTask(
        final LogEntryService<ReadableLogEntry<ReadableHttpRequestHeaderField, ReadableHttpResponseHeaderField>> service,
        final UserAgentStringParser parser, final LogEntryAnalysisResult.Builder builder,
        final Interval interval, final int startPosition, final int maxResults) {

    if (service == null) {
        throw new IllegalArgumentException("Argument 'service' can not be null.");
    }/*from w  ww . ja v a 2s. c  o  m*/

    if (parser == null) {
        throw new IllegalArgumentException("Argument 'parser' can not be null.");
    }

    if (builder == null) {
        throw new IllegalArgumentException("Argument 'builder' can not be null.");
    }

    if (interval == null) {
        throw new IllegalArgumentException("Argument 'interval' can not be null.");
    }

    if (interval.getStart().isAfter(interval.getEndMillis())) {
        throw new IllegalArgumentException("The time interval specify an negative range.");
    }

    if (startPosition < 0) {
        throw new IllegalArgumentException("Argument 'startPosition' can not be smaller than 0.");
    }

    if (maxResults < 1) {
        throw new IllegalArgumentException("Argument 'maxResults' can not be smaller than 1.");
    }

    this.service = service;
    this.parser = parser;
    this.builder = builder;
    this.interval = interval;
    this.startPosition = startPosition;
    this.maxResults = maxResults;
}

From source file:net.sourceforge.fenixedu.dataTransferObject.InfoLessonInstanceAggregation.java

License:Open Source License

public SortedSet<Integer> getWeeks(final Interval lessonInterval) {
    final SortedSet<Integer> weeks = new TreeSet<Integer>();
    final LocalDate firstPossibleLessonDay = lessonInterval.getStart().toLocalDate();
    for (final LocalDate localDate : dates) {
        final Integer week = Weeks.weeksBetween(firstPossibleLessonDay, localDate).getWeeks() + 1;
        weeks.add(week);//from  w w w. j  a  va  2 s  .co  m
    }
    return weeks;
}

From source file:net.sourceforge.fenixedu.dataTransferObject.resourceAllocationManager.OccupationPeriodBean.java

License:Open Source License

public String getDatesString() {
    if (intervals.size() == 0 || occupationPeriod == null) {
        return BundleUtil.getString(Bundle.RESOURCE_ALLOCATION, "label.periods.no.dates");
    }//w ww .  jav  a 2s.co  m

    DateTimeFormatter formatter = DateTimeFormat.forPattern("dd MMM").withLocale(I18N.getLocale());

    StringBuilder builder = new StringBuilder();

    for (Interval interval : getIntervals()) {

        if (builder.length() > 0) {
            builder.append(", ");
        }

        builder.append(formatter.print(interval.getStart()));

        builder.append(" - ");

        builder.append(formatter.print(interval.getEnd()));

    }

    return builder.toString();

}

From source file:net.sourceforge.fenixedu.domain.Lesson.java

License:Open Source License

public SortedSet<Interval> getAllLessonIntervalsWithoutInstanceDates() {
    SortedSet<Interval> dates = new TreeSet<Interval>(new Comparator<Interval>() {

        @Override// w w w  .  j a v a  2  s .  c om
        public int compare(Interval o1, Interval o2) {
            return o1.getStart().compareTo(o2.getStart());
        }

    });
    if (!wasFinished()) {
        YearMonthDay startDateToSearch = getLessonStartDay();
        YearMonthDay endDateToSearch = getLessonEndDay();
        final HourMinuteSecond b = getBeginHourMinuteSecond();
        final HourMinuteSecond e = getEndHourMinuteSecond();
        for (final YearMonthDay yearMonthDay : getAllValidLessonDatesWithoutInstancesDates(startDateToSearch,
                endDateToSearch)) {
            final DateTime start = new DateTime(yearMonthDay.getYear(), yearMonthDay.getMonthOfYear(),
                    yearMonthDay.getDayOfMonth(), b.getHour(), b.getMinuteOfHour(), b.getSecondOfMinute(), 0);
            final DateTime end = new DateTime(yearMonthDay.getYear(), yearMonthDay.getMonthOfYear(),
                    yearMonthDay.getDayOfMonth(), e.getHour(), e.getMinuteOfHour(), e.getSecondOfMinute(), 0);
            dates.add(new Interval(start, end));
        }
    }
    return dates;
}

From source file:net.sourceforge.fenixedu.domain.Lesson.java

License:Open Source License

public boolean overlaps(final Interval interval) {
    if (wasFinished()) {
        return false;
    }/*from   w  w w.  ja va  2s . c o m*/
    final YearMonthDay startDateToSearch = getLessonStartDay();
    if (startDateToSearch == null) {
        return false;
    }
    final YearMonthDay endDateToSearch = getLessonEndDay();
    if (endDateToSearch == null) {
        return false;
    }
    final DateTime intervalStart = interval.getStart();
    if (intervalStart.isAfter(endDateToSearch.toDateTimeAtMidnight().plusDays(1))) {
        return false;
    }
    final DateTime intervalEnd = interval.getEnd();
    if (intervalEnd.isBefore(startDateToSearch.toDateTimeAtMidnight())) {
        return false;
    }
    final HourMinuteSecond b = getBeginHourMinuteSecond();
    final HourMinuteSecond e = getEndHourMinuteSecond();
    for (final YearMonthDay yearMonthDay : getAllValidLessonDatesWithoutInstancesDates(startDateToSearch,
            endDateToSearch)) {
        final DateTime start = new DateTime(yearMonthDay.getYear(), yearMonthDay.getMonthOfYear(),
                yearMonthDay.getDayOfMonth(), b.getHour(), b.getMinuteOfHour(), b.getSecondOfMinute(), 0);
        if (start.isAfter(intervalEnd)) {
            continue;
        }
        final DateTime end = new DateTime(yearMonthDay.getYear(), yearMonthDay.getMonthOfYear(),
                yearMonthDay.getDayOfMonth(), e.getHour(), e.getMinuteOfHour(), e.getSecondOfMinute(), 0);
        if (end.isBefore(intervalStart)) {
            continue;
        }
        return true;
    }
    return false;
}

From source file:net.sourceforge.fenixedu.domain.Lesson.java

License:Open Source License

private boolean isAllIntervalIn(Interval interval, SortedSet<YearMonthDay> allLessonDates) {

    YearMonthDay intervalStartDate = interval.getStart().toYearMonthDay();
    YearMonthDay intervalEndDate = interval.getEnd().toYearMonthDay();

    HourMinuteSecond intervalBegin = new HourMinuteSecond(interval.getStart().getHourOfDay(),
            interval.getStart().getMinuteOfHour(), 0);
    HourMinuteSecond intervalEnd = new HourMinuteSecond(interval.getEnd().getHourOfDay(),
            interval.getEnd().getMinuteOfHour(), 0);

    for (YearMonthDay day : allLessonDates) {
        if (intervalStartDate.isEqual(intervalEndDate)) {
            if (day.isEqual(intervalStartDate) && !intervalBegin.isBefore(getBeginHourMinuteSecond())
                    && !intervalEnd.isAfter(getEndHourMinuteSecond())) {
                return true;
            }//from   w  w  w. j  ava 2s.  c  o  m
        }
    }
    return false;
}

From source file:net.sourceforge.fenixedu.domain.Lesson.java

License:Open Source License

private boolean contains(Interval interval, SortedSet<YearMonthDay> allLessonDates) {

    YearMonthDay intervalStartDate = interval.getStart().toYearMonthDay();
    YearMonthDay intervalEndDate = interval.getEnd().toYearMonthDay();

    HourMinuteSecond intervalBegin = new HourMinuteSecond(interval.getStart().getHourOfDay(),
            interval.getStart().getMinuteOfHour(), interval.getStart().getSecondOfMinute());
    HourMinuteSecond intervalEnd = new HourMinuteSecond(interval.getEnd().getHourOfDay(),
            interval.getEnd().getMinuteOfHour(), interval.getEnd().getSecondOfMinute());

    for (YearMonthDay day : allLessonDates) {
        if (intervalStartDate.isEqual(intervalEndDate)) {
            if (day.isEqual(intervalStartDate) && !intervalBegin.isAfter(getEndHourMinuteSecond())
                    && !intervalEnd.isBefore(getBeginHourMinuteSecond())) {
                return true;
            }/*from  ww  w .  j a va  2  s. c o  m*/
        } else {
            if ((day.isAfter(intervalStartDate) && day.isBefore(intervalEndDate))
                    || day.isEqual(intervalStartDate) && !getEndHourMinuteSecond().isBefore(intervalBegin)
                    || (day.isEqual(intervalEndDate) && !getBeginHourMinuteSecond().isAfter(intervalEnd))) {
                return true;
            }
        }
    }
    return false;
}

From source file:net.sourceforge.fenixedu.domain.Lesson.java

License:Open Source License

public String getOccurrenceWeeksAsString() {
    final SortedSet<Integer> weeks = new TreeSet<Integer>();

    final ExecutionCourse executionCourse = getExecutionCourse();
    final YearMonthDay firstPossibleLessonDay = executionCourse.getMaxLessonsPeriod().getLeft();
    final YearMonthDay lastPossibleLessonDay = executionCourse.getMaxLessonsPeriod().getRight();
    for (final Interval interval : getAllLessonIntervals()) {
        final Integer week = Weeks.weeksBetween(firstPossibleLessonDay, interval.getStart().toLocalDate())
                .getWeeks() + 1;// w  ww.j  av  a 2 s .  c o  m
        weeks.add(week);
    }

    final StringBuilder builder = new StringBuilder();
    final Integer[] weeksA = weeks.toArray(new Integer[0]);
    for (int i = 0; i < weeksA.length; i++) {
        if (i == 0) {
            builder.append(weeksA[i]);
        } else if (i == weeksA.length - 1 || (weeksA[i]) + 1 != (weeksA[i + 1])) {
            final String seperator = (weeksA[i - 1]) + 1 == (weeksA[i]) ? " - " : ", ";
            builder.append(seperator);
            builder.append(weeksA[i]);
        } else if ((weeksA[i - 1]) + 1 != weeksA[i]) {
            builder.append(", ");
            builder.append(weeksA[i]);
        }
    }
    return builder.toString();
}