diff --git a/lib/src/androidTest/kotlin/at/bitfire/ical4android/AndroidEventTest.kt b/lib/src/androidTest/kotlin/at/bitfire/ical4android/AndroidEventTest.kt index 976a08ec..d2725982 100644 --- a/lib/src/androidTest/kotlin/at/bitfire/ical4android/AndroidEventTest.kt +++ b/lib/src/androidTest/kotlin/at/bitfire/ical4android/AndroidEventTest.kt @@ -21,7 +21,6 @@ import androidx.core.content.contentValuesOf import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation import at.bitfire.ical4android.impl.TestCalendar import at.bitfire.ical4android.util.AndroidTimeUtils -import at.bitfire.ical4android.util.DateUtils import at.bitfire.ical4android.util.MiscUtils.asSyncAdapter import at.bitfire.ical4android.util.MiscUtils.closeCompat import at.bitfire.synctools.icalendar.Css3Color @@ -35,6 +34,7 @@ import net.fortuna.ical4j.model.Parameter import net.fortuna.ical4j.model.ParameterList import net.fortuna.ical4j.model.Property import net.fortuna.ical4j.model.Recur +import net.fortuna.ical4j.model.TimeZoneRegistryFactory import net.fortuna.ical4j.model.component.VAlarm import net.fortuna.ical4j.model.parameter.Cn import net.fortuna.ical4j.model.parameter.CuType @@ -74,11 +74,12 @@ class AndroidEventTest { private val testAccount = Account("ical4android@example.com", ACCOUNT_TYPE_LOCAL) - private val tzVienna = DateUtils.ical4jTimeZone("Europe/Vienna")!! - private val tzShanghai = DateUtils.ical4jTimeZone("Asia/Shanghai")!! + private val tzRegistry = TimeZoneRegistryFactory.getInstance().createRegistry()!! + private val tzVienna = tzRegistry.getTimeZone("Europe/Vienna")!! + private val tzShanghai = tzRegistry.getTimeZone("Asia/Shanghai")!! private val tzIdDefault = java.util.TimeZone.getDefault().id - private val tzDefault = DateUtils.ical4jTimeZone(tzIdDefault) + private val tzDefault = tzRegistry.getTimeZone(tzIdDefault) lateinit var client: ContentProviderClient private lateinit var calendar: AndroidCalendar diff --git a/lib/src/androidTest/kotlin/at/bitfire/ical4android/AndroidTimeZonesTest.kt b/lib/src/androidTest/kotlin/at/bitfire/ical4android/AndroidTimeZonesTest.kt index d16716a3..8c678a94 100644 --- a/lib/src/androidTest/kotlin/at/bitfire/ical4android/AndroidTimeZonesTest.kt +++ b/lib/src/androidTest/kotlin/at/bitfire/ical4android/AndroidTimeZonesTest.kt @@ -6,7 +6,7 @@ package at.bitfire.ical4android -import at.bitfire.ical4android.util.DateUtils +import net.fortuna.ical4j.model.TimeZoneRegistryFactory import org.junit.Assert import org.junit.Assert.assertNotNull import org.junit.Test @@ -18,10 +18,11 @@ class AndroidTimeZonesTest { @Test fun testLoadSystemTimezones() { + val tzRegistry = TimeZoneRegistryFactory.getInstance().createRegistry() for (id in ZoneId.getAvailableZoneIds()) { val name = ZoneId.of(id).getDisplayName(TextStyle.FULL, Locale.US) val info = try { - DateUtils.ical4jTimeZone(id) + tzRegistry.getTimeZone(id) } catch(e: Exception) { Assert.fail("Invalid system timezone $name ($id)") } diff --git a/lib/src/androidTest/kotlin/at/bitfire/ical4android/DmfsTaskTest.kt b/lib/src/androidTest/kotlin/at/bitfire/ical4android/DmfsTaskTest.kt index 50b6fc9b..d99dc660 100644 --- a/lib/src/androidTest/kotlin/at/bitfire/ical4android/DmfsTaskTest.kt +++ b/lib/src/androidTest/kotlin/at/bitfire/ical4android/DmfsTaskTest.kt @@ -13,11 +13,11 @@ import android.database.DatabaseUtils import android.net.Uri import at.bitfire.ical4android.impl.TestTask import at.bitfire.ical4android.impl.TestTaskList -import at.bitfire.ical4android.util.DateUtils import at.bitfire.synctools.storage.LocalStorageException import net.fortuna.ical4j.model.Date import net.fortuna.ical4j.model.DateList import net.fortuna.ical4j.model.DateTime +import net.fortuna.ical4j.model.TimeZoneRegistryFactory import net.fortuna.ical4j.model.component.VAlarm import net.fortuna.ical4j.model.parameter.Email import net.fortuna.ical4j.model.parameter.RelType @@ -58,9 +58,10 @@ class DmfsTaskTest( providerName: TaskProvider.ProviderName ): DmfsStyleProvidersTaskTest(providerName) { - private val tzVienna = DateUtils.ical4jTimeZone("Europe/Vienna")!! - private val tzChicago = DateUtils.ical4jTimeZone("America/Chicago")!! - private val tzDefault = DateUtils.ical4jTimeZone(ZoneId.systemDefault().id)!! + private val tzRegistry = TimeZoneRegistryFactory.getInstance().createRegistry()!! + private val tzVienna = tzRegistry.getTimeZone("Europe/Vienna")!! + private val tzChicago = tzRegistry.getTimeZone("America/Chicago")!! + private val tzDefault = tzRegistry.getTimeZone(ZoneId.systemDefault().id)!! private val testAccount = Account("AndroidTaskTest", LOCAL_ACCOUNT_TYPE) diff --git a/lib/src/androidTest/kotlin/at/bitfire/ical4android/EventTest.kt b/lib/src/androidTest/kotlin/at/bitfire/ical4android/EventTest.kt index c30f3629..73b41b60 100644 --- a/lib/src/androidTest/kotlin/at/bitfire/ical4android/EventTest.kt +++ b/lib/src/androidTest/kotlin/at/bitfire/ical4android/EventTest.kt @@ -12,6 +12,7 @@ import at.bitfire.synctools.icalendar.Css3Color import net.fortuna.ical4j.model.Date import net.fortuna.ical4j.model.DateTime import net.fortuna.ical4j.model.Parameter +import net.fortuna.ical4j.model.TimeZoneRegistryFactory import net.fortuna.ical4j.model.component.VAlarm import net.fortuna.ical4j.model.parameter.Email import net.fortuna.ical4j.model.property.Attendee @@ -20,6 +21,7 @@ import net.fortuna.ical4j.model.property.DtStart import net.fortuna.ical4j.model.property.Organizer import net.fortuna.ical4j.model.property.RRule import net.fortuna.ical4j.model.property.RecurrenceId +import net.fortuna.ical4j.util.TimeZones import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse import org.junit.Assert.assertNull @@ -33,6 +35,11 @@ import java.time.Duration class EventTest { + private val tzRegistry = TimeZoneRegistryFactory.getInstance().createRegistry() + private val tzBerlin = tzRegistry.getTimeZone("Europe/Berlin")!! + private val tzLondon = tzRegistry.getTimeZone("Europe/London")!! + private val tzUTC = tzRegistry.getTimeZone(TimeZones.UTC_ID)!! + /* public interface tests */ @Test @@ -69,8 +76,6 @@ class EventTest { @Test fun testGenerateEtcUTC() { - val tzUTC = DateUtils.ical4jTimeZone("Etc/UTC") - val e = Event() e.uid = "etc-utc-test@example.com" e.dtStart = DtStart("20200926T080000", tzUTC) @@ -126,13 +131,13 @@ class EventTest { fun testRecurringWriteFullDayException() { val event = Event().apply { uid = "test1" - dtStart = DtStart("20190117T083000", DateUtils.ical4jTimeZone("Europe/Berlin")) + dtStart = DtStart("20190117T083000", tzBerlin) summary = "Main event" rRules += RRule("FREQ=DAILY;COUNT=5") exceptions += arrayOf( Event().apply { uid = "test2" - recurrenceId = RecurrenceId(DateTime("20190118T073000", DateUtils.ical4jTimeZone("Europe/London"))) + recurrenceId = RecurrenceId(DateTime("20190118T073000", tzLondon)) summary = "Normal exception" }, Event().apply { @@ -248,7 +253,7 @@ class EventTest { fun testWrite() { val e = Event() e.uid = "SAMPLEUID" - e.dtStart = DtStart("20190101T100000", DateUtils.ical4jTimeZone("Europe/Berlin")) + e.dtStart = DtStart("20190101T100000", tzBerlin) e.alarms += VAlarm(Duration.ofHours(-1)) val os = ByteArrayOutputStream() diff --git a/lib/src/androidTest/kotlin/at/bitfire/ical4android/ICalendarTest.kt b/lib/src/androidTest/kotlin/at/bitfire/ical4android/ICalendarTest.kt index b432233e..58dabf4b 100644 --- a/lib/src/androidTest/kotlin/at/bitfire/ical4android/ICalendarTest.kt +++ b/lib/src/androidTest/kotlin/at/bitfire/ical4android/ICalendarTest.kt @@ -6,12 +6,12 @@ package at.bitfire.ical4android -import at.bitfire.ical4android.util.DateUtils import net.fortuna.ical4j.data.CalendarBuilder import net.fortuna.ical4j.model.Component import net.fortuna.ical4j.model.Date import net.fortuna.ical4j.model.DateTime import net.fortuna.ical4j.model.Property +import net.fortuna.ical4j.model.TimeZoneRegistryFactory import net.fortuna.ical4j.model.component.VAlarm import net.fortuna.ical4j.model.component.VTimeZone import net.fortuna.ical4j.model.parameter.Related @@ -31,7 +31,9 @@ import java.time.Period class ICalendarTest { // UTC timezone - private val tzUTC = DateUtils.ical4jTimeZone(TimeZones.UTC_ID)!!.vTimeZone + private val tzRegistry = TimeZoneRegistryFactory.getInstance().createRegistry() + val tzUTC = tzRegistry.getTimeZone(TimeZones.UTC_ID)!! + private val vtzUTC = tzUTC.vTimeZone // Austria (Europa/Vienna) uses DST regularly private val vtzVienna = readTimeZone("Vienna.ics") @@ -98,8 +100,8 @@ class ICalendarTest { // Keep the only observance for UTC. // DATE-TIME values in UTC are usually noted with ...Z and don't have a VTIMEZONE, // but it is allowed to write them as TZID=Etc/UTC. - assertEquals(1, tzUTC.observances.size) - ICalendar.minifyVTimeZone(tzUTC, Date("20200612")).let { minified -> + assertEquals(1, vtzUTC.observances.size) + ICalendar.minifyVTimeZone(vtzUTC, Date("20200612")).let { minified -> assertEquals(1, minified.observances.size) } } diff --git a/lib/src/androidTest/kotlin/at/bitfire/ical4android/TaskTest.kt b/lib/src/androidTest/kotlin/at/bitfire/ical4android/TaskTest.kt index fcc8a6f2..c092dee0 100644 --- a/lib/src/androidTest/kotlin/at/bitfire/ical4android/TaskTest.kt +++ b/lib/src/androidTest/kotlin/at/bitfire/ical4android/TaskTest.kt @@ -7,12 +7,12 @@ package at.bitfire.ical4android import at.bitfire.ical4android.impl.testProdId -import at.bitfire.ical4android.util.DateUtils import net.fortuna.ical4j.model.Date import net.fortuna.ical4j.model.DateList import net.fortuna.ical4j.model.DateTime import net.fortuna.ical4j.model.Parameter import net.fortuna.ical4j.model.TimeZone +import net.fortuna.ical4j.model.TimeZoneRegistryFactory import net.fortuna.ical4j.model.component.VAlarm import net.fortuna.ical4j.model.parameter.RelType import net.fortuna.ical4j.model.parameter.Value @@ -39,7 +39,9 @@ import java.nio.charset.Charset class TaskTest { - val tzVienna: TimeZone = DateUtils.ical4jTimeZone("Europe/Vienna")!! + val tzRegistry = TimeZoneRegistryFactory.getInstance().createRegistry()!! + val tzBerlin: TimeZone = tzRegistry.getTimeZone("Europe/Berlin")!! + val tzVienna: TimeZone = tzRegistry.getTimeZone("Europe/Vienna")!! /* public interface tests */ @@ -200,7 +202,7 @@ class TaskTest { fun testWrite() { val t = Task() t.uid = "SAMPLEUID" - t.dtStart = DtStart("20190101T100000", DateUtils.ical4jTimeZone("Europe/Berlin")) + t.dtStart = DtStart("20190101T100000", tzBerlin) val alarm = VAlarm(java.time.Duration.ofHours(-1) /*Dur(0, -1, 0, 0)*/) alarm.properties += Action.AUDIO diff --git a/lib/src/androidTest/kotlin/at/bitfire/ical4android/util/AndroidTimeUtilsTest.kt b/lib/src/androidTest/kotlin/at/bitfire/ical4android/util/AndroidTimeUtilsTest.kt index a8f57bcc..5b4c17bc 100644 --- a/lib/src/androidTest/kotlin/at/bitfire/ical4android/util/AndroidTimeUtilsTest.kt +++ b/lib/src/androidTest/kotlin/at/bitfire/ical4android/util/AndroidTimeUtilsTest.kt @@ -27,11 +27,12 @@ import java.time.Period class AndroidTimeUtilsTest { - val tzBerlin: TimeZone = DateUtils.ical4jTimeZone("Europe/Berlin")!! - val tzToronto: TimeZone = DateUtils.ical4jTimeZone("America/Toronto")!! + val tzRegistry = TimeZoneRegistryFactory.getInstance().createRegistry()!! + val tzBerlin: TimeZone = tzRegistry.getTimeZone("Europe/Berlin")!! + val tzToronto: TimeZone = tzRegistry.getTimeZone("America/Toronto")!! val tzCustom by lazy { - val builder = CalendarBuilder() + val builder = CalendarBuilder(tzRegistry) val cal = builder.build(StringReader("BEGIN:VCALENDAR\n" + "BEGIN:VTIMEZONE\n" + "TZID:CustomTime\n" + @@ -45,15 +46,15 @@ class AndroidTimeUtilsTest { TimeZone(cal.getComponent(VTimeZone.VTIMEZONE) as VTimeZone) } - val tzIdDefault = java.util.TimeZone.getDefault().id - val tzDefault = DateUtils.ical4jTimeZone(tzIdDefault) + val tzIdDefault = java.util.TimeZone.getDefault().id!! + val tzDefault = tzRegistry.getTimeZone(tzIdDefault)!! // androidifyTimeZone @Test fun testAndroidifyTimeZone_Null() { // must not throw an exception - AndroidTimeUtils.androidifyTimeZone(null) + AndroidTimeUtils.androidifyTimeZone(null, tzRegistry) } // androidifyTimeZone @@ -63,7 +64,7 @@ class AndroidTimeUtilsTest { fun testAndroidifyTimeZone_DateProperty_Date() { // dates (without time) should be ignored val dtStart = DtStart(Date("20150101")) - AndroidTimeUtils.androidifyTimeZone(dtStart) + AndroidTimeUtils.androidifyTimeZone(dtStart, tzRegistry) assertTrue(DateUtils.isDate(dtStart)) assertNull(dtStart.timeZone) assertFalse(dtStart.isUtc) @@ -73,7 +74,7 @@ class AndroidTimeUtilsTest { fun testAndroidifyTimeZone_DateProperty_KnownTimeZone() { // date-time with known time zone should be unchanged val dtStart = DtStart("20150101T230350", tzBerlin) - AndroidTimeUtils.androidifyTimeZone(dtStart) + AndroidTimeUtils.androidifyTimeZone(dtStart, tzRegistry) assertEquals(tzBerlin, dtStart.timeZone) assertFalse(dtStart.isUtc) } @@ -83,7 +84,7 @@ class AndroidTimeUtilsTest { // time zone that is not available on Android systems should be rewritten to system default val dtStart = DtStart("20150101T031000", tzCustom) // 20150101T031000 CustomTime [+0310] = 20150101T000000 UTC = 1420070400 UNIX - AndroidTimeUtils.androidifyTimeZone(dtStart) + AndroidTimeUtils.androidifyTimeZone(dtStart, tzRegistry) assertEquals(1420070400000L, dtStart.date.time) assertEquals(tzIdDefault, dtStart.timeZone.id) assertFalse(dtStart.isUtc) @@ -93,7 +94,7 @@ class AndroidTimeUtilsTest { fun testAndroidifyTimeZone_DateProperty_FloatingTime() { // times with floating time should be treated as system default time zone val dtStart = DtStart("20150101T230350") - AndroidTimeUtils.androidifyTimeZone(dtStart) + AndroidTimeUtils.androidifyTimeZone(dtStart, tzRegistry) assertEquals(DateTime("20150101T230350", tzDefault).time, dtStart.date.time) assertEquals(tzIdDefault, dtStart.timeZone.id) assertFalse(dtStart.isUtc) @@ -103,7 +104,7 @@ class AndroidTimeUtilsTest { fun testAndroidifyTimeZone_DateProperty_UTC() { // times with UTC should be unchanged val dtStart = DtStart("20150101T230350Z") - AndroidTimeUtils.androidifyTimeZone(dtStart) + AndroidTimeUtils.androidifyTimeZone(dtStart, tzRegistry) assertEquals(1420153430000L, dtStart.date.time) assertNull(dtStart.timeZone) assertTrue(dtStart.isUtc) @@ -279,7 +280,7 @@ class AndroidTimeUtilsTest { @Test fun testAndroidStringToRecurrenceSets_UtcTimes() { // list of UTC times - val exDate = AndroidTimeUtils.androidStringToRecurrenceSet("20150101T103010Z,20150702T103020Z", false) { ExDate(it) } + val exDate = AndroidTimeUtils.androidStringToRecurrenceSet("20150101T103010Z,20150702T103020Z", tzRegistry, false) { ExDate(it) } assertNull(exDate.timeZone) val exDates = exDate.dates assertEquals(Value.DATE_TIME, exDates.type) @@ -292,7 +293,7 @@ class AndroidTimeUtilsTest { @Test fun testAndroidStringToRecurrenceSets_ZonedTimes() { // list of time zone times - val exDate = AndroidTimeUtils.androidStringToRecurrenceSet("${tzToronto.id};20150103T113030,20150704T113040",false) { ExDate(it) } + val exDate = AndroidTimeUtils.androidStringToRecurrenceSet("${tzToronto.id};20150103T113030,20150704T113040", tzRegistry,false) { ExDate(it) } assertEquals(tzToronto, exDate.timeZone) assertEquals(tzToronto.id, (exDate.getParameter(Parameter.TZID) as TzId).value) val exDates = exDate.dates @@ -306,7 +307,7 @@ class AndroidTimeUtilsTest { @Test fun testAndroidStringToRecurrenceSets_Dates() { // list of dates - val exDate = AndroidTimeUtils.androidStringToRecurrenceSet("20150101T103010Z,20150702T103020Z", true) { ExDate(it) } + val exDate = AndroidTimeUtils.androidStringToRecurrenceSet("20150101T103010Z,20150702T103020Z", tzRegistry, true) { ExDate(it) } val exDates = exDate.dates assertEquals(Value.DATE, exDates.type) assertEquals(2, exDates.size) @@ -316,7 +317,7 @@ class AndroidTimeUtilsTest { @Test fun testAndroidStringToRecurrenceSets_Exclude() { - val exDate = AndroidTimeUtils.androidStringToRecurrenceSet("${tzToronto.id};20150103T113030",false, 1420302630000L) { ExDate(it) } + val exDate = AndroidTimeUtils.androidStringToRecurrenceSet("${tzToronto.id};20150103T113030", tzRegistry,false, 1420302630000L) { ExDate(it) } assertEquals(0, exDate.dates.size) } diff --git a/lib/src/androidTest/kotlin/at/bitfire/ical4android/util/DateUtilsTest.kt b/lib/src/androidTest/kotlin/at/bitfire/ical4android/util/DateUtilsTest.kt index b71e864e..9163a750 100644 --- a/lib/src/androidTest/kotlin/at/bitfire/ical4android/util/DateUtilsTest.kt +++ b/lib/src/androidTest/kotlin/at/bitfire/ical4android/util/DateUtilsTest.kt @@ -12,7 +12,6 @@ import net.fortuna.ical4j.model.property.DtEnd import net.fortuna.ical4j.model.property.DtStart import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse -import org.junit.Assert.assertNotNull import org.junit.Assert.assertNull import org.junit.Assert.assertTrue import org.junit.Test @@ -21,18 +20,6 @@ import java.util.TimeZone class DateUtilsTest { - private val tzIdToronto = "America/Toronto" - private val tzToronto = DateUtils.ical4jTimeZone(tzIdToronto)!! - - @Test - fun testTimeZoneRegistry() { - assertNotNull(DateUtils.ical4jTimeZone("Europe/Vienna")) - - // https://github.com/ical4j/ical4j/issues/207 - assertNotNull(DateUtils.ical4jTimeZone("EST")) - } - - @Test fun testFindAndroidTimezoneID() { assertEquals("Europe/Vienna", DateUtils.findAndroidTimezoneID("Europe/Vienna")) diff --git a/lib/src/androidTest/kotlin/at/bitfire/ical4android/util/TimeApiExtensionsTest.kt b/lib/src/androidTest/kotlin/at/bitfire/ical4android/util/TimeApiExtensionsTest.kt index f8a1f193..4d7714c6 100644 --- a/lib/src/androidTest/kotlin/at/bitfire/ical4android/util/TimeApiExtensionsTest.kt +++ b/lib/src/androidTest/kotlin/at/bitfire/ical4android/util/TimeApiExtensionsTest.kt @@ -18,6 +18,7 @@ import at.bitfire.ical4android.util.TimeApiExtensions.toZonedDateTime import net.fortuna.ical4j.model.Date import net.fortuna.ical4j.model.DateTime import net.fortuna.ical4j.model.TimeZone +import net.fortuna.ical4j.model.TimeZoneRegistryFactory import net.fortuna.ical4j.util.TimeZones import org.junit.Assert.assertEquals import org.junit.Assert.assertTrue @@ -34,7 +35,8 @@ import java.time.ZonedDateTime class TimeApiExtensionsTest { - val tzBerlin: TimeZone = DateUtils.ical4jTimeZone("Europe/Berlin")!! + val tzRegistry = TimeZoneRegistryFactory.getInstance().createRegistry()!! + val tzBerlin = tzRegistry.getTimeZone("Europe/Berlin")!! @Test @@ -155,10 +157,9 @@ class TimeApiExtensionsTest { @Test fun testZonedDateTime_toIcal4jDateTime_NotUtc() { - val tzBerlin = DateUtils.ical4jTimeZone("Europe/Berlin") assertEquals( DateTime("20200705T010203", tzBerlin), - ZonedDateTime.of(2020, 7, 5, 1, 2, 3, 0, ZoneId.of("Europe/Berlin")).toIcal4jDateTime() + ZonedDateTime.of(2020, 7, 5, 1, 2, 3, 0, ZoneId.of("Europe/Berlin")).toIcal4jDateTime(tzRegistry) ) } @@ -166,7 +167,7 @@ class TimeApiExtensionsTest { fun testZonedDateTime_toIcal4jDateTime_Utc() { assertEquals( DateTime("20200705T010203Z"), - ZonedDateTime.of(2020, 7, 5, 1, 2, 3, 0, ZoneOffset.UTC).toIcal4jDateTime() + ZonedDateTime.of(2020, 7, 5, 1, 2, 3, 0, ZoneOffset.UTC).toIcal4jDateTime(tzRegistry) ) } diff --git a/lib/src/androidTest/kotlin/at/bitfire/synctools/storage/calendar/AndroidCalendarTest.kt b/lib/src/androidTest/kotlin/at/bitfire/synctools/storage/calendar/AndroidCalendarTest.kt index edeff276..160c1e23 100644 --- a/lib/src/androidTest/kotlin/at/bitfire/synctools/storage/calendar/AndroidCalendarTest.kt +++ b/lib/src/androidTest/kotlin/at/bitfire/synctools/storage/calendar/AndroidCalendarTest.kt @@ -19,6 +19,7 @@ import at.bitfire.ical4android.Event import at.bitfire.ical4android.impl.TestCalendar import at.bitfire.ical4android.util.MiscUtils.closeCompat import at.bitfire.synctools.icalendar.Css3Color +import net.fortuna.ical4j.model.TimeZoneRegistryFactory import net.fortuna.ical4j.model.property.DtEnd import net.fortuna.ical4j.model.property.DtStart import org.junit.After @@ -36,6 +37,7 @@ class AndroidCalendarTest { ) private val testAccount = Account("ical4android.AndroidCalendarTest", CalendarContract.ACCOUNT_TYPE_LOCAL) + private val tzRegistry = TimeZoneRegistryFactory.getInstance().createRegistry() lateinit var client: ContentProviderClient lateinit var provider: AndroidCalendarProvider diff --git a/lib/src/main/kotlin/at/bitfire/ical4android/AndroidEvent.kt b/lib/src/main/kotlin/at/bitfire/ical4android/AndroidEvent.kt index 822a80bd..49718259 100644 --- a/lib/src/main/kotlin/at/bitfire/ical4android/AndroidEvent.kt +++ b/lib/src/main/kotlin/at/bitfire/ical4android/AndroidEvent.kt @@ -49,6 +49,7 @@ import net.fortuna.ical4j.model.DateList import net.fortuna.ical4j.model.DateTime import net.fortuna.ical4j.model.Parameter import net.fortuna.ical4j.model.Property +import net.fortuna.ical4j.model.TimeZoneRegistryFactory import net.fortuna.ical4j.model.component.VAlarm import net.fortuna.ical4j.model.parameter.Cn import net.fortuna.ical4j.model.parameter.Email @@ -212,6 +213,8 @@ class AndroidEvent( logger.log(Level.FINE, "Read event entity from calender provider", row) val event = requireNotNull(event) + val tzRegistry by lazy { TimeZoneRegistryFactory.getInstance().createRegistry() } + row.getAsString(Events.MUTATORS)?.let { strPackages -> val packages = strPackages.split(MUTATORS_SEPARATOR).toSet() event.userAgents.addAll(packages) @@ -259,10 +262,9 @@ class AndroidEvent( } else /* !allDay */ { // use DATE-TIME values - // check time zone ID (calendar apps may insert no or an invalid ID) val startTzId = DateUtils.findAndroidTimezoneID(row.getAsString(Events.EVENT_TIMEZONE)) - val startTz = DateUtils.ical4jTimeZone(startTzId) + val startTz = tzRegistry.getTimeZone(startTzId) val dtStartDateTime = DateTime(tsStart).apply { if (startTz != null) { // null if there was not ical4j time zone for startTzId, which should not happen, but technically may happen if (TimeZones.isUtc(startTz)) @@ -292,7 +294,7 @@ class AndroidEvent( logger.fine("dtEnd $tsEnd == dtStart, won't generate DTEND property")*/ else /* tsEnd > tsStart */ { val endTz = row.getAsString(Events.EVENT_END_TIMEZONE)?.let { tzId -> - DateUtils.ical4jTimeZone(tzId) + tzRegistry.getTimeZone(tzId) } ?: startTz event.dtEnd = DtEnd(DateTime(tsEnd).apply { if (endTz != null) { @@ -314,7 +316,7 @@ class AndroidEvent( event.rRules += RRule(rule) } row.getAsString(Events.RDATE)?.let { datesStr -> - val rDate = AndroidTimeUtils.androidStringToRecurrenceSet(datesStr, allDay, tsStart) { RDate(it) } + val rDate = AndroidTimeUtils.androidStringToRecurrenceSet(datesStr, tzRegistry, allDay, tsStart) { RDate(it) } event.rDates += rDate } @@ -323,7 +325,7 @@ class AndroidEvent( event.exRules += ExRule(null, rule) } row.getAsString(Events.EXDATE)?.let { datesStr -> - val exDate = AndroidTimeUtils.androidStringToRecurrenceSet(datesStr, allDay) { ExDate(it) } + val exDate = AndroidTimeUtils.androidStringToRecurrenceSet(datesStr, tzRegistry, allDay) { ExDate(it) } event.exDates += exDate } } catch (e: Exception) { @@ -792,7 +794,8 @@ class AndroidEvent( val allDay = DateUtils.isDate(dtStart) // make sure that time zone is supported by Android - AndroidTimeUtils.androidifyTimeZone(dtStart) + val tzRegistry = TimeZoneRegistryFactory.getInstance().createRegistry() + AndroidTimeUtils.androidifyTimeZone(dtStart, tzRegistry) val recurring = event.rRules.isNotEmpty() || event.rDates.isNotEmpty() @@ -828,7 +831,7 @@ class AndroidEvent( .withValue(Events.EVENT_TIMEZONE, AndroidTimeUtils.storageTzId(dtStart)) var dtEnd = event.dtEnd - AndroidTimeUtils.androidifyTimeZone(dtEnd) + AndroidTimeUtils.androidifyTimeZone(dtEnd, tzRegistry) var duration = if (dtEnd == null) @@ -947,7 +950,7 @@ class AndroidEvent( } } - AndroidTimeUtils.androidifyTimeZone(dtEnd) + AndroidTimeUtils.androidifyTimeZone(dtEnd, tzRegistry) builder .withValue(Events.DTEND, dtEnd.date.time) .withValue(Events.EVENT_END_TIMEZONE, AndroidTimeUtils.storageTzId(dtEnd)) .withValue(Events.DURATION, null) diff --git a/lib/src/main/kotlin/at/bitfire/ical4android/DmfsTask.kt b/lib/src/main/kotlin/at/bitfire/ical4android/DmfsTask.kt index 2d6b9bb9..d9d4b57c 100644 --- a/lib/src/main/kotlin/at/bitfire/ical4android/DmfsTask.kt +++ b/lib/src/main/kotlin/at/bitfire/ical4android/DmfsTask.kt @@ -12,7 +12,6 @@ import android.net.Uri import android.os.RemoteException import androidx.annotation.CallSuper import at.bitfire.ical4android.util.AndroidTimeUtils -import at.bitfire.ical4android.util.DateUtils import at.bitfire.synctools.storage.BatchOperation.CpoBuilder import at.bitfire.synctools.storage.LocalStorageException import at.bitfire.synctools.storage.TasksBatchOperation @@ -23,6 +22,7 @@ import net.fortuna.ical4j.model.Parameter import net.fortuna.ical4j.model.Property import net.fortuna.ical4j.model.PropertyList import net.fortuna.ical4j.model.TimeZone +import net.fortuna.ical4j.model.TimeZoneRegistryFactory import net.fortuna.ical4j.model.component.VAlarm import net.fortuna.ical4j.model.parameter.Email import net.fortuna.ical4j.model.parameter.RelType @@ -71,11 +71,10 @@ abstract class DmfsTask( companion object { const val UNKNOWN_PROPERTY_DATA = Properties.DATA0 - - val utcTimeZone by lazy { DateUtils.ical4jTimeZone(TimeZones.UTC_ID) } } protected val logger = Logger.getLogger(javaClass.name) + protected val tzRegistry by lazy { TimeZoneRegistryFactory.getInstance().createRegistry() } var id: Long? = null @@ -210,7 +209,10 @@ abstract class DmfsTask( val allDay = (values.getAsInteger(Tasks.IS_ALLDAY) ?: 0) != 0 val tzID = values.getAsString(Tasks.TZ) - val tz = tzID?.let { DateUtils.ical4jTimeZone(it) } + val tz = tzID?.let { + val tzRegistry = TimeZoneRegistryFactory.getInstance().createRegistry() + tzRegistry.getTimeZone(it) + } values.getAsLong(Tasks.CREATED)?.let { task.createdAt = it } values.getAsLong(Tasks.LAST_MODIFIED)?.let { task.lastModified = it } @@ -253,10 +255,10 @@ abstract class DmfsTask( } values.getAsString(Tasks.RDATE)?.let { - task.rDates += AndroidTimeUtils.androidStringToRecurrenceSet(it, allDay) { dates -> RDate(dates) } + task.rDates += AndroidTimeUtils.androidStringToRecurrenceSet(it, tzRegistry, allDay) { dates -> RDate(dates) } } values.getAsString(Tasks.EXDATE)?.let { - task.exDates += AndroidTimeUtils.androidStringToRecurrenceSet(it, allDay) { dates -> ExDate(dates) } + task.exDates += AndroidTimeUtils.androidStringToRecurrenceSet(it, tzRegistry, allDay) { dates -> ExDate(dates) } } values.getAsString(Tasks.RRULE)?.let { task.rRule = RRule(it) } @@ -537,8 +539,8 @@ abstract class DmfsTask( builder .withValue(Tasks.IS_ALLDAY, 1) .withValue(Tasks.TZ, null) } else { - AndroidTimeUtils.androidifyTimeZone(task.dtStart) - AndroidTimeUtils.androidifyTimeZone(task.due) + AndroidTimeUtils.androidifyTimeZone(task.dtStart, tzRegistry) + AndroidTimeUtils.androidifyTimeZone(task.due, tzRegistry) builder .withValue(Tasks.IS_ALLDAY, 0) .withValue(Tasks.TZ, getTimeZone().id) } @@ -570,17 +572,17 @@ abstract class DmfsTask( val task = requireNotNull(task) return task.dtStart?.let { dtStart -> if (dtStart.isUtc) - utcTimeZone + tzRegistry.getTimeZone(TimeZones.UTC_ID) else dtStart.timeZone } ?: task.due?.let { due -> if (due.isUtc) - utcTimeZone + tzRegistry.getTimeZone(TimeZones.UTC_ID) else due.timeZone } ?: - DateUtils.ical4jTimeZone(ZoneId.systemDefault().id)!! + tzRegistry.getTimeZone(ZoneId.systemDefault().id)!! } diff --git a/lib/src/main/kotlin/at/bitfire/ical4android/Event.kt b/lib/src/main/kotlin/at/bitfire/ical4android/Event.kt index 4d85eb77..673cc46e 100644 --- a/lib/src/main/kotlin/at/bitfire/ical4android/Event.kt +++ b/lib/src/main/kotlin/at/bitfire/ical4android/Event.kt @@ -246,8 +246,8 @@ data class Event( * Parses an iCalendar resource, applies [at.bitfire.ical4android.validation.ICalPreprocessor] * and [EventValidator] to increase compatibility and extracts the VEVENTs. * - * @param reader where the iCalendar is taken from - * @param properties Known iCalendar properties (like [CALENDAR_NAME]) will be put into this map. Key: property name; value: property value + * @param reader where the iCalendar is read from + * @param properties Known iCalendar properties (like [CALENDAR_NAME]) will be put into this map. Key: property name; value: property value * * @return array of filled [Event] data objects (may have size 0) * diff --git a/lib/src/main/kotlin/at/bitfire/ical4android/ICalendar.kt b/lib/src/main/kotlin/at/bitfire/ical4android/ICalendar.kt index a80827ae..d33c6f5e 100644 --- a/lib/src/main/kotlin/at/bitfire/ical4android/ICalendar.kt +++ b/lib/src/main/kotlin/at/bitfire/ical4android/ICalendar.kt @@ -84,15 +84,18 @@ open class ICalendar { /** * Parses an iCalendar resource and applies [ICalPreprocessor] to increase compatibility. * - * @param reader where the iCalendar is taken from - * @param properties Known iCalendar properties (like [CALENDAR_NAME]) will be put into this map. Key: property name; value: property value + * @param reader where the iCalendar is read from + * @param properties Known iCalendar properties (like [CALENDAR_NAME]) will be put into this map. Key: property name; value: property value * * @return parsed iCalendar resource * * @throws InvalidRemoteResourceException when the iCalendar can't be parsed */ @Deprecated("Use ICalendarParser directly") - fun fromReader(reader: Reader, properties: MutableMap? = null): Calendar { + fun fromReader( + reader: Reader, + properties: MutableMap? = null + ): Calendar { logger.fine("Parsing iCalendar stream") val calendar = ICalendarParser().parse(reader) diff --git a/lib/src/main/kotlin/at/bitfire/ical4android/util/AndroidTimeUtils.kt b/lib/src/main/kotlin/at/bitfire/ical4android/util/AndroidTimeUtils.kt index 9d67fb99..dbb42b1e 100644 --- a/lib/src/main/kotlin/at/bitfire/ical4android/util/AndroidTimeUtils.kt +++ b/lib/src/main/kotlin/at/bitfire/ical4android/util/AndroidTimeUtils.kt @@ -18,6 +18,8 @@ import net.fortuna.ical4j.model.DateList import net.fortuna.ical4j.model.DateTime import net.fortuna.ical4j.model.TemporalAmountAdapter import net.fortuna.ical4j.model.TimeZone +import net.fortuna.ical4j.model.TimeZoneRegistry +import net.fortuna.ical4j.model.TimeZoneRegistryFactory import net.fortuna.ical4j.model.parameter.Value import net.fortuna.ical4j.model.property.DateListProperty import net.fortuna.ical4j.model.property.DateProperty @@ -66,11 +68,12 @@ object AndroidTimeUtils { * use [storageTzId]. * * @param date [DateProperty] to validate. Values which are not DATE-TIME will be ignored. + * @param tzRegistry time zone registry to get time zones from */ - fun androidifyTimeZone(date: DateProperty?) { + fun androidifyTimeZone(date: DateProperty?, tzRegistry: TimeZoneRegistry) { if (DateUtils.isDateTime(date) && date?.isUtc == false) { val tzID = DateUtils.findAndroidTimezoneID(date.timeZone?.id) - date.timeZone = DateUtils.ical4jTimeZone(tzID) + date.timeZone = tzRegistry.getTimeZone(tzID) } } @@ -83,24 +86,26 @@ object AndroidTimeUtils { * @param dateList [DateListProperty] to validate. Values which are not DATE-TIME will be ignored. */ fun androidifyTimeZone(dateList: DateListProperty) { + val tzRegistry by lazy { TimeZoneRegistryFactory.getInstance().createRegistry() } + // periods (RDate only) val periods = (dateList as? RDate)?.periods - if (periods != null && periods.size > 0 && !periods.isUtc) { + if (periods != null && periods.isNotEmpty() && !periods.isUtc) { val tzID = DateUtils.findAndroidTimezoneID(periods.timeZone?.id) // Setting the time zone won't work until resolved in ical4j (https://github.com/ical4j/ical4j/discussions/568) // DateListProperty.setTimeZone() does not set the timeZone property when the DateList has PERIODs - dateList.timeZone = DateUtils.ical4jTimeZone(tzID) + dateList.timeZone = tzRegistry.getTimeZone(tzID) return // RDate can only contain periods OR dates - not both, bail out fast } // date-times (RDate and ExDate) val dates = dateList.dates - if (dates != null && dates.size > 0) { + if (dates != null && dates.isNotEmpty()) { if (dates.type == Value.DATE_TIME && !dates.isUtc) { val tzID = DateUtils.findAndroidTimezoneID(dates.timeZone?.id) - dateList.timeZone = DateUtils.ical4jTimeZone(tzID) + dateList.timeZone = tzRegistry.getTimeZone(tzID) } } } @@ -201,7 +206,7 @@ object AndroidTimeUtils { // DTSTART is DATE-TIME; amend DATE-TIME with clock time from dtStart dateListProp.dates.mapTo(strDates) { date -> // take time (including time zone) from dtStart and date from date - val dtStartTime = (dtStart as DateTime).toZonedDateTime() + val dtStartTime = dtStart.toZonedDateTime() val localDate = date.toLocalDate() val dtStartTimeUtc = ZonedDateTime.of( localDate, @@ -228,17 +233,24 @@ object AndroidTimeUtils { * Takes a formatted string as provided by the Android calendar provider and returns a DateListProperty * constructed from these values. * - * @param dbStr formatted string from Android calendar provider (RDATE/EXDATE field) - * expected format: "[TZID;]date1,date2,date3" where date is "yyyymmddThhmmss[Z]" - * @param allDay true: list will contain DATE values; false: list will contain DATE_TIME values - * @param exclude this time stamp won't be added to the [DateListProperty] - * @param generator generates the [DateListProperty]; must call the constructor with the one argument of type [DateList] + * @param dbStr formatted string from Android calendar provider (RDATE/EXDATE field) + * expected format: "[TZID;]date1,date2,date3" where date is "yyyymmddThhmmss[Z]" + * @param tzRegistry time zone registry + * @param allDay true: list will contain DATE values; false: list will contain DATE_TIME values + * @param exclude this time stamp won't be added to the [DateListProperty] + * @param generator generates the [DateListProperty]; must call the constructor with the one argument of type [DateList] * - * @return instance of "type" containing the parsed dates/times from the string + * @return instance of "type" containing the parsed dates/times from the string * * @throws ParseException when the string cannot be parsed */ - fun androidStringToRecurrenceSet(dbStr: String, allDay: Boolean, exclude: Long? = null, generator: (DateList) -> T): T + fun androidStringToRecurrenceSet( + dbStr: String, + tzRegistry: TimeZoneRegistry, + allDay: Boolean, + exclude: Long? = null, + generator: (DateList) -> T + ): T { // 1. split string into time zone and actual dates var timeZone: TimeZone? @@ -247,7 +259,7 @@ object AndroidTimeUtils { val limiter = dbStr.indexOf(RECURRENCE_LIST_TZID_SEPARATOR) if (limiter != -1) { // TZID given val tzId = dbStr.substring(0, limiter) - timeZone = DateUtils.ical4jTimeZone(tzId) + timeZone = tzRegistry.getTimeZone(tzId) if (TimeZones.isUtc(timeZone)) timeZone = null datesStr = dbStr.substring(limiter + 1) diff --git a/lib/src/main/kotlin/at/bitfire/ical4android/util/DateUtils.kt b/lib/src/main/kotlin/at/bitfire/ical4android/util/DateUtils.kt index 0429fe01..e7629195 100644 --- a/lib/src/main/kotlin/at/bitfire/ical4android/util/DateUtils.kt +++ b/lib/src/main/kotlin/at/bitfire/ical4android/util/DateUtils.kt @@ -10,7 +10,6 @@ import net.fortuna.ical4j.data.CalendarBuilder import net.fortuna.ical4j.model.Date import net.fortuna.ical4j.model.DateTime import net.fortuna.ical4j.model.TimeZone -import net.fortuna.ical4j.model.TimeZoneRegistryFactory import net.fortuna.ical4j.model.component.VTimeZone import net.fortuna.ical4j.model.property.DateProperty import java.io.StringReader @@ -28,12 +27,6 @@ object DateUtils { private val logger get() = Logger.getLogger(javaClass.name) - /** - * Global ical4j time zone registry used for event/task processing. Do not - * modify this registry or its entries! - */ - private val tzRegistry = TimeZoneRegistryFactory.getInstance().createRegistry() - // time zones @@ -46,7 +39,7 @@ object DateUtils { * 2. Find partial matches (case-sensitive) in both directions, so both "Vienna" * and "MyClient: Europe/Vienna" will return "Europe/Vienna". This shouln't be * case-insensitive, because that would for instance return "EST" for "Westeuropäische Sommerzeit". - * 3. If nothing can be found or [tzId] is `null`, return the system default time zone. + * 3. If nothing can be found or [tzID] is `null`, return the system default time zone. * * @param tzID time zone ID to be converted into Android time zone ID * @@ -87,25 +80,11 @@ object DateUtils { try { val zone = ZoneId.of(id) zone - } catch (e: Exception) { + } catch (_: Exception) { null } } - /** - * Loads a time zone from the ical4j time zone registry (which contains the - * VTIMEZONE definitions). - * - * All Android time zone IDs plus some other time zones should be available. - * However, the possibility that the time zone is not available in ical4j should - * be handled. - * - * @param id time zone ID (like `Europe/Vienna`) - * @return the ical4j time zone (VTIMEZONE), or `null` if no VTIMEZONE is available - */ - @Deprecated("Create and query new TimeZoneRegistry instance if one is needed") - fun ical4jTimeZone(id: String): TimeZone? = tzRegistry.getTimeZone(id) - /** * Determines whether a given date represents a DATE value. * @param date date property to check @@ -127,8 +106,8 @@ object DateUtils { * * @return parsed [VTimeZone], or `null` when the timezone definition can't be parsed */ - fun parseVTimeZone(timezoneDef: String): VTimeZone? { - val builder = CalendarBuilder(tzRegistry) + fun parseVTimeZone(timezoneDef: String ): VTimeZone? { + val builder = CalendarBuilder() try { val cal = builder.build(StringReader(timezoneDef)) return cal.getComponent(VTimeZone.VTIMEZONE) as VTimeZone @@ -138,4 +117,4 @@ object DateUtils { } } -} +} \ No newline at end of file diff --git a/lib/src/main/kotlin/at/bitfire/ical4android/util/TimeApiExtensions.kt b/lib/src/main/kotlin/at/bitfire/ical4android/util/TimeApiExtensions.kt index 1246d070..4283b1be 100644 --- a/lib/src/main/kotlin/at/bitfire/ical4android/util/TimeApiExtensions.kt +++ b/lib/src/main/kotlin/at/bitfire/ical4android/util/TimeApiExtensions.kt @@ -8,6 +8,8 @@ package at.bitfire.ical4android.util import net.fortuna.ical4j.model.Date import net.fortuna.ical4j.model.DateTime +import net.fortuna.ical4j.model.TimeZoneRegistry +import net.fortuna.ical4j.model.TimeZoneRegistryFactory import net.fortuna.ical4j.util.TimeZones import java.time.Duration import java.time.Instant @@ -59,25 +61,25 @@ object TimeApiExtensions { } fun DateTime.requireTimeZone(): TimeZone = - if (isUtc) - TimeZones.getUtcTimeZone() - else - timeZone ?: TimeZone.getDefault() + if (isUtc) + TimeZones.getUtcTimeZone() + else + timeZone ?: TimeZone.getDefault() fun DateTime.requireZoneId(): ZoneId = - if (isUtc) - ZoneOffset.UTC - else - timeZone?.toZoneIdCompat() ?: ZoneId.systemDefault() + if (isUtc) + ZoneOffset.UTC + else + timeZone?.toZoneIdCompat() ?: ZoneId.systemDefault() fun DateTime.toLocalDate(): LocalDate = - toZonedDateTime().toLocalDate() + toZonedDateTime().toLocalDate() fun DateTime.toLocalTime(): LocalTime = - toZonedDateTime().toLocalTime() + toZonedDateTime().toLocalTime() fun DateTime.toZonedDateTime(): ZonedDateTime = - ZonedDateTime.ofInstant(Instant.ofEpochMilli(time), requireZoneId()) + ZonedDateTime.ofInstant(Instant.ofEpochMilli(time), requireZoneId()) fun LocalDate.toIcal4jDate(): Date { val cal = Calendar.getInstance(TimeZones.getDateTimeZone()) @@ -92,14 +94,18 @@ object TimeApiExtensions { * Sets UTC flag ([DateTime.isUtc], means `...ThhmmddZ` format) when this zone-date time object has a * time zone of [ZoneOffset.UTC]. * + * @param tzRegistry time zone registry to get the [net.fortuna.ical4j.model.TimeZone] from (if needed) + * * @return ical4j [DateTime] of the given zoned date-time */ - fun ZonedDateTime.toIcal4jDateTime(): DateTime { + fun ZonedDateTime.toIcal4jDateTime( + tzRegistry: TimeZoneRegistry = TimeZoneRegistryFactory.getInstance().createRegistry() + ): DateTime { val date = DateTime(toEpochSecond() * MILLIS_PER_SECOND) if (zone == ZoneOffset.UTC) date.isUtc = true else - date.timeZone = DateUtils.ical4jTimeZone(zone.id) + date.timeZone = tzRegistry.getTimeZone(zone.id) return date } diff --git a/lib/src/main/kotlin/at/bitfire/synctools/icalendar/ICalendarParser.kt b/lib/src/main/kotlin/at/bitfire/synctools/icalendar/ICalendarParser.kt index aec4ae70..1e5a378f 100644 --- a/lib/src/main/kotlin/at/bitfire/synctools/icalendar/ICalendarParser.kt +++ b/lib/src/main/kotlin/at/bitfire/synctools/icalendar/ICalendarParser.kt @@ -32,6 +32,9 @@ class ICalendarParser { * 1. The input stream from is preprocessed with [ICalPreprocessor.preprocessStream]. * 2. The parsed calendar is preprocessed with [ICalPreprocessor.preprocessCalendar]. * + * @param reader where the iCalendar is read from + * @param tzRegistry time zone registry where VTIMEZONE definitions of the iCalendar will be put + * * @throws InvalidRemoteResourceException when the resource is can't be parsed */ fun parse(reader: Reader): Calendar { @@ -44,7 +47,7 @@ class ICalendarParser { calendar = CalendarBuilder( /* parser = */ CalendarParserFactory.getInstance().get(), /* contentHandlerContext = */ ContentHandlerContext().withSupressInvalidProperties(/* supressInvalidProperties = */ true), - /* tzRegistry = */ TimeZoneRegistryFactory.getInstance().createRegistry() // AndroidCompatTimeZoneRegistry + /* tzRegistry = */ TimeZoneRegistryFactory.getInstance().createRegistry() ).build(preprocessed) } catch(e: ParserException) { throw InvalidRemoteResourceException("Couldn't parse iCalendar", e) diff --git a/lib/src/main/kotlin/at/bitfire/synctools/test/InitCalendarProviderRule.kt b/lib/src/main/kotlin/at/bitfire/synctools/test/InitCalendarProviderRule.kt index f4b29928..ae8c5b8b 100644 --- a/lib/src/main/kotlin/at/bitfire/synctools/test/InitCalendarProviderRule.kt +++ b/lib/src/main/kotlin/at/bitfire/synctools/test/InitCalendarProviderRule.kt @@ -19,6 +19,7 @@ import at.bitfire.ical4android.AndroidEvent import at.bitfire.ical4android.Event import at.bitfire.synctools.storage.calendar.AndroidCalendar import at.bitfire.synctools.storage.calendar.AndroidCalendarProvider +import net.fortuna.ical4j.model.TimeZoneRegistryFactory import net.fortuna.ical4j.model.property.DtStart import net.fortuna.ical4j.model.property.RRule import org.junit.Assert @@ -81,6 +82,7 @@ class InitCalendarProviderRule private constructor() : ExternalResource() { } val calendar = calendarOrNull ?: throw IllegalStateException("Couldn't create calendar") + val tzRegistry = TimeZoneRegistryFactory.getInstance().createRegistry() try { // single event init val normalEvent = Event().apply { diff --git a/lib/src/test/kotlin/at/bitfire/ical4android/validation/EventValidatorTest.kt b/lib/src/test/kotlin/at/bitfire/ical4android/validation/EventValidatorTest.kt index 37f3ef85..a1a12228 100644 --- a/lib/src/test/kotlin/at/bitfire/ical4android/validation/EventValidatorTest.kt +++ b/lib/src/test/kotlin/at/bitfire/ical4android/validation/EventValidatorTest.kt @@ -7,7 +7,6 @@ package at.bitfire.ical4android.validation import at.bitfire.ical4android.Event -import at.bitfire.ical4android.util.DateUtils import net.fortuna.ical4j.model.Date import net.fortuna.ical4j.model.DateList import net.fortuna.ical4j.model.DateTime @@ -144,7 +143,7 @@ class EventValidatorTest { } assertEquals( DateTime("20211214T235959Z"), - event.rRules.first.recur.until + event.rRules.first().recur.until ) EventValidator.sameTypeForDtStartAndRruleUntil(event.dtStart!!, event.rRules) assertEquals("FREQ=MONTHLY;UNTIL=20211214", event.rRules.joinToString()) @@ -160,7 +159,7 @@ class EventValidatorTest { "END:VCALENDAR" ) ).first() - assertEquals(1639440000000, event1.rRules.first.recur.until.time) + assertEquals(1639440000000, event1.rRules.first().recur.until.time) assertEquals("FREQ=MONTHLY;UNTIL=20211214;BYMONTHDAY=15", event1.rRules.joinToString()) } @@ -375,7 +374,8 @@ class EventValidatorTest { @Test fun testRemoveRecurrencesOfRecurringWithExceptions() { // Test manually created event - val tz = DateUtils.ical4jTimeZone("Europe/Paris") + val tzRegistry = TimeZoneRegistryFactory.getInstance().createRegistry() + val tz = tzRegistry.getTimeZone("Europe/Paris") val manualEvent = Event().apply { dtStart = DtStart("20240219T130000", tz) dtEnd = DtEnd("20240219T140000", tz) @@ -507,7 +507,7 @@ class EventValidatorTest { // helpers - private fun Iterable.joinToString(): String = - this.map { rRule -> rRule.value }.joinToString("\n") + private fun Iterable.joinToString() = + this.joinToString("\n") { rRule -> rRule.value } } \ No newline at end of file