Example usage for org.joda.time DateTime plusDays

List of usage examples for org.joda.time DateTime plusDays

Introduction

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

Prototype

public DateTime plusDays(int days) 

Source Link

Document

Returns a copy of this datetime plus the specified number of days.

Usage

From source file:org.fenixedu.academic.domain.vigilancy.VigilantWrapper.java

License:Open Source License

public UnavailableTypes getWhyIsUnavailabeFor(WrittenEvaluation writtenEvaluation) {
    DateTime begin = writtenEvaluation.getBeginningDateTime();
    DateTime end = writtenEvaluation.getEndDateTime();

    if (!this.isAvailableOnDate(begin, end)) {
        return UnavailableTypes.UNAVAILABLE_PERIOD;
    }//from w  ww  . j  a va  2  s. com
    if (!this.isAvailableInCampus(writtenEvaluation.getCampus())) {
        return UnavailableTypes.NOT_AVAILABLE_ON_CAMPUS;
    }
    if (!this.hasNoEvaluationsOnDate(begin, end)) {
        return UnavailableTypes.ALREADY_CONVOKED_FOR_ANOTHER_EVALUATION;
    }

    Teacher teacher = this.getPerson().getTeacher();
    if (teacher != null) {
        Set<PersonContractSituation> validTeacherServiceExemptions = PersonContractSituation
                .getValidTeacherServiceExemptions(teacher, new Interval(begin, end.plusDays(1)));
        if (!validTeacherServiceExemptions.isEmpty()) {
            return UnavailableTypes.SERVICE_EXEMPTION;
        }
    }

    if (teacher != null && teacher.hasLessons(begin, end)) {
        return UnavailableTypes.LESSON_AT_SAME_TIME;
    }

    Person person = Vigilancy.getIncompatibleVigilantPerson(this.getPerson());
    if (person != null) {
        Collection<Vigilancy> convokes = writtenEvaluation.getVigilanciesSet();
        for (Vigilancy convoke : convokes) {
            if (convoke.getVigilantWrapper().getPerson().equals(person)) {
                return UnavailableTypes.INCOMPATIBLE_PERSON;
            }
        }
    }

    return UnavailableTypes.UNKNOWN;

}

From source file:org.fenixedu.academic.ui.spring.service.AccountingReportService.java

License:Open Source License

private boolean isFor(AccountingTransactionDetail atd, DateTime start, DateTime end) {
    final DateTime whenRegistered = atd.getWhenRegistered();
    return new Interval(start, end.plusDays(1)).contains(whenRegistered);
}

From source file:org.fenixedu.academic.ui.struts.action.resourceAllocationManager.SearchOccupationsDA.java

License:Open Source License

@Atomic
public static Collection<SpaceOccupationEventBean> run(Space building, DateTime start, DateTime end,
        List<OccupationType> types) {
    final Set<SpaceOccupationEventBean> beans = new HashSet<SpaceOccupationEventBean>();
    end = end.plusDays(1);
    final Interval searchInterval = new Interval(start, end);
    for (Space space : getAllChildren(building)) {
        final Map<Occupation, Collection<Interval>> map = getEventSpaceOccupations(space, searchInterval)
                .asMap();/*from   w w  w  .  ja v a 2 s  . co m*/
        final Set<Occupation> spaceOccupations = map.keySet();
        if (spaceOccupations.isEmpty()) {
            continue;
        }
        for (Occupation occupation : spaceOccupations) {
            OccupationType occupationType = getType(occupation);
            if (!types.contains(occupationType)) {
                continue;
            }
            if (occupation instanceof WrittenEvaluationSpaceOccupation) {
                WrittenEvaluationSpaceOccupation evalOccupation = (WrittenEvaluationSpaceOccupation) occupation;
                for (WrittenEvaluation eval : evalOccupation.getWrittenEvaluationsSet()) {
                    final Interval durationInterval = eval.getDurationInterval();
                    if (searchInterval.overlaps(durationInterval)) {
                        String desc;
                        if (eval instanceof WrittenTest) {
                            desc = String.format("(%s) %s - %s", eval.getEvaluationType(), eval.getName(),
                                    ((WrittenTest) eval).getDescription());
                        } else {
                            desc = String.format("(%s) %s", eval.getEvaluationType(), eval.getName());
                        }
                        beans.add(new SpaceOccupationEventBean(space, durationInterval, desc, occupationType));
                    }
                }
            } else {
                final String desc = getPresentationString(occupation);
                for (Interval interval : map.get(occupation)) {
                    beans.add(new SpaceOccupationEventBean(space, interval, desc, occupationType));
                }
            }
        }
    }
    return beans;
}

From source file:org.fenixedu.spaces.domain.occupation.config.DailyConfig.java

License:Open Source License

@Override
public List<Interval> getIntervals() {
    List<Interval> intervals = new ArrayList<>();
    DateTime startDate = getInterval().getStart();
    DateTime endDate = getInterval().getEnd();
    DateTime start = startDate;
    while (start.isBefore(endDate) || start.isEqual(endDate)) {
        intervals.add(new Interval(start.withFields(getStartTime()), start.withFields(getEndTime())));
        start = start.plusDays(getRepeatsEvery());
    }// w  w w  . jav a  2 s.  c o  m
    return intervals;
}

From source file:org.filteredpush.qc.date.DateUtils.java

License:Apache License

/**
 * Given a string that may be a date or a date range, extract a interval of
 * dates from that date range, up to the end milisecond of the last day.
 * //from w  w w  .j  ava  2s .  c  o  m
 * @see DateUtils#extractDateInterval(String) which returns a pair of DateMidnights.
 * 
 * @param eventDate a string containing a dwc:eventDate from which to extract an interval.
 * @return an interval from the beginning of event date to the end of event date.
 */
public static Interval extractInterval(String eventDate) {
    Interval result = null;
    DateTimeParser[] parsers = { DateTimeFormat.forPattern("yyyy-MM").getParser(),
            DateTimeFormat.forPattern("yyyy").getParser(),
            ISODateTimeFormat.dateOptionalTimeParser().getParser() };
    DateTimeFormatter formatter = new DateTimeFormatterBuilder().append(null, parsers).toFormatter();
    if (eventDate != null && eventDate.contains("/") && isRange(eventDate)) {
        String[] dateBits = eventDate.split("/");
        try {
            // must be at least a 4 digit year.
            if (dateBits[0].length() > 3 && dateBits[1].length() > 3) {
                DateMidnight startDate = DateMidnight.parse(dateBits[0], formatter);
                DateTime endDate = DateTime.parse(dateBits[1], formatter);
                logger.debug(startDate);
                logger.debug(endDate);
                if (dateBits[1].length() == 4) {
                    result = new Interval(startDate, endDate.plusMonths(12).minus(1l));
                } else if (dateBits[1].length() == 7) {
                    result = new Interval(startDate, endDate.plusMonths(1).minus(1l));
                } else {
                    result = new Interval(startDate, endDate.plusDays(1).minus(1l));
                }
                logger.debug(result);
            }
        } catch (Exception e) {
            // not a date range
            logger.error(e.getMessage());
        }
    } else {
        try {
            DateMidnight startDate = DateMidnight.parse(eventDate, formatter);
            logger.debug(startDate);
            if (eventDate.length() == 4) {
                DateTime endDate = startDate.toDateTime().plusMonths(12).minus(1l);
                result = new Interval(startDate, endDate);
                logger.debug(result);
            } else if (eventDate.length() == 7) {
                DateTime endDate = startDate.toDateTime().plusMonths(1).minus(1l);
                result = new Interval(startDate, endDate);
                logger.debug(result);
            } else {
                DateTime endDate = startDate.toDateTime().plusDays(1).minus(1l);
                result = new Interval(startDate, endDate);
                logger.debug(result);
            }
        } catch (Exception e) {
            // not a date
            logger.error(e.getMessage());
        }
    }
    return result;
}

From source file:org.finra.datagenerator.engine.scxml.tags.boundary.BoundaryDate.java

License:Apache License

/**
 * @param isNullable isNullable//from w  ww.j  a  va 2 s  .c om
 * @param earliest   lower boundary date
 * @param latest     upper boundary date
 * @return a list of boundary dates
 */
public List<String> negativeCase(boolean isNullable, String earliest, String latest) {
    List<String> values = new LinkedList<>();

    DateTimeFormatter parser = ISODateTimeFormat.date();
    DateTime earlyDate = parser.parseDateTime(earliest);
    DateTime lateDate = parser.parseDateTime(latest);

    String prevDay = parser.print(earlyDate.minusDays(1));
    String nextDay = parser.print(lateDate.plusDays(1));

    values.add(prevDay);
    values.add(nextDay);
    values.add(nextDay.substring(5, 7) + "-" + nextDay.substring(8, 10) + "-" + nextDay.substring(0, 4));
    values.add(getRandomHoliday(earliest, latest));

    if (!isNullable) {
        values.add("");
    }
    return values;
}

From source file:org.finra.datagenerator.engine.scxml.tags.boundary.BoundaryDate.java

License:Apache License

/**
 * Given a year, month, and day, find the number of occurrences of that day in the month
 *
 * @param year  the year/*from w w  w  .  j  a v a2  s .  com*/
 * @param month the month
 * @param day   the day
 * @return the number of occurrences of the day in the month
 */
public int numOccurrences(int year, int month, int day) {
    DateTimeFormatter parser = ISODateTimeFormat.date();
    DateTime date = parser.parseDateTime(year + "-" + month + "-" + "01");
    Calendar cal = Calendar.getInstance();
    cal.setTime(date.toDate());
    GregorianChronology calendar = GregorianChronology.getInstance();
    DateTimeField field = calendar.dayOfMonth();

    int days = 0;
    int count = 0;
    int num = field.getMaximumValue(new LocalDate(year, month, day, calendar));
    while (days < num) {
        if (cal.get(Calendar.DAY_OF_WEEK) == day) {
            count++;
        }
        date = date.plusDays(1);
        cal.setTime(date.toDate());

        days++;
    }
    return count;
}

From source file:org.finra.datagenerator.engine.scxml.tags.boundary.BoundaryDate.java

License:Apache License

/**
 * Convert the holiday format from EquivalenceClassTransformer into a date format
 *
 * @param holiday the date/*from w w  w.  j ava2s  .c o m*/
 * @return a date String in the format yyyy-MM-dd
 */
public String convertToReadableDate(Holiday holiday) {
    DateTimeFormatter parser = ISODateTimeFormat.date();

    if (holiday.isInDateForm()) {
        String month = Integer.toString(holiday.getMonth()).length() < 2 ? "0" + holiday.getMonth()
                : Integer.toString(holiday.getMonth());
        String day = Integer.toString(holiday.getDayOfMonth()).length() < 2 ? "0" + holiday.getDayOfMonth()
                : Integer.toString(holiday.getDayOfMonth());
        return holiday.getYear() + "-" + month + "-" + day;
    } else {
        /*
         * 5 denotes the final occurrence of the day in the month. Need to find actual
         * number of occurrences
         */
        if (holiday.getOccurrence() == 5) {
            holiday.setOccurrence(
                    numOccurrences(holiday.getYear(), holiday.getMonth(), holiday.getDayOfWeek()));
        }

        DateTime date = parser.parseDateTime(holiday.getYear() + "-" + holiday.getMonth() + "-" + "01");
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date.toDate());
        int count = 0;

        while (count < holiday.getOccurrence()) {
            if (calendar.get(Calendar.DAY_OF_WEEK) == holiday.getDayOfWeek()) {
                count++;
                if (count == holiday.getOccurrence()) {
                    break;
                }
            }
            date = date.plusDays(1);
            calendar.setTime(date.toDate());
        }
        return date.toString().substring(0, 10);
    }
}

From source file:org.gephi.desktop.timeline.MinimalDrawer.java

License:Open Source License

private void paintUpperRulerForInterval(Graphics2D g2d, DateTime dtFrom, DateTime dtTo) {

    g2d.setFont(settings.graduations.font);
    g2d.setColor(settings.graduations.fontColor);
    int leftMargin = settings.graduations.leftMargin;
    int textTopPosition = settings.graduations.textTopPosition;
    int width = getWidth();
    int height = getHeight();
    // TODO take these from the model

    Interval interval = new Interval(dtFrom, dtTo);

    Period p = interval.toPeriod(PeriodType.days());
    // try to determine length if we had to show milliseconds

    int n = p.getDays();
    int unitSize = (int) (settings.graduations.fontMetrics.getStringBounds("wednesday  ", null)).getWidth();
    if (n < (width / unitSize)) {
        //System.out.println("jour");
        for (int i = 0; i < n; i++) {
            g2d.drawString(dtFrom.plusDays(i).dayOfWeek().getAsText(LOCALE), leftMargin + 2 + i * (width / n),
                    textTopPosition);/*w ww . j a v  a 2 s .c  o m*/
            g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n),
                    height - settings.graduations.textBottomMargin);
            paintSmallGraduations(g2d, leftMargin + i * (width / n), leftMargin + (i + 1) * (width / n),
                    Hours.hoursBetween(dtFrom.plusDays(i), dtFrom.plusDays(i + 1)).getHours());
        }
        return;
    }

    unitSize = (int) (settings.graduations.fontMetrics.getStringBounds("wed ", null)).getWidth();
    if (n < (width / unitSize)) {
        //System.out.println("jou");
        for (int i = 0; i < n; i++) {
            g2d.drawString(dtFrom.plusDays(i).dayOfWeek().getAsShortText(LOCALE),
                    leftMargin + 2 + i * (width / n), textTopPosition);
            g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n),
                    height - settings.graduations.textBottomMargin);

            paintSmallGraduations(g2d, leftMargin + i * (width / n), leftMargin + (i + 1) * (width / n),
                    Hours.hoursBetween(dtFrom.plusDays(i), dtFrom.plusDays(i + 1)).getHours());
        }
        return;
    }

    p = interval.toPeriod(PeriodType.days());
    n = p.getDays();
    unitSize = (int) (settings.graduations.fontMetrics.getStringBounds("30", null)).getWidth();
    if (n < (width / unitSize)) {
        //System.out.println("j");
        for (int i = 0; i < n; i++) {
            g2d.drawString("" + (dtFrom.getDayOfMonth() + i), leftMargin + 2 + i * (width / n),
                    textTopPosition);
            g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n),
                    height - settings.graduations.textBottomMargin);

            paintSmallGraduations(g2d, leftMargin + i * (width / n), leftMargin + (i + 1) * (width / n),
                    Hours.hoursBetween(dtFrom.plusDays(i), dtFrom.plusDays(i + 1)).getHours());
        }
        return;
    }

    p = interval.toPeriod(PeriodType.months());
    n = p.getMonths();
    unitSize = (int) (settings.graduations.fontMetrics.getStringBounds("September  ", null)).getWidth();
    if (n < (width / unitSize)) {
        //System.out.println("mois");
        for (int i = 0; i < n; i++) {
            g2d.drawString(dtFrom.plusMonths(i).monthOfYear().getAsText(LOCALE),
                    leftMargin + 2 + i * (width / n), textTopPosition);
            g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n),
                    height - settings.graduations.textBottomMargin);

            paintSmallGraduations(g2d, leftMargin + i * (width / n), leftMargin + (i + 1) * (width / n),
                    Days.daysBetween(dtFrom.plusMonths(i), dtFrom.plusMonths(i + 1)).getDays());
        }
        return;
    }

    unitSize = (int) (settings.graduations.fontMetrics.getStringBounds("dec ", null)).getWidth();
    if (n < (width / unitSize)) {
        //System.out.println("mo");
        for (int i = 0; i < n; i++) {
            g2d.drawString(dtFrom.plusMonths(i).monthOfYear().getAsShortText(LOCALE),
                    leftMargin + 2 + i * (width / n), textTopPosition);
            g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n),
                    height - settings.graduations.textBottomMargin);
            paintSmallGraduations(g2d, leftMargin + i * (width / n), leftMargin + (i + 1) * (width / n),
                    Days.daysBetween(dtFrom.plusMonths(i), dtFrom.plusMonths(i + 1)).getDays());
        }
        return;
    }

    unitSize = (int) (settings.graduations.fontMetrics.getStringBounds("29 ", null)).getWidth();
    if (n < (width / unitSize)) {
        //System.out.println("m");
        for (int i = 0; i < n; i++) {
            g2d.drawString("" + (dtFrom.getMonthOfYear() + i), leftMargin + 2 + i * (width / n),
                    textTopPosition);
            g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n),
                    height - settings.graduations.textBottomMargin);
            paintSmallGraduations(g2d, leftMargin + i * (width / n), leftMargin + (i + 1) * (width / n),
                    Days.daysBetween(dtFrom.plusMonths(i), dtFrom.plusMonths(i + 1)).getDays());
        }
        return;
    }

    p = interval.toPeriod(PeriodType.years());
    n = p.getYears();
    unitSize = (int) (settings.graduations.fontMetrics.getStringBounds("1980 ", null)).getWidth();
    if (n < (width / unitSize)) {
        //System.out.println("year");
        for (int i = 0; i < n; i++) {
            g2d.drawString("" + (dtFrom.getYear() + i), leftMargin + 2 + i * (width / n), textTopPosition);
            g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n),
                    height - settings.graduations.textBottomMargin);
            paintSmallGraduations(g2d, leftMargin + i * (width / n), leftMargin + (i + 1) * (width / n),
                    Months.monthsBetween(dtFrom.plusYears(i), dtFrom.plusYears(i + 1)).getMonths());
        }
        return;
    }

    int group = 10;
    n = p.getYears() / group;
    if (n < (width / unitSize)) {
        //System.out.println("10 years");
        for (int i = 0; i < n; i++) {
            g2d.drawString("" + (dtFrom.getYear() + i * group), leftMargin + 2 + i * (width / n),
                    textTopPosition);
            g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n),
                    height - settings.graduations.textBottomMargin);
            paintSmallGraduations(g2d, leftMargin + i * (width / n), leftMargin + (i + 1) * (width / n), Months
                    .monthsBetween(dtFrom.plusYears(i * group), dtFrom.plusYears((i + 1) * group)).getMonths());
        }
        return;
    }
    group = 20;
    n = p.getYears() / group;
    if (n < (width / unitSize)) {
        //System.out.println("20 years");
        for (int i = 0; i < n; i++) {
            g2d.drawString("" + (dtFrom.getYear() + i * group), leftMargin + 2 + i * (width / n),
                    textTopPosition);
            g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n),
                    height - settings.graduations.textBottomMargin);
            paintSmallGraduations(g2d, leftMargin + i * (width / n), leftMargin + (i + 1) * (width / n), Months
                    .monthsBetween(dtFrom.plusYears(i * group), dtFrom.plusYears((i + 1) * group)).getMonths());
        }
        return;
    }
    group = 50;
    n = p.getYears() / group;
    if (n < (width / unitSize)) {
        //System.out.println("50 years");
        for (int i = 0; i < n; i++) {
            g2d.drawString("" + (dtFrom.getYear() + i * group), leftMargin + 2 + i * (width / n),
                    textTopPosition);
            g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n),
                    height - settings.graduations.textBottomMargin);
            paintSmallGraduations(g2d, leftMargin + i * (width / n), leftMargin + (i + 1) * (width / n), Months
                    .monthsBetween(dtFrom.plusYears(i * group), dtFrom.plusYears((i + 1) * group)).getMonths());
        }
        return;
    }
    group = 100;
    n = p.getYears() / group;
    if (n / 100 < (width / unitSize)) {
        //System.out.println("100 years");
        for (int i = 0; i < n; i++) {
            g2d.drawString("" + (dtFrom.getYear() + i * group), leftMargin + 2 + i * (width / n),
                    textTopPosition);
            g2d.drawLine(leftMargin + i * (width / n), 2, leftMargin + i * (width / n),
                    height - settings.graduations.textBottomMargin);
            paintSmallGraduations(g2d, leftMargin + i * (width / n), leftMargin + (i + 1) * (width / n), Months
                    .monthsBetween(dtFrom.plusYears(i * group), dtFrom.plusYears((i + 1) * group)).getMonths());
        }
    }
    return;
}

From source file:org.glucosio.android.presenter.OverviewPresenter.java

License:Open Source License

private void addZeroReadings(final ArrayList<IntGraphObject> graphObjects, final DateTime firstDate,
        final DateTime lastDate) {
    int daysBetween = Days.daysBetween(firstDate, lastDate).getDays();
    for (int i = 1; i < daysBetween; i++) {
        graphObjects.add(new IntGraphObject(firstDate.plusDays(i), 0));
    }/*w  ww .  java2 s.  c  o m*/
}