2

Using the iCal4j library, I can create all occurrences of a recurrence starting with a rrule and a start date.

This code works fine, but the problem comes up when I create a recurrence that starts during DST and ends with standard time or vice versa.

Can iCal4j handle daylight saving time? How?

    private String rrule;
    private Date dtStart;
    private Date until;

public ArrayList<Event> createRecurEventList() throws Exception {

        ArrayList<Event> eventsList = new ArrayList<>();

        RRule iCalRRule = new RRule(rrule);
        DateTime dateTimeStart = new DateTime(dtStart);
        DateTime untilDate = (DateTime) iCalRRule.getRecur().getUntil();

        DtStart dtStartProp = new DtStart(dateTimeStart);
        Duration durationProp = new Duration(java.time.Duration.ofMinutes(eventsDuration));

        VEvent vEvent = new VEvent();

        vEvent.getProperties().add(dtStartProp);
        vEvent.getProperties().add(durationProp);
        vEvent.getProperties().add(iCalRRule);

        Period period = new Period(dateTimeStart, untilDate);

        PeriodList periods = vEvent.calculateRecurrenceSet(period);
        for (Period p : periods) {
            Event event = new ELEvent(ownerId, calId, expId);
            event.setDtStart(p.getStart());
            event.setDtEnd(p.getEnd());
            event.setDuration(p.getDuration().get(ChronoUnit.SECONDS));
            eventsList.add(elEvent);
        }

        return elEventsList;
    }
Luyi
  • 148
  • 1
  • 11

0 Answers0