Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import net.fortuna.ical4j.model.ParameterList
import net.fortuna.ical4j.model.Property
import net.fortuna.ical4j.model.component.VEvent
import net.fortuna.ical4j.model.parameter.TzId
import net.fortuna.ical4j.model.parameter.Value
import net.fortuna.ical4j.model.property.ExDate
import net.fortuna.ical4j.model.property.ProdId
import net.fortuna.ical4j.model.property.RDate
Expand Down Expand Up @@ -166,7 +167,7 @@ class AndroidEventHandler(
// Return ExDate
return if (originalAllDay) {
// .. as date, without time
ExDate(DateList(LocalDate.from(date)))
ExDate(ParameterList(listOf(Value.DATE)), DateList(LocalDate.from(date)))
} else if (date is Instant) {
ExDate(DateList(date))
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import android.provider.CalendarContract.Events
import android.provider.CalendarContract.ExtendedProperties
import androidx.core.content.contentValuesOf
import at.bitfire.dateTimeValue
import at.bitfire.dateValue
import at.bitfire.synctools.icalendar.dtStart
import at.bitfire.synctools.icalendar.recurrenceId
import at.bitfire.synctools.storage.calendar.EventAndExceptions
import at.bitfire.synctools.storage.calendar.EventsContract
import at.bitfire.synctools.util.AndroidTimeUtils
import net.fortuna.ical4j.model.Parameter
import net.fortuna.ical4j.model.Property
import net.fortuna.ical4j.model.TimeZoneRegistryFactory
import net.fortuna.ical4j.model.parameter.Value
import net.fortuna.ical4j.model.property.DtStart
import net.fortuna.ical4j.model.property.ExDate
import net.fortuna.ical4j.model.property.ProdId
Expand Down Expand Up @@ -148,6 +150,43 @@ class AndroidEventHandlerTest {
assertTrue(result.exceptions.isEmpty())
}

@Test
fun `mapToVEvents rewrites cancelled all-day exception to EXDATE with VALUE=DATE`() {
val result = handler.mapToVEvents(
eventAndExceptions = EventAndExceptions(
main = Entity(contentValuesOf(
Events.TITLE to "Recurring all-day event with cancelled all-day exception",
Events.DTSTART to 1594056600000L,
Events.EVENT_TIMEZONE to "UTC",
Events.ALL_DAY to 1, // main event is all-day
Events.RRULE to "FREQ=DAILY;COUNT=10"
)),
exceptions = listOf(
Entity(contentValuesOf(
Events.ORIGINAL_INSTANCE_TIME to 1594143000000L,
Events.ORIGINAL_ALL_DAY to 1, // exception is all-day
Events.DTSTART to 1594143000000L,
Events.ALL_DAY to 1,
Events.EVENT_TIMEZONE to "UTC",
Events.STATUS to Events.STATUS_CANCELED
))
)
)
).associatedEvents
val main = result.main!!
assertEquals("Recurring all-day event with cancelled all-day exception", main.summary.value)
assertEquals("FREQ=DAILY;COUNT=10", main.getProperty<RRule<*>>(Property.RRULE).get().value)

// Check that EXDATE has VALUE=DATE
val exDate = main.getProperty<ExDate<*>>(Property.EXDATE).get()
assertEquals(Value.DATE, exDate.getParameter<Value>(Parameter.VALUE).get())
assertEquals(
dateValue("20200707"),
main.getProperty<ExDate<*>>(Property.EXDATE)?.getOrNull()?.dates?.first()
)
assertTrue(result.exceptions.isEmpty())
}

@Test
fun `mapToVEvents rewrites cancelled exception using UTC to EXDATE`() {
val result = handler.mapToVEvents(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import at.bitfire.dateValue
import io.mockk.mockk
import junit.framework.TestCase.assertEquals
import net.fortuna.ical4j.model.DateList
import net.fortuna.ical4j.model.Parameter
import net.fortuna.ical4j.model.ParameterList
import net.fortuna.ical4j.model.Property
import net.fortuna.ical4j.model.Recur
Expand Down Expand Up @@ -132,10 +133,10 @@ class RecurrenceFieldHandlerTest {
"FREQ=WEEKLY;COUNT=1",
result.getProperties<ExRule<Temporal>>(Property.EXRULE).joinToString { it.value }
)
assertEquals(
"20260201",
result.getProperties<ExDate<Temporal>>(Property.EXDATE).joinToString { it.value }
)
// All-day EXDATE must have VALUE=DATE
val exDates = result.getProperties<ExDate<Temporal>>(Property.EXDATE)
assertEquals(Value.DATE, exDates.first().getParameter<Value>(Parameter.VALUE).get())
assertEquals("20260201", exDates.joinToString { it.value })
}

@Test
Expand Down
Loading