Example usage for org.joda.time Interval Interval

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

Introduction

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

Prototype

public Interval(Object interval, Chronology chronology) 

Source Link

Document

Constructs a time interval by converting or copying from another object, overriding the chronology.

Usage

From source file:net.schweerelos.timeline.model.Timeline.java

License:Open Source License

public Interval convertSliceToInterval(int row) {
    if (row > -1) {
        DateTime periodStart = start;/*from w  w w. ja v  a2s . co m*/
        for (int i = 0; i < row; i++) {
            Duration addDuration = increment.toDurationFrom(periodStart);
            periodStart = periodStart.plus(addDuration);
        }
        Duration addDuration = increment.toDurationFrom(periodStart);
        DateTime periodEnd = periodStart.plus(addDuration);
        if (periodEnd.isAfter(end)) {
            periodEnd = end;
        }
        periodEnd = periodEnd.minus(Minutes.ONE);
        return new Interval(periodStart, periodEnd);
    } else {
        return null;
    }
}

From source file:net.schweerelos.timeline.ui.TimelinePanel.java

License:Open Source License

public IntervalChain<T> getSelections() {
    IntervalChain<T> result = new IntervalChain<T>();
    if (selectionModel.isSelectionEmpty()) {
        return result;
    }/*w  w  w  .  j  a  v  a2  s.c  o  m*/
    List<Interval> selections = new ArrayList<Interval>();
    int minSelectedIndex = selectionModel.getMinSelectionIndex();
    int maxSelectedIndex = selectionModel.getMaxSelectionIndex();

    DateTime lastStart = null;
    int currentIndex = minSelectedIndex;

    while (currentIndex <= maxSelectedIndex) {
        if (selectionModel.isSelectedIndex(currentIndex)) {
            if (lastStart == null) {
                // start of a new interval
                lastStart = tModel.convertSliceToInterval(currentIndex).getStart();
            }
        } else {
            if (lastStart != null) {
                // end of a new interval
                DateTime end = tModel.convertSliceToInterval(currentIndex).getEnd();
                Interval newInterval = new Interval(lastStart, end);
                selections.add(newInterval);
                lastStart = null;
            }
        }
        currentIndex++;
    }
    // lastStart should be non-null now
    if (lastStart != null) {
        // end of a new interval
        DateTime end = tModel.convertSliceToInterval(maxSelectedIndex).getEnd();
        Interval newInterval = new Interval(lastStart, end);
        selections.add(newInterval);
    } else {
        logger.warn("last start is null, shouldn't happen");
    }

    // TODO see if we can get this to be more efficient
    for (PayloadInterval<T> interval : tModel.getIntervalsWithinRange()) {
        for (Interval selection : selections) {
            if (selection.contains(interval.toInterval())) {
                result.add(interval);
            }
        }
    }
    return result;
}

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

License:Apache License

private void analyzeEntries() {
    if (service != null) {
        final DateTimeFormatter format = DateTimeFormat.forPattern("yyyyMMdd");
        final DateTime from = format.parseDateTime(this.from);
        final DateTime to = (this.to != null) ? format.parseDateTime(this.to) : from.plusDays(1);
        final Interval interval = new Interval(from, to);
        final Period period = interval.toPeriod();

        final StringBuffer buffer = new StringBuffer();
        buffer.append("Analyse the log entries from '");
        buffer.append(from.toString()).append('\'');
        buffer.append(" to '").append(to);

        // print the period
        final String space = " ";
        buffer.append("'. The period includes ");
        final PeriodFormatter dateFormat = new PeriodFormatterBuilder().appendYears()
                .appendSuffix(" year", " years").appendSeparator(space).appendMonths()
                .appendSuffix(" month", " months").appendSeparator(space).appendWeeks()
                .appendSuffix(" week", " weeks").appendSeparator(space).appendDays()
                .appendSuffix(" day", " days").appendSeparator(space).appendHours()
                .appendSuffix(" hour", " hours").appendSeparator(space).appendMinutes()
                .appendSuffix(" minute", " minutes").appendSeparator(space).toFormatter();
        dateFormat.printTo(buffer, period);
        buffer.append('.');

        System.out.println(buffer.toString());

        final long maxResults = service.count(interval);
        if (maxResults > 0) {
            int maxCount = 0;
            if (proceed(maxResults)) {
                final long startTime = System.currentTimeMillis();

                final LogEntryAnalysisResult result = analyzerService.analyze(interval).toResult();
                final Map<UserAgentInfo, AtomicInteger> stats = result.getUserAgentInfos();
                System.out.println("User agent information count: " + stats.size());

                String name;//  ww w  .  j  a va 2 s  . co  m
                String osName;
                int count;
                for (final Entry<UserAgentInfo, AtomicInteger> entry : stats.entrySet()) {
                    name = entry.getKey().getName();
                    osName = entry.getKey().getOsName();
                    count = entry.getValue().get();
                    maxCount += count;
                    System.out.println(name + " (" + osName + ") \t" + count);
                }
                System.out.println("Sum: " + maxCount);

                final long elapsedTime = System.currentTimeMillis() - startTime;
                final Period p = new Period(elapsedTime);
                System.out.println("Total processing time: " + p.toString(FORMATTER));
            }
        } else {
            System.out.println("There is nothing to analyze.");
        }
    }
}

From source file:net.solarnetwork.central.dras.mock.biz.MockDRASQueryBiz.java

License:Open Source License

/**
 * Constructor.//from   www . j av a  2  s  .c  om
 * 
 * @param observerBiz the observer biz to setup mock data with
 */
public MockDRASQueryBiz(MockDRASObserverBiz observerBiz) {
    DateTimeZone tz = DateTimeZone.forID("Pacific/Auckland");
    reportableInterval = new Interval(new DateTime(2011, 1, 1, 8, 0, 0, 0, tz),
            new DateTime(2011, 2, 1, 8, 0, 0, 0, tz));
    /*
    for ( Program program : observerBiz.getAllPrograms(null) ) {
       for ( NodeIdentity node : observerBiz.getProgramParticipants(program, null, null)) {
            
            
       }
    }
    */
}

From source file:net.sourceforge.fenixedu.applicationTier.Factory.RoomSiteComponentBuilder.java

License:Open Source License

private ISiteComponent getInfoSiteRoomTimeTable(InfoSiteRoomTimeTable component, Calendar day, Space room,
        ExecutionSemester executionSemester) throws Exception {

    List<InfoObject> infoShowOccupations = new ArrayList<InfoObject>();

    Calendar startDay = Calendar.getInstance();
    startDay.setTimeInMillis(day.getTimeInMillis());
    startDay.add(Calendar.DATE, Calendar.MONDAY - day.get(Calendar.DAY_OF_WEEK));

    Calendar endDay = Calendar.getInstance();
    endDay.setTimeInMillis(startDay.getTimeInMillis());
    endDay.add(Calendar.DATE, 6);

    // final boolean isCurrentUserRoomManager =
    // isCurrentUserRoomManager(room);

    final YearMonthDay weekStartYearMonthDay = YearMonthDay.fromCalendarFields(startDay);
    final YearMonthDay weekEndYearMonthDay = YearMonthDay.fromCalendarFields(endDay);

    final Interval search = new Interval(weekStartYearMonthDay.toDateTimeAtMidnight(),
            weekEndYearMonthDay.toDateTimeAtMidnight());

    for (final Occupation roomOccupation : room.getOccupationSet()) {

        if (roomOccupation instanceof WrittenEvaluationSpaceOccupation) {
            Collection<WrittenEvaluation> writtenEvaluations = ((WrittenEvaluationSpaceOccupation) roomOccupation)
                    .getWrittenEvaluationsSet();
            getWrittenEvaluationRoomOccupations(infoShowOccupations, weekStartYearMonthDay, weekEndYearMonthDay,
                    writtenEvaluations);
        } else if (roomOccupation instanceof LessonSpaceOccupation) {
            final Lesson lesson = ((LessonSpaceOccupation) roomOccupation).getLesson();
            getLessonOccupations(infoShowOccupations, weekStartYearMonthDay, weekEndYearMonthDay, lesson);
        } else if (roomOccupation instanceof LessonInstanceSpaceOccupation) {
            Collection<LessonInstance> lessonInstances = ((LessonInstanceSpaceOccupation) roomOccupation)
                    .getLessonInstancesSet();
            getLessonInstanceOccupations(infoShowOccupations, weekStartYearMonthDay, weekEndYearMonthDay,
                    lessonInstances);//  w w w .  j a  v a2 s .  c om
        } else {
            for (Interval interval : roomOccupation.getIntervals()) {
                if (search.overlaps(interval)) {
                    infoShowOccupations.add(new InfoOccupation(roomOccupation, interval));
                }
            }
        }
    }

    component.setInfoShowOccupation(infoShowOccupations);
    component.setInfoRoom(InfoRoom.newInfoFromDomain(room));

    return component;
}

From source file:net.sourceforge.fenixedu.applicationTier.Factory.RoomSiteComponentBuilder.java

License:Open Source License

private void getLessonOccupations(List<InfoObject> infoShowOccupations, YearMonthDay weekStartYearMonthDay,
        YearMonthDay weekEndYearMonthDay, Lesson lesson) {

    if (lesson != null && lesson.getShift() != null && lesson.containsWithoutCheckInstanceDates(new Interval(
            weekStartYearMonthDay.toDateTimeAtMidnight(), weekEndYearMonthDay.toDateTimeAtMidnight()))) {
        infoShowOccupations.add(InfoLesson.newInfoFromDomain(lesson));
    }/*from  w w  w .j a v a  2s . co  m*/
}

From source file:net.sourceforge.fenixedu.dataTransferObject.administrativeOffice.lists.SearchDiplomasBySituationParametersBean.java

License:Open Source License

@Override
public Collection<AcademicServiceRequest> searchAcademicServiceRequests() {
    return AcademicAuthorizationGroup.getAcademicServiceRequests(AccessControl.getPerson(), serviceRequestYear,
            academicServiceRequestSituationType,
            new Interval(searchBegin.toDateTimeAtStartOfDay(), searchEnd.toDateTimeAtStartOfDay()));
}

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

License:Open Source License

public SortedSet<Integer> getWeeks() {
    final ExecutionCourse executionCourse = shift.getExecutionCourse();
    final YearMonthDay firstPossibleLessonDay = executionCourse.getMaxLessonsPeriod().getLeft();
    final YearMonthDay lastPossibleLessonDay = executionCourse.getMaxLessonsPeriod().getRight();
    return getWeeks(new Interval(firstPossibleLessonDay.toDateTimeAtMidnight(),
            lastPossibleLessonDay.toDateTimeAtMidnight().plusDays(1)));
}

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

License:Open Source License

public OccupationPeriodBean(int id) {

    this.id = id;

    this.semester = ExecutionSemester.readActualExecutionSemester().getSemester();

    this.occupationPeriodType = OccupationPeriodType.LESSONS;

    this.intervals = Lists.newArrayList(new Interval(new DateTime(), new DateTime().plusDays(1)));

}

From source file:net.sourceforge.fenixedu.dataTransferObject.teacherCredits.TeacherCreditsPeriodBean.java

License:Open Source License

private Interval getSharedUnitCreditsInterval() {
    return new Interval(getSharedUnitCreditsBeginDate(), getSharedUnitCreditsEndDate());
}