Skip to content

Problem using RDate with LocalDate #764

@alexweirig

Description

@alexweirig

Describe the bug
I'm trying to create an RDate rule with LocalDate (s), e.g.

RDATE;VALUE=DATE:20241226,20241228

The sample event should have following rules:
RRULE:FREQ=DAILY;INTERVAL=2;UNTIL=20241231;WKST=MO
EXDATE;VALUE=DATE:20241225,20241227
RDATE;VALUE=DATE:20241226,20241228

When I use the calculateRecurrenceSet I get an Exception:
Exception in thread "main" java.time.DateTimeException: Unable to obtain Instant from TemporalAccessor: 2024-12-28 of type java.time.LocalDate

This gets thrown by the
Instant.class
and the method
public static Instant from(TemporalAccessor temporal) {

This method is called by the
Period.class:
and the method
private PeriodList subtractInterval(Period period)

in the line:
var thatInterval = TemporalAdapter.isFloating(getStart())
? period.toInterval(TimeZones.getDefault().toZoneId()) : period.toInterval();

My understanding is that period.toInterval() is not working if period is a LocalDate.
I think this should be something like:
Instant instant = period.atStartOfDay().toInstant(TimeZones.getDefault().toZoneId());

Or am I missing something?

If you set the RDATE to 20241226T000000Z,20241228T000000Z

it works fine ... but then why are DATE values supported?

BTW: There is no issue with EXDATE

Here's my sample code:
VEvent vEvent = new VEvent(LocalDate.of(2024, 12, 21), "Test");
RRule rrule = new RRule("FREQ=DAILY;INTERVAL=2;UNTIL=20241231;WKST=MO");

	ExDate<LocalDate> exdate = new ExDate<LocalDate>("20241225,20241227");
	exdate.add(new Value("DATE"));

	RDate<LocalDate> rdate = new RDate<>();
	rdate.add(new Value("DATE"));
	rdate.setValue("20241226,20241228");
	
	vEvent.add(rrule);
	vEvent.add(rdate);
	vEvent.add(exdate);
	
	Period<LocalDate> period = new Period<LocalDate>(LocalDate.of(2024, 12, 10), LocalDate.of(2025, 1, 10));
	Set<Period<LocalDate>> calculateRecurrenceSet = vEvent.calculateRecurrenceSet(period);
	
	for (Period<LocalDate> p : calculateRecurrenceSet) {
		System.out.println(p.getStart() + " " + p.getEnd());
	}

Expected behavior
The result I would expect is:
2024-12-21 2024-12-21
2024-12-23 2024-12-23
2024-12-26T00:00Z 2024-12-26T00:00Z
2024-12-28T00:00Z 2024-12-28T00:00Z
2024-12-29 2024-12-29
2024-12-31 2024-12-31

Environment (please complete the following information):

  • OS: WIndows 10
  • Java Version 23
  • iCal4j Version 4.0.7

All the best for 2025 and thank you very much for the great library.

Thank you very much in advance for your feedback

Alex

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions