Skip to content

Commit

Permalink
Ignore RDATEs when there's an also an infinite RRULE to avoid calenda…
Browse files Browse the repository at this point in the history
…r 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 <arnyminerz@proton.me>

* Tighten test intention

* Remove unused import directive

---------

Signed-off-by: Arnau Mora <arnyminerz@proton.me>
Co-authored-by: Arnau Mora <arnyminerz@proton.me>
Co-authored-by: Sunik Kupfer <kupfer@bitfire.at>
  • Loading branch information
3 people authored Sep 12, 2023
1 parent dd0ac1f commit 76e30b7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,21 @@ class AndroidEventTest {
assertEquals("${tzShanghai.id};20200601T123000,20200701T183000,20200702T183000,20200801T123000,20200802T123000", values.getAsString(Events.RDATE))
}

@Test
fun testBuildEvent_NonAllDay_DtEnd_NoDuration_Recurring_InfiniteRruleAndRdate() {
val values = buildEvent(false) {
dtStart = DtStart("20200601T123000", tzShanghai)
dtEnd = DtEnd("20200601T123000", tzVienna)
rRules += RRule(
Recur("FREQ=DAILY;INTERVAL=2")
)
rDates += RDate(DateList("20200701T123000,20200702T123000", Value.DATE_TIME, tzVienna))
}

assertNull(values.get(Events.RDATE))
assertEquals("FREQ=DAILY;INTERVAL=2", values.get(Events.RRULE))
}

@Test
fun testBuildEvent_NonAllDay_DtEnd_Duration_NonRecurring() {
val values = buildEvent(false) {
Expand Down
24 changes: 17 additions & 7 deletions lib/src/main/kotlin/at/bitfire/ical4android/AndroidEvent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -791,15 +791,25 @@ abstract class AndroidEvent(
builder.withValue(Events.RRULE, null)

if (event.rDates.isNotEmpty()) {
for (rDate in event.rDates)
AndroidTimeUtils.androidifyTimeZone(rDate)
// ignore RDATEs when there's also an infinite RRULE [https://issuetracker.google.com/issues/216374004]
val infiniteRrule = event.rRules.any { rRule ->
rRule.recur.count == -1 && // no COUNT AND
rRule.recur.until == null // no UNTIL
}

if (infiniteRrule)
Ical4Android.log.warning("Android can't handle infinite RRULE + RDATE [https://issuetracker.google.com/issues/216374004]; ignoring RDATE(s)")
else {
for (rDate in event.rDates)
AndroidTimeUtils.androidifyTimeZone(rDate)

// Calendar provider drops DTSTART instance when using RDATE [https://code.google.com/p/android/issues/detail?id=171292]
val listWithDtStart = DateList()
listWithDtStart.add(dtStart.date)
event.rDates.addFirst(RDate(listWithDtStart))
// Calendar provider drops DTSTART instance when using RDATE [https://code.google.com/p/android/issues/detail?id=171292]
val listWithDtStart = DateList()
listWithDtStart.add(dtStart.date)
event.rDates.addFirst(RDate(listWithDtStart))

builder.withValue(Events.RDATE, AndroidTimeUtils.recurrenceSetsToAndroidString(event.rDates, allDay))
builder.withValue(Events.RDATE, AndroidTimeUtils.recurrenceSetsToAndroidString(event.rDates, allDay))
}
} else
builder.withValue(Events.RDATE, null)

Expand Down

0 comments on commit 76e30b7

Please sign in to comment.