Commit be6d515d authored by Ricki Hirner's avatar Ricki Hirner 🐑

isAllDay: check for null

parent 605b9045
Pipeline #107469412 passed with stages
in 4 minutes and 34 seconds
......@@ -14,6 +14,7 @@ import net.fortuna.ical4j.data.CalendarOutputter
import net.fortuna.ical4j.data.ParserException
import net.fortuna.ical4j.model.*
import net.fortuna.ical4j.model.Calendar
import net.fortuna.ical4j.model.Date
import net.fortuna.ical4j.model.TimeZone
import net.fortuna.ical4j.model.component.VAlarm
import net.fortuna.ical4j.model.component.VEvent
......@@ -303,6 +304,11 @@ class Event: ICalendar() {
// helpers
fun isAllDay() = !isDateTime(dtStart)
/**
* Determines whether this Event is an all-day event.
*
* @return *true* if [dtStart] is a DATE value; *false* otherwise ([dtStart] is a DATETIME value or *null*)
*/
fun isAllDay() = dtStart != null && !isDateTime(dtStart)
}
......@@ -79,6 +79,13 @@ class EventTest {
assertTrue("Event 2 Exception 2" == e.exceptions.first.summary || "Event 2 Exception 2" == e.exceptions[1].summary)
}
@Test
fun testIsAllDay() {
assertFalse(Event().isAllDay())
assertTrue(Event().apply { dtStart = DtStart(Date("20190101")) }.isAllDay())
assertFalse(Event().apply { dtStart = DtStart(DateTime("20190101T010100")) }.isAllDay())
}
@Test
fun testParse() {
val event = parseCalendar("utf8.ics").first()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment