List of usage examples for org.joda.time Interval getStart
public DateTime getStart()
From source file:pt.ist.fenix.task.exportData.santanderCardGeneration.CreateAndInitializeExecutionCourses.java
License:Open Source License
protected List<Interval> generateEventSpaceOccupationIntervals(YearMonthDay begin, final YearMonthDay end, final HourMinuteSecond beginTime, final HourMinuteSecond endTime, final DiaSemana diaSemana, final FrequencyType frequency) { final YearMonthDay startDateToSearch = begin; final YearMonthDay endDateToSearch = end; List<Interval> result = new ArrayList<Interval>(); begin = getBeginDateInSpecificWeekDay(diaSemana, begin); if (frequency == null) { if (!begin.isAfter(end) && (startDateToSearch == null || (!end.isBefore(startDateToSearch) && !begin.isAfter(endDateToSearch)))) { result.add(createNewInterval(begin, end, beginTime, endTime)); return result; }/*w w w .j ava 2 s .co m*/ } else { int numberOfDaysToSum = frequency.getNumberOfDays(); while (true) { if (begin.isAfter(end)) { break; } if (startDateToSearch == null || (!begin.isBefore(startDateToSearch) && !begin.isAfter(endDateToSearch))) { Interval interval = createNewInterval(begin, begin, beginTime, endTime); if (!frequency.equals(FrequencyType.DAILY) || ((false || interval.getStart().getDayOfWeek() != SATURDAY_IN_JODA_TIME) && (false || interval.getStart().getDayOfWeek() != SUNDAY_IN_JODA_TIME))) { result.add(interval); } } begin = begin.plusDays(numberOfDaysToSum); } } return result; }
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; }/*w w w . j av a 2s. c o m*/ } } } 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 ww w .j a v a 2 s . c om 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/*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
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//from w w w. ja va 2 s. com .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:pt.ist.fenixedu.teacher.domain.TeacherCredits.java
License:Open Source License
private static boolean isSabbaticalForSemester(Teacher teacher, Interval exemptionInterval, Interval semesterPeriod) {/*from w w w .j a v a 2 s.c o m*/ double overlapPercentageThisSemester = calculateLessonsIntervalAndExemptionOverlapPercentage(semesterPeriod, exemptionInterval); if (overlapPercentageThisSemester == 1) { return true; } if (semesterPeriod.contains(exemptionInterval.getStart())) { return overlapPercentageThisSemester >= 0.5; } ExecutionSemester firstExecutionPeriod = ExecutionSemester.readByDateTime(exemptionInterval.getStart()); Interval firstExecutionPeriodInterval = new Interval( firstExecutionPeriod.getBeginDateYearMonthDay().toLocalDate().toDateTimeAtStartOfDay(), firstExecutionPeriod.getEndDateYearMonthDay().toLocalDate().toDateTimeAtStartOfDay()); double overlapPercentageFirstSemester = calculateLessonsIntervalAndExemptionOverlapPercentage( firstExecutionPeriodInterval, exemptionInterval); return overlapPercentageFirstSemester < 0.5; }
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."); }/* w ww .ja v a2 s.co 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:syncthing.android.service.ServiceSettings.java
License:Open Source License
static long getNextNextStartTimeFor(long start, long end) { DateTime now = DateTime.now();//from w w w. j a va 2 s . c o m Interval interval = SyncthingUtils.getIntervalForRange(now, start, end); if (interval.isAfter(now)) { //Interval hasnt started yet return interval.getStartMillis(); } else { //were either inside the interval or past it, get the next days start //XXX we count inside interval as next day so if user // explicitly shuts us down we dont just start again return interval.getStart().plusDays(1).getMillis(); } }
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);/*w w w .j a v a 2 s . c o m*/ return newElement; }
From source file:windows.Recursos.java
/** * Este metodo se encarga de buscar todas las semnas en el ao actual * * @return numero de semanas/* ww w.j av a 2 s . c om*/ */ public static int generateWeeks() { // SimpleDateFormat df = new SimpleDateFormat("dd.MM.yyyy"); DateTime d = new DateTime(); Period weekPeriod = new Period().withWeeks(1); DateTime startDate = new DateTime(d.getYear(), 1, 1, 0, 0, 0, 0); while (startDate.getDayOfWeek() != DateTimeConstants.MONDAY) { startDate = startDate.plusDays(1); } DateTime endDate = new DateTime(d.getYear() + 1, 1, 1, 0, 0, 0, 0); Interval i = new Interval(startDate, weekPeriod); int ct = 0; while (i.getStart().isBefore(endDate)) { i = new Interval(i.getStart().plus(weekPeriod), weekPeriod); ct++; } return ct; }