Skip to content
This repository was archived by the owner on May 26, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 2 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 @@ -23,6 +23,9 @@ import net.fortuna.ical4j.model.parameter.TzId
import net.fortuna.ical4j.model.property.DateProperty
import net.fortuna.ical4j.model.property.immutable.ImmutableVersion
import java.io.Writer
import java.time.Instant
import java.time.ZoneOffset
import java.time.ZonedDateTime
import java.time.temporal.Temporal
import java.util.logging.Logger
import javax.annotation.WillNotClose
Expand Down Expand Up @@ -68,7 +71,9 @@ class ICalendarGenerator {
ical += exception

exception.dtStart<Temporal>()?.date?.let { start ->
if (earliestStart == null || TemporalAdapter.isBefore(start, earliestStart))
val normalizedStart = start.normalizeForComparison()
val normalizedEarliest = earliestStart?.normalizeForComparison()
if (normalizedEarliest == null || TemporalAdapter.isBefore(normalizedStart, normalizedEarliest))
earliestStart = start
}
usedTimezoneIds += timeZonesOf(exception)
Expand Down Expand Up @@ -107,6 +112,9 @@ class ICalendarGenerator {
CalendarOutputter(false).output(ical, to)
}

private fun Temporal.normalizeForComparison(): ZonedDateTime =
if (this is Instant) atZone(ZoneOffset.UTC) else ZonedDateTime.from(this)
Comment thread
ArnyminerZ marked this conversation as resolved.
Outdated

/**
* Creates a one-level deep copy of the given [VTimeZone] instance.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,27 @@ class ICalendarGeneratorTest {
assertTrue(result.isEmpty())
}

@Test
fun `Write event with UTC Instant exception DTSTART does not throw`() {
val iCal = StringWriter()
writer.write(AssociatedEvents(
main = VEvent(propertyListOf(
Uid("UTCTEST"),
DtStart(ZonedDateTime.of(LocalDateTime.parse("2025-08-22T05:30:00"), tzBerlin)),
DtStamp("20250822T000000Z"),
RRule<Temporal>("FREQ=DAILY;COUNT=3")
)),
exceptions = listOf(
VEvent(propertyListOf(
Uid("UTCTEST"),
RecurrenceId(Instant.parse("2025-08-22T03:30:00Z")),
DtStart(Instant.parse("2025-08-22T03:30:00Z")),
DtStamp("20250822T000000Z")
))
),
prodId = userAgent
), iCal)
assertTrue(iCal.toString().contains("BEGIN:VCALENDAR"))
}

}
Loading