Skip to content

Commit 95a2404

Browse files
committed
Pass time zone registry to ICalendarParser and Event
1 parent f5e41c4 commit 95a2404

File tree

9 files changed

+90
-71
lines changed

9 files changed

+90
-71
lines changed

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

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ class AndroidEventTest {
147147
*/
148148

149149
private fun buildEvent(automaticDates: Boolean, eventBuilder: Event.() -> Unit): ContentValues {
150-
val event = Event().apply {
150+
val event = Event(tzRegistry = tzRegistry).apply {
151151
if (automaticDates)
152152
dtStart = DtStart(DateTime())
153153
eventBuilder()
@@ -1323,7 +1323,7 @@ class AndroidEventTest {
13231323
buildEvent(false) {
13241324
dtStart = DtStart("20200706T193000", tzVienna)
13251325
rRules += RRule("FREQ=DAILY;COUNT=10")
1326-
exceptions += Event().apply {
1326+
exceptions += Event(tzRegistry = tzRegistry).apply {
13271327
recurrenceId = RecurrenceId("20200707T193000", tzVienna)
13281328
dtStart = DtStart("20200706T203000", tzShanghai)
13291329
summary = "Event moved to one hour later"
@@ -1349,7 +1349,7 @@ class AndroidEventTest {
13491349
buildEvent(false) {
13501350
dtStart = DtStart("20200706T193000", tzVienna)
13511351
rRules += RRule("FREQ=DAILY;COUNT=10")
1352-
exceptions += Event().apply {
1352+
exceptions += Event(tzRegistry = tzRegistry).apply {
13531353
recurrenceId = RecurrenceId(Date("20200707")) // illegal! should be rewritten to DateTime("20200707T193000", tzVienna)
13541354
dtStart = DtStart("20200706T203000", tzShanghai)
13551355
summary = "Event moved to one hour later"
@@ -1375,7 +1375,7 @@ class AndroidEventTest {
13751375
buildEvent(false) {
13761376
dtStart = DtStart(Date("20200706"))
13771377
rRules += RRule("FREQ=WEEKLY;COUNT=3")
1378-
exceptions += Event().apply {
1378+
exceptions += Event(tzRegistry = tzRegistry).apply {
13791379
recurrenceId = RecurrenceId(Date("20200707"))
13801380
dtStart = DtStart("20200706T123000", tzVienna)
13811381
summary = "Today not an all-day event"
@@ -1400,7 +1400,7 @@ class AndroidEventTest {
14001400
buildEvent(false) {
14011401
dtStart = DtStart(Date("20200706"))
14021402
rRules += RRule("FREQ=WEEKLY;COUNT=3")
1403-
exceptions += Event().apply {
1403+
exceptions += Event(tzRegistry = tzRegistry).apply {
14041404
recurrenceId = RecurrenceId("20200707T000000", tzVienna) // illegal! should be rewritten to Date("20200707")
14051405
dtStart = DtStart("20200706T123000", tzVienna)
14061406
summary = "Today not an all-day event"
@@ -2351,7 +2351,7 @@ class AndroidEventTest {
23512351
@Test
23522352
fun testUpdateEvent() {
23532353
// add test event without reminder
2354-
val event = Event()
2354+
val event = Event(tzRegistry = tzRegistry)
23552355
event.uid = "sample1@testAddEvent"
23562356
event.summary = "Sample event"
23572357
event.dtStart = DtStart("20150502T120000Z")
@@ -2386,7 +2386,7 @@ class AndroidEventTest {
23862386
@Test
23872387
fun testUpdateEvent_ResetColor() {
23882388
// add event with color
2389-
val event = Event().apply {
2389+
val event = Event(tzRegistry = tzRegistry).apply {
23902390
uid = "sample1@testAddEvent"
23912391
dtStart = DtStart(DateTime())
23922392
color = Css3Color.silver
@@ -2409,7 +2409,7 @@ class AndroidEventTest {
24092409

24102410
@Test
24112411
fun testUpdateEvent_UpdateStatusFromNull() {
2412-
val event = Event()
2412+
val event = Event(tzRegistry = tzRegistry)
24132413
event.uid = "sample1@testAddEvent"
24142414
event.summary = "Sample event with STATUS"
24152415
event.dtStart = DtStart("20150502T120000Z")
@@ -2438,7 +2438,7 @@ class AndroidEventTest {
24382438

24392439
@Test
24402440
fun testUpdateEvent_UpdateStatusToNull() {
2441-
val event = Event()
2441+
val event = Event(tzRegistry = tzRegistry)
24422442
event.uid = "sample1@testAddEvent"
24432443
event.summary = "Sample event with STATUS"
24442444
event.dtStart = DtStart("20150502T120000Z")
@@ -2470,7 +2470,7 @@ class AndroidEventTest {
24702470

24712471
@Test
24722472
fun testTransaction() {
2473-
val event = Event()
2473+
val event = Event(tzRegistry = tzRegistry)
24742474
event.uid = "sample1@testTransaction"
24752475
event.summary = "an event"
24762476
event.dtStart = DtStart("20150502T120000Z")
@@ -2493,7 +2493,7 @@ class AndroidEventTest {
24932493
@Test
24942494
fun testMarkEventAsDeleted() {
24952495
// Create event
2496-
val event = Event().apply {
2496+
val event = Event(tzRegistry = tzRegistry).apply {
24972497
dtStart = DtStart("20220120T010203Z")
24982498
summary = "A fine event"
24992499
}
@@ -2518,7 +2518,7 @@ class AndroidEventTest {
25182518

25192519
@Test
25202520
fun testNumDirectInstances_SingleInstance() {
2521-
val event = Event().apply {
2521+
val event = Event(tzRegistry = tzRegistry).apply {
25222522
dtStart = DtStart("20220120T010203Z")
25232523
summary = "Event with 1 instance"
25242524
}
@@ -2530,7 +2530,7 @@ class AndroidEventTest {
25302530

25312531
@Test
25322532
fun testNumDirectInstances_Recurring() {
2533-
val event = Event().apply {
2533+
val event = Event(tzRegistry = tzRegistry).apply {
25342534
dtStart = DtStart("20220120T010203Z")
25352535
summary = "Event with 5 instances"
25362536
rRules.add(RRule("FREQ=DAILY;COUNT=5"))
@@ -2543,7 +2543,7 @@ class AndroidEventTest {
25432543

25442544
@Test
25452545
fun testNumDirectInstances_Recurring_Endless() {
2546-
val event = Event().apply {
2546+
val event = Event(tzRegistry = tzRegistry).apply {
25472547
dtStart = DtStart("20220120T010203Z")
25482548
summary = "Event without end"
25492549
rRules.add(RRule("FREQ=DAILY"))
@@ -2557,7 +2557,7 @@ class AndroidEventTest {
25572557
@Test
25582558
// flaky, needs InitCalendarProviderRule
25592559
fun testNumDirectInstances_Recurring_LateEnd() {
2560-
val event = Event().apply {
2560+
val event = Event(tzRegistry = tzRegistry).apply {
25612561
dtStart = DtStart("20220120T010203Z")
25622562
summary = "Event with 53 years"
25632563
rRules.add(RRule("FREQ=YEARLY;UNTIL=20740119T010203Z")) // year 2074 is not supported by Android <11 Calendar Storage
@@ -2573,7 +2573,7 @@ class AndroidEventTest {
25732573

25742574
@Test
25752575
fun testNumDirectInstances_Recurring_ManyInstances() {
2576-
val event = Event().apply {
2576+
val event = Event(tzRegistry = tzRegistry).apply {
25772577
dtStart = DtStart("20220120T010203Z")
25782578
summary = "Event with 2 years"
25792579
rRules.add(RRule("FREQ=DAILY;UNTIL=20240120T010203Z"))
@@ -2589,7 +2589,7 @@ class AndroidEventTest {
25892589

25902590
@Test
25912591
fun testNumDirectInstances_RecurringWithExdate() {
2592-
val event = Event().apply {
2592+
val event = Event(tzRegistry = tzRegistry).apply {
25932593
dtStart = DtStart(Date("20220120T010203Z"))
25942594
summary = "Event with 5 instances"
25952595
rRules.add(RRule("FREQ=DAILY;COUNT=5"))
@@ -2603,16 +2603,16 @@ class AndroidEventTest {
26032603

26042604
@Test
26052605
fun testNumDirectInstances_RecurringWithExceptions() {
2606-
val event = Event().apply {
2606+
val event = Event(tzRegistry = tzRegistry).apply {
26072607
dtStart = DtStart("20220120T010203Z")
26082608
summary = "Event with 5 instances"
26092609
rRules.add(RRule("FREQ=DAILY;COUNT=5"))
2610-
exceptions.add(Event().apply {
2610+
exceptions.add(Event(tzRegistry = tzRegistry).apply {
26112611
recurrenceId = RecurrenceId("20220122T010203Z")
26122612
dtStart = DtStart("20220122T130203Z")
26132613
summary = "Exception on 3rd day"
26142614
})
2615-
exceptions.add(Event().apply {
2615+
exceptions.add(Event(tzRegistry = tzRegistry).apply {
26162616
recurrenceId = RecurrenceId("20220124T010203Z")
26172617
dtStart = DtStart("20220122T160203Z")
26182618
summary = "Exception on 5th day"
@@ -2627,7 +2627,7 @@ class AndroidEventTest {
26272627

26282628
@Test
26292629
fun testNumInstances_SingleInstance() {
2630-
val event = Event().apply {
2630+
val event = Event(tzRegistry = tzRegistry).apply {
26312631
dtStart = DtStart("20220120T010203Z")
26322632
summary = "Event with 1 instance"
26332633
}
@@ -2639,7 +2639,7 @@ class AndroidEventTest {
26392639

26402640
@Test
26412641
fun testNumInstances_Recurring() {
2642-
val event = Event().apply {
2642+
val event = Event(tzRegistry = tzRegistry).apply {
26432643
dtStart = DtStart("20220120T010203Z")
26442644
summary = "Event with 5 instances"
26452645
rRules.add(RRule("FREQ=DAILY;COUNT=5"))
@@ -2652,7 +2652,7 @@ class AndroidEventTest {
26522652

26532653
@Test
26542654
fun testNumInstances_Recurring_Endless() {
2655-
val event = Event().apply {
2655+
val event = Event(tzRegistry = tzRegistry).apply {
26562656
dtStart = DtStart("20220120T010203Z")
26572657
summary = "Event with infinite instances"
26582658
rRules.add(RRule("FREQ=YEARLY"))
@@ -2665,7 +2665,7 @@ class AndroidEventTest {
26652665

26662666
@Test
26672667
fun testNumInstances_Recurring_LateEnd() {
2668-
val event = Event().apply {
2668+
val event = Event(tzRegistry = tzRegistry).apply {
26692669
dtStart = DtStart("20220120T010203Z")
26702670
summary = "Event over 22 years"
26712671
rRules.add(RRule("FREQ=YEARLY;UNTIL=20740119T010203Z")) // year 2074 not supported by Android <11 Calendar Storage
@@ -2681,7 +2681,7 @@ class AndroidEventTest {
26812681

26822682
@Test
26832683
fun testNumInstances_Recurring_ManyInstances() {
2684-
val event = Event().apply {
2684+
val event = Event(tzRegistry = tzRegistry).apply {
26852685
dtStart = DtStart("20220120T010203Z")
26862686
summary = "Event over two years"
26872687
rRules.add(RRule("FREQ=DAILY;UNTIL=20240120T010203Z"))
@@ -2700,16 +2700,16 @@ class AndroidEventTest {
27002700

27012701
@Test
27022702
fun testNumInstances_RecurringWithExceptions() {
2703-
val event = Event().apply {
2703+
val event = Event(tzRegistry = tzRegistry).apply {
27042704
dtStart = DtStart("20220120T010203Z")
27052705
summary = "Event with 6 instances"
27062706
rRules.add(RRule("FREQ=DAILY;COUNT=6"))
2707-
exceptions.add(Event().apply {
2707+
exceptions.add(Event(tzRegistry = tzRegistry).apply {
27082708
recurrenceId = RecurrenceId("20220122T010203Z")
27092709
dtStart = DtStart("20220122T130203Z")
27102710
summary = "Exception on 3rd day"
27112711
})
2712-
exceptions.add(Event().apply {
2712+
exceptions.add(Event(tzRegistry = tzRegistry).apply {
27132713
recurrenceId = RecurrenceId("20220124T010203Z")
27142714
dtStart = DtStart("20220122T160203Z")
27152715
summary = "Exception on 5th day"

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class EventTest {
7676

7777
@Test
7878
fun testGenerateEtcUTC() {
79-
val e = Event()
79+
val e = Event(tzRegistry = tzRegistry)
8080
e.uid = "etc-utc-test@example.com"
8181
e.dtStart = DtStart("20200926T080000", tzUTC)
8282
e.dtEnd = DtEnd("20200926T100000", tzUTC)
@@ -129,18 +129,18 @@ class EventTest {
129129

130130
@Test
131131
fun testRecurringWriteFullDayException() {
132-
val event = Event().apply {
132+
val event = Event(tzRegistry = tzRegistry).apply {
133133
uid = "test1"
134134
dtStart = DtStart("20190117T083000", tzBerlin)
135135
summary = "Main event"
136136
rRules += RRule("FREQ=DAILY;COUNT=5")
137137
exceptions += arrayOf(
138-
Event().apply {
138+
Event(tzRegistry = tzRegistry).apply {
139139
uid = "test2"
140140
recurrenceId = RecurrenceId(DateTime("20190118T073000", tzLondon))
141141
summary = "Normal exception"
142142
},
143-
Event().apply {
143+
Event(tzRegistry = tzRegistry).apply {
144144
uid = "test3"
145145
recurrenceId = RecurrenceId(Date("20190223"))
146146
summary = "Full-day exception"
@@ -239,7 +239,7 @@ class EventTest {
239239

240240
@Test
241241
fun testToString() {
242-
val e = Event()
242+
val e = Event(tzRegistry = tzRegistry)
243243
e.uid = "SAMPLEUID"
244244
val s = e.toString()
245245
assertTrue(s.contains(Event::class.java.simpleName))
@@ -251,7 +251,7 @@ class EventTest {
251251

252252
@Test
253253
fun testWrite() {
254-
val e = Event()
254+
val e = Event(tzRegistry = tzRegistry)
255255
e.uid = "SAMPLEUID"
256256
e.dtStart = DtStart("20190101T100000", tzBerlin)
257257
e.alarms += VAlarm(Duration.ofHours(-1))
@@ -314,12 +314,12 @@ class EventTest {
314314

315315
@Test
316316
fun testOrganizerEmail_None() {
317-
assertNull(Event().organizerEmail)
317+
assertNull(Event(tzRegistry = tzRegistry).organizerEmail)
318318
}
319319

320320
@Test
321321
fun testOrganizerEmail_EmailParameter() {
322-
assertEquals("organizer@example.com", Event().apply {
322+
assertEquals("organizer@example.com", Event(tzRegistry = tzRegistry).apply {
323323
organizer = Organizer("SomeFancyOrganizer").apply {
324324
parameters.add(Email("organizer@example.com"))
325325
}
@@ -328,7 +328,7 @@ class EventTest {
328328

329329
@Test
330330
fun testOrganizerEmail_MailtoValue() {
331-
assertEquals("organizer@example.com", Event().apply {
331+
assertEquals("organizer@example.com", Event(tzRegistry = tzRegistry).apply {
332332
organizer = Organizer("mailto:organizer@example.com")
333333
}.organizerEmail)
334334
}

0 commit comments

Comments
 (0)