Example usage for java.time.temporal Temporal plus

List of usage examples for java.time.temporal Temporal plus

Introduction

In this page you can find the example usage for java.time.temporal Temporal plus.

Prototype

Temporal plus(long amountToAdd, TemporalUnit unit);

Source Link

Document

Returns an object of the same type as this object with the specified period added.

Usage

From source file:org.silverpeas.core.calendar.ical4j.ICal4JImporter.java

private CalendarEventOccurrence occurrenceFromICalEvent(final Mutable<ZoneId> zoneId, final CalendarEvent event,
        final VEvent vEvent) {
    // The original start date
    Temporal originalStartDate = iCal4JDateCodec.decode(vEvent.getRecurrenceId().getDate(), zoneId.get());
    // The occurrence
    CalendarEventOccurrence occurrence = CalendarEventOccurrenceBuilder.forEvent(event)
            .startingAt(originalStartDate).endingAt(originalStartDate.plus(1, ChronoUnit.DAYS)).build();
    // The period
    occurrence.setPeriod(extractPeriod(zoneId, vEvent));
    // Component data
    copyICalEventToComponent(vEvent, occurrence.asCalendarComponent());
    return occurrence;
}

From source file:org.silverpeas.core.calendar.ical4j.ICal4JImporter.java

private Period extractPeriod(final Mutable<ZoneId> zoneId, final VEvent vEvent) {
    final Date startDate = vEvent.getStartDate().getDate();
    Date endDate = vEvent.getEndDate().getDate();
    if (endDate == null && !(startDate instanceof DateTime)) {
        endDate = startDate;/*from   ww  w . j  a  v  a2  s.c  om*/
    }
    Temporal startTemporal = iCal4JDateCodec.decode(startDate, zoneId.get());
    Temporal endTemporal = iCal4JDateCodec.decode(endDate, zoneId.get());
    if (endTemporal instanceof OffsetDateTime && startTemporal.equals(endTemporal)) {
        endTemporal = endTemporal.plus(1, ChronoUnit.HOURS);
    }
    return Period.between(startTemporal, endTemporal);
}

From source file:org.silverpeas.core.calendar.Recurrence.java

private Temporal computeEndDate() {
    Temporal date = this.getStartDate();
    if (getRecurrenceCount() == 1) {
        return date;
    }//  w ww.  j  ava 2 s  . c  o  m
    final long interval = (long) getRecurrenceCount()
            * (getFrequency().getInterval() >= 1 ? getFrequency().getInterval() : 1);
    date = date.plus(interval, getFrequency().getUnit().toChronoUnit());
    boolean firstDayOfWeekSet = false;
    for (DayOfWeekOccurrence dayOfWeek : daysOfWeek) {
        Temporal current = date.with(dayOfWeek.dayOfWeek());
        if (getFrequency().isMonthly()) {
            current = computeDateForMonthlyFrequencyFrom(current, dayOfWeek);
        } else if (getFrequency().isYearly()) {
            current = computeDateForYearlyFrequencyFrom(current, dayOfWeek);
        }

        if (!firstDayOfWeekSet || LocalDate.from(current).isAfter(LocalDate.from(date))) {
            date = current;
            firstDayOfWeekSet = true;
        }
    }
    return date;
}