List of usage examples for org.joda.time Interval getEnd
public DateTime getEnd()
From source file:org.springframework.ws.samples.airline.dao.jpa.JpaFlightDao.java
License:Apache License
public List<Flight> findFlights(String fromAirportCode, String toAirportCode, Interval interval, ServiceClass serviceClass) throws DataAccessException { Query query = entityManager.createQuery("SELECT f FROM Flight f WHERE f.from.code = :fromParam " + "AND f.to.code = :toParam AND f.departureTime >= :start AND f.departureTime <= :end AND " + "f.serviceClass = :class"); query.setParameter("fromParam", fromAirportCode); query.setParameter("toParam", toAirportCode); query.setParameter("start", interval.getStart()); query.setParameter("end", interval.getEnd()); query.setParameter("class", serviceClass); return query.getResultList(); }
From source file:org.springframework.xd.analytics.metrics.memory.InMemoryAggregateCounter.java
License:Apache License
public AggregateCount getCounts(Interval interval, AggregateCountResolution resolution) { DateTime start = interval.getStart(); DateTime end = interval.getEnd(); Chronology c = interval.getChronology(); long[] counts; if (resolution == AggregateCountResolution.minute) { List<long[]> days = accumulateDayCounts(minuteCountsByDay, start, end, 60 * 24); counts = MetricUtils.concatArrays(days, interval.getStart().getMinuteOfDay(), interval.toPeriod().toStandardMinutes().getMinutes() + 1); } else if (resolution == AggregateCountResolution.hour) { List<long[]> days = accumulateDayCounts(hourCountsByDay, start, end, 24); counts = MetricUtils.concatArrays(days, interval.getStart().getHourOfDay(), interval.toPeriod().toStandardHours().getHours() + 1); } else if (resolution == AggregateCountResolution.day) { DateTime startDay = new DateTime(c.dayOfYear().roundFloor(start.getMillis())); DateTime endDay = new DateTime(c.dayOfYear().roundFloor(end.plusDays(1).getMillis())); int nDays = Days.daysBetween(startDay, endDay).getDays(); DateTime cursor = new DateTime(c.year().roundFloor(interval.getStartMillis())); List<long[]> yearDays = new ArrayList<long[]>(); DateTime endYear = new DateTime(c.year().roundCeiling(end.getMillis())); while (cursor.isBefore(endYear)) { long[] dayCounts = dayCountsByYear.get(cursor.getYear()); if (dayCounts == null) { // Querying where we have no data dayCounts = new long[daysInYear(cursor.getYear())]; }//from ww w. j a v a2 s .co m yearDays.add(dayCounts); cursor = cursor.plusYears(1); } counts = MetricUtils.concatArrays(yearDays, startDay.getDayOfYear() - 1, nDays); } else if (resolution == AggregateCountResolution.month) { DateTime startMonth = new DateTime(c.monthOfYear().roundFloor(interval.getStartMillis())); DateTime endMonth = new DateTime(c.monthOfYear().roundFloor(end.plusMonths(1).getMillis())); int nMonths = Months.monthsBetween(startMonth, endMonth).getMonths(); DateTime cursor = new DateTime(c.year().roundFloor(interval.getStartMillis())); List<long[]> yearMonths = new ArrayList<long[]>(); DateTime endYear = new DateTime(c.year().roundCeiling(end.getMillis())); while (cursor.isBefore(endYear)) { long[] monthCounts = monthCountsByYear.get(cursor.getYear()); if (monthCounts == null) { monthCounts = new long[12]; } yearMonths.add(monthCounts); cursor = cursor.plusYears(1); } counts = MetricUtils.concatArrays(yearMonths, startMonth.getMonthOfYear() - 1, nMonths); } else if (resolution == AggregateCountResolution.year) { DateTime startYear = new DateTime(interval.getStart().getYear(), 1, 1, 0, 0); DateTime endYear = new DateTime(end.getYear() + 1, 1, 1, 0, 0); int nYears = Years.yearsBetween(startYear, endYear).getYears(); counts = new long[nYears]; for (int i = 0; i < nYears; i++) { long[] monthCounts = monthCountsByYear.get(startYear.plusYears(i).getYear()); counts[i] = MetricUtils.sum(monthCounts); } } else { throw new IllegalStateException("Shouldn't happen. Unhandled resolution: " + resolution); } return new AggregateCount(getName(), interval, counts, resolution); }
From source file:org.springframework.xd.analytics.metrics.redis.RedisAggregateCounterRepository.java
License:Apache License
/** * For each query, we need to convert the interval into two variations. One is the start and end points rounded to * the resolution (used to calculate the number of entries to be returned from the query). The second is the start * and end buckets we have to retrieve which may contain entries for the interval. For example, when querying * at day resolution, the number of entries is the number of Joda time days between the start (rounded down to a * day boundary) and the end plus one day (also rounded down). However, we need load the data from the buckets * from the month the start day occurs in to the month end day occurs in. These are then concatenated, using the * start day as the start index into the first array, and writing the total number of entries in sequence from that * point into the combined result counts array. */// www . j a v a 2 s . co m @Override public AggregateCount getCounts(String name, Interval interval, AggregateCountResolution resolution) { DateTime end = interval.getEnd(); Chronology c = interval.getChronology(); long[] counts; if (resolution == AggregateCountResolution.minute) { // Iterate through each hour in the interval and load the minutes for it MutableDateTime dt = new MutableDateTime(interval.getStart()); dt.setRounding(c.hourOfDay()); Duration step = Duration.standardHours(1); List<long[]> hours = new ArrayList<long[]>(); while (dt.isBefore(end) || dt.isEqual(end)) { hours.add(getMinCountsForHour(name, dt)); dt.add(step); } counts = MetricUtils.concatArrays(hours, interval.getStart().getMinuteOfHour(), interval.toPeriod().toStandardMinutes().getMinutes() + 1); } else if (resolution == AggregateCountResolution.hour) { DateTime cursor = new DateTime(c.dayOfMonth().roundFloor(interval.getStart().getMillis())); List<long[]> days = new ArrayList<long[]>(); Duration step = Duration.standardHours(24); while (cursor.isBefore(end)) { days.add(getHourCountsForDay(name, cursor)); cursor = cursor.plus(step); } counts = MetricUtils.concatArrays(days, interval.getStart().getHourOfDay(), interval.toPeriod().toStandardHours().getHours() + 1); } else if (resolution == AggregateCountResolution.day) { DateTime startDay = new DateTime(c.dayOfYear().roundFloor(interval.getStart().getMillis())); DateTime endDay = new DateTime(c.dayOfYear().roundFloor(end.plusDays(1).getMillis())); int nDays = Days.daysBetween(startDay, endDay).getDays(); DateTime cursor = new DateTime(c.monthOfYear().roundFloor(interval.getStart().getMillis())); List<long[]> months = new ArrayList<long[]>(); DateTime endMonth = new DateTime( c.monthOfYear().roundCeiling(interval.getEnd().plusMonths(1).getMillis())); while (cursor.isBefore(endMonth)) { months.add(getDayCountsForMonth(name, cursor)); cursor = cursor.plusMonths(1); } counts = MetricUtils.concatArrays(months, interval.getStart().getDayOfMonth() - 1, nDays); } else if (resolution == AggregateCountResolution.month) { DateTime startMonth = new DateTime(c.monthOfYear().roundFloor(interval.getStartMillis())); DateTime endMonth = new DateTime(c.monthOfYear().roundFloor(end.plusMonths(1).getMillis())); int nMonths = Months.monthsBetween(startMonth, endMonth).getMonths(); DateTime cursor = new DateTime(c.year().roundFloor(interval.getStartMillis())); List<long[]> years = new ArrayList<long[]>(); DateTime endYear = new DateTime(c.year().roundCeiling(interval.getEnd().plusYears(1).getMillis())); while (cursor.isBefore(endYear)) { years.add(getMonthCountsForYear(name, cursor)); cursor = cursor.plusYears(1); } counts = MetricUtils.concatArrays(years, interval.getStart().getMonthOfYear() - 1, nMonths); } else if (resolution == AggregateCountResolution.year) { DateTime startYear = new DateTime(interval.getStart().getYear(), 1, 1, 0, 0); DateTime endYear = new DateTime(end.getYear() + 1, 1, 1, 0, 0); int nYears = Years.yearsBetween(startYear, endYear).getYears(); Map<String, Long> yearCounts = getYearCounts(name); counts = new long[nYears]; for (int i = 0; i < nYears; i++) { int year = startYear.plusYears(i).getYear(); Long count = yearCounts.get(Integer.toString(year)); if (count == null) { count = 0L; } counts[i] = count; } } else { throw new IllegalStateException("Shouldn't happen. Unhandled resolution: " + resolution); } return new AggregateCount(name, interval, counts, resolution); }
From source file:pt.ist.fenixedu.contracts.domain.personnelSection.contracts.PersonProfessionalData.java
License:Open Source License
public static boolean isTeacherActiveForSemester(Teacher teacher, ExecutionSemester executionSemester) { int minimumWorkingDays = 90; int activeDays = 0; Interval semesterInterval = new Interval( executionSemester.getBeginDateYearMonthDay().toLocalDate().toDateTimeAtStartOfDay(), executionSemester.getEndDateYearMonthDay().toLocalDate().toDateTimeAtStartOfDay()); PersonProfessionalData personProfessionalData = teacher.getPerson().getPersonProfessionalData(); if (personProfessionalData != null) { GiafProfessionalData giafProfessionalData = personProfessionalData.getGiafProfessionalData(); if (giafProfessionalData != null) { for (final PersonContractSituation situation : giafProfessionalData .getValidPersonContractSituations()) { if (situation.overlaps(semesterInterval) && situation.getProfessionalCategory() != null && situation.getProfessionalCategory().getCategoryType().equals(CategoryType.TEACHER)) { LocalDate beginDate = situation.getBeginDate() .isBefore(semesterInterval.getStart().toLocalDate()) ? semesterInterval.getStart().toLocalDate() : situation.getBeginDate(); LocalDate endDate = situation.getEndDate() == null || situation.getEndDate().isAfter(semesterInterval.getEnd().toLocalDate()) ? semesterInterval.getEnd().toLocalDate() : situation.getEndDate(); int days = new Interval(beginDate.toDateTimeAtStartOfDay(), endDate.toDateTimeAtStartOfDay()).toPeriod(PeriodType.days()).getDays() + 1; activeDays = activeDays + days; }//from w ww .ja v a 2s . c om } } } return activeDays >= minimumWorkingDays; }
From source file:pt.ist.fenixedu.contracts.tasks.UpdateTeacherAuthorizations.java
License:Open Source License
private int getActiveDays(PersonContractSituation situation, Interval semesterInterval) { LocalDate beginDate = situation.getBeginDate().isBefore(semesterInterval.getStart().toLocalDate()) ? semesterInterval.getStart().toLocalDate() : situation.getBeginDate();/*from w w w . j av a 2 s . co m*/ LocalDate endDate = situation.getEndDate() == null || situation.getEndDate().isAfter(semesterInterval.getEnd().toLocalDate()) ? semesterInterval.getEnd().toLocalDate() : situation.getEndDate(); int activeDays = new Interval(beginDate.toDateTimeAtStartOfDay(), endDate.toDateTimeAtStartOfDay()) .toPeriod(PeriodType.days()).getDays() + 1; return activeDays; }
From source file:pt.ist.fenixedu.contracts.tasks.UpdateTeacherAuthorizations.java
License:Open Source License
private Department getDominantDepartment(Person person, ExecutionSemester semester) { SortedSet<EmployeeContract> contracts = new TreeSet<EmployeeContract>(new Comparator<EmployeeContract>() { @Override/*from w w w . jav a 2 s . c o m*/ public int compare(EmployeeContract ec1, EmployeeContract ec2) { int compare = ec1.getBeginDate().compareTo(ec2.getBeginDate()); return compare == 0 ? ec1.getExternalId().compareTo(ec2.getExternalId()) : compare; } }); Interval semesterInterval = semester.getAcademicInterval().toInterval(); contracts.addAll(((Collection<EmployeeContract>) person .getParentAccountabilities(AccountabilityTypeEnum.WORKING_CONTRACT, EmployeeContract.class)) .stream() .filter(ec -> ec.belongsToPeriod(semesterInterval.getStart().toYearMonthDay(), semesterInterval.getEnd().toYearMonthDay())) .filter(Objects::nonNull).collect(Collectors.toSet())); Department firstDepartmentUnit = null; for (EmployeeContract employeeContract : contracts) { Department employeeDepartmentUnit = getEmployeeDepartmentUnit(employeeContract.getUnit()); if (employeeDepartmentUnit != null) { Interval contractInterval = new Interval( employeeContract.getBeginDate().toLocalDate().toDateTimeAtStartOfDay(), employeeContract.getEndDate() == null ? new DateTime(Long.MAX_VALUE) : employeeContract.getEndDate().toLocalDate().toDateTimeAtStartOfDay() .plusMillis(1)); Interval overlap = semesterInterval.overlap(contractInterval); int days = overlap.toPeriod(PeriodType.days()).getDays() + 1; if (days > minimumDaysForActivity) { return employeeDepartmentUnit; } if (firstDepartmentUnit == null) { firstDepartmentUnit = employeeDepartmentUnit; } } } return firstDepartmentUnit; }
From source file:pt.ist.fenixedu.teacher.domain.TeacherCredits.java
License:Open Source License
public static double calculateServiceExemptionCredits(Teacher teacher, ExecutionSemester executionSemester) { Set<PersonContractSituation> personProfessionalExemptions = PersonContractSituation .getValidTeacherServiceExemptions(teacher, executionSemester); Interval semesterInterval = new Interval( executionSemester.getBeginDateYearMonthDay().toLocalDate().toDateTimeAtStartOfDay(), executionSemester.getEndDateYearMonthDay().toLocalDate().toDateTimeAtStartOfDay()); int lessonsDays = semesterInterval.toPeriod(PeriodType.days()).getDays(); List<Interval> notYetOverlapedIntervals = new ArrayList<Interval>(); List<Interval> newIntervals = new ArrayList<Interval>(); notYetOverlapedIntervals.add(semesterInterval); Double mandatoryLessonHours = calculateMandatoryLessonHours(teacher, executionSemester); Double maxSneHours = mandatoryLessonHours; TeacherService teacherService = TeacherService.getTeacherServiceByExecutionPeriod(teacher, executionSemester);/*from w ww . j a v a 2s. c om*/ if (teacherService != null && teacherService.getReductionService() != null) { maxSneHours = Math.max(0, (mandatoryLessonHours - teacherService.getReductionServiceCredits().doubleValue())); } for (PersonContractSituation personContractSituation : personProfessionalExemptions) { LocalDate exemptionEnd = personContractSituation.getServiceExemptionEndDate() == null ? semesterInterval.getEnd().toLocalDate() : personContractSituation.getServiceExemptionEndDate(); Interval exemptionInterval = new Interval( personContractSituation.getBeginDate().toDateTimeAtStartOfDay(), exemptionEnd.toDateTimeAtStartOfDay()); PersonProfessionalExemption personProfessionalExemption = personContractSituation .getPersonProfessionalExemption(); if (personContractSituation.countForCredits(semesterInterval)) { if (personProfessionalExemption != null) { exemptionEnd = personProfessionalExemption.getEndDate() == null ? semesterInterval.getEnd().toLocalDate() : personProfessionalExemption.getEndDate(); exemptionInterval = new Interval( personProfessionalExemption.getBeginDate().toDateTimeAtStartOfDay(), exemptionEnd.toDateTimeAtStartOfDay()); if (personProfessionalExemption.getIsSabaticalOrEquivalent()) { if (isSabbaticalForSemester(teacher, exemptionInterval, semesterInterval)) { return maxSneHours; } else { continue; } } } for (Interval notYetOverlapedInterval : notYetOverlapedIntervals) { Interval overlapInterval = exemptionInterval.overlap(notYetOverlapedInterval); if (overlapInterval != null) { newIntervals.addAll(getNotOverlapedIntervals(overlapInterval, notYetOverlapedInterval)); } else { newIntervals.add(notYetOverlapedInterval); } } notYetOverlapedIntervals.clear(); notYetOverlapedIntervals.addAll(newIntervals); newIntervals.clear(); } } int notOverlapedDays = 0; for (Interval interval : notYetOverlapedIntervals) { notOverlapedDays += interval.toPeriod(PeriodType.days()).getDays(); } int overlapedDays = lessonsDays - notOverlapedDays; Double overlapedPercentage = round(Double.valueOf(overlapedDays) / Double.valueOf(lessonsDays)); return round(overlapedPercentage * maxSneHours); }
From source file:pt.ist.fenixedu.teacher.domain.TeacherCredits.java
License:Open Source License
private static List<Interval> getNotOverlapedIntervals(Interval overlapInterval, Interval notYetOverlapedInterval) { List<Interval> intervals = new ArrayList<Interval>(); LocalDate overlapIntervalStart = overlapInterval.getStart().toLocalDate(); LocalDate overlapIntervalEnd = overlapInterval.getEnd().toLocalDate(); LocalDate notYetOverlapedIntervalStart = notYetOverlapedInterval.getStart().toLocalDate(); LocalDate notYetOverlapedIntervalEnd = notYetOverlapedInterval.getEnd().toLocalDate(); if (overlapIntervalStart.equals(notYetOverlapedIntervalStart) && !overlapIntervalEnd.equals(notYetOverlapedIntervalEnd)) { intervals.add(new Interval(overlapInterval.getEnd().plusDays(1), notYetOverlapedInterval.getEnd())); } else if (!overlapIntervalStart.equals(notYetOverlapedIntervalStart) && overlapIntervalEnd.equals(notYetOverlapedIntervalEnd)) { intervals/* w ww .java2s .c om*/ .add(new Interval(notYetOverlapedInterval.getStart(), overlapInterval.getStart().minusDays(1))); } else if (!overlapIntervalStart.equals(notYetOverlapedIntervalStart) && !overlapIntervalEnd.equals(notYetOverlapedIntervalEnd)) { intervals .add(new Interval(notYetOverlapedInterval.getStart(), overlapInterval.getStart().minusDays(1))); intervals.add(new Interval(overlapInterval.getEnd().plusDays(1), notYetOverlapedInterval.getEnd())); } return intervals; }
From source file:supply.CapacityHarvester.java
License:Apache License
public static int getCalculatedRemainingHours(String username) { // Find start and end date for current sprint // --> Lookup sprint setup // Business days To Sprint End DateTime sprintStartDate = new DateTime(2014, 02, 1, 0, 0, 0, 0); DateTime sprintEndDate = new DateTime(2014, 02, 28, 17, 0); logger.info("sprintEndDate WeekOfWeekyear=" + sprintEndDate.getWeekOfWeekyear()); logger.info("sprintEndDate WeekOfWeekyear=" + sprintEndDate.getWeekOfWeekyear()); LocalDate today = new LocalDate(); // business days left in current week logger.info("Current week=" + today.getWeekOfWeekyear()); if (today.getDayOfWeek() > 5) { logger.info("Not a business day. 0 hours left of availability as this is weekend."); }/*from ww w .j ava 2 s . c o m*/ SimpleDateFormat df = new SimpleDateFormat("dd.MM.yyyy"); Period weekPeriod = new Period().withWeeks(1); Interval i = new Interval(sprintStartDate, weekPeriod); int hours = 0; while (i.getEnd().isBefore(sprintEndDate)) { logger.info("week: " + i.getStart().getWeekOfWeekyear() + " start: " + df.format(i.getStart().toDate()) + " end: " + df.format(i.getEnd().minusMillis(1).toDate())); i = new Interval(i.getStart().plus(weekPeriod), weekPeriod); int availabilityHours = Availability.getAvailability(i.getStart().toCalendar(Locale.US), username); logger.info("Reported availability hours for [" + username + "]: " + availabilityHours); hours += availabilityHours; } Days days = Days.daysBetween(today.toDateTimeAtStartOfDay(), sprintEndDate); int hoursRemaining = Hours.hoursBetween(today.toDateTimeAtCurrentTime(), sprintEndDate).getHours(); if (hoursRemaining < 0) hoursRemaining = 0; logger.info("HoursToSprintEnd=" + hoursRemaining); logger.info("DayOfWeek=" + today.getDayOfWeek()); logger.info("WeekOfWeekyear=" + today.getWeekOfWeekyear()); logger.info("Hours from DB=" + hours); // --> Find week numbers // --> Check that current date is between start/end date of sprint // Lookup how many hours this user has for the sprint // --> lookup in HBase // --> return hoursRemaining; }
From source file:TVShowTimelineMaker.util.XML.IntervalXMLWriter.java
@Override public Element writeElements(Interval ObjectToWrite) { Element newElement = new Element("Interval"); XMLWriter<DateTime> DateTimeWriter = XMLWriterImp.getXMLWriter(DateTime.class); Element startElement = new Element("startTime"); startElement.addContent(DateTimeWriter.writeElements(ObjectToWrite.getStart())); newElement.addContent(startElement); Element endElement = new Element("endTime"); endElement.addContent(DateTimeWriter.writeElements(ObjectToWrite.getEnd())); newElement.addContent(endElement);//from w w w . j a v a2 s . co m return newElement; }