Skip to content
This repository was archived by the owner on Jun 9, 2025. It is now read-only.

Commit 76e30b7

Browse files
rfc2822ArnyminerZsunkup
authored
Ignore RDATEs when there's an also an infinite RRULE to avoid calendar provider exception (#114)
* Ignore RDATEs when there's an also an infinite RRULE to avoid calendar provider exception * Added test Signed-off-by: Arnau Mora <[email protected]> * Tighten test intention * Remove unused import directive --------- Signed-off-by: Arnau Mora <[email protected]> Co-authored-by: Arnau Mora <[email protected]> Co-authored-by: Sunik Kupfer <[email protected]>
1 parent dd0ac1f commit 76e30b7

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

lib/src/androidTest/kotlin/at/bitfire/ical4android/AndroidEventTest.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,21 @@ class AndroidEventTest {
264264
assertEquals("${tzShanghai.id};20200601T123000,20200701T183000,20200702T183000,20200801T123000,20200802T123000", values.getAsString(Events.RDATE))
265265
}
266266

267+
@Test
268+
fun testBuildEvent_NonAllDay_DtEnd_NoDuration_Recurring_InfiniteRruleAndRdate() {
269+
val values = buildEvent(false) {
270+
dtStart = DtStart("20200601T123000", tzShanghai)
271+
dtEnd = DtEnd("20200601T123000", tzVienna)
272+
rRules += RRule(
273+
Recur("FREQ=DAILY;INTERVAL=2")
274+
)
275+
rDates += RDate(DateList("20200701T123000,20200702T123000", Value.DATE_TIME, tzVienna))
276+
}
277+
278+
assertNull(values.get(Events.RDATE))
279+
assertEquals("FREQ=DAILY;INTERVAL=2", values.get(Events.RRULE))
280+
}
281+
267282
@Test
268283
fun testBuildEvent_NonAllDay_DtEnd_Duration_NonRecurring() {
269284
val values = buildEvent(false) {

lib/src/main/kotlin/at/bitfire/ical4android/AndroidEvent.kt

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -791,15 +791,25 @@ abstract class AndroidEvent(
791791
builder.withValue(Events.RRULE, null)
792792

793793
if (event.rDates.isNotEmpty()) {
794-
for (rDate in event.rDates)
795-
AndroidTimeUtils.androidifyTimeZone(rDate)
794+
// ignore RDATEs when there's also an infinite RRULE [https://issuetracker.google.com/issues/216374004]
795+
val infiniteRrule = event.rRules.any { rRule ->
796+
rRule.recur.count == -1 && // no COUNT AND
797+
rRule.recur.until == null // no UNTIL
798+
}
799+
800+
if (infiniteRrule)
801+
Ical4Android.log.warning("Android can't handle infinite RRULE + RDATE [https://issuetracker.google.com/issues/216374004]; ignoring RDATE(s)")
802+
else {
803+
for (rDate in event.rDates)
804+
AndroidTimeUtils.androidifyTimeZone(rDate)
796805

797-
// Calendar provider drops DTSTART instance when using RDATE [https://code.google.com/p/android/issues/detail?id=171292]
798-
val listWithDtStart = DateList()
799-
listWithDtStart.add(dtStart.date)
800-
event.rDates.addFirst(RDate(listWithDtStart))
806+
// Calendar provider drops DTSTART instance when using RDATE [https://code.google.com/p/android/issues/detail?id=171292]
807+
val listWithDtStart = DateList()
808+
listWithDtStart.add(dtStart.date)
809+
event.rDates.addFirst(RDate(listWithDtStart))
801810

802-
builder.withValue(Events.RDATE, AndroidTimeUtils.recurrenceSetsToAndroidString(event.rDates, allDay))
811+
builder.withValue(Events.RDATE, AndroidTimeUtils.recurrenceSetsToAndroidString(event.rDates, allDay))
812+
}
803813
} else
804814
builder.withValue(Events.RDATE, null)
805815

0 commit comments

Comments
 (0)