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

Add DTSTAMP to generated VEVENTs again

parent e6cca076
Pipeline #98485931 passed with stages
in 4 minutes and 54 seconds
......@@ -238,10 +238,15 @@ class Event: ICalendar() {
* @return generated VEvent
*/
private fun toVEvent(): VEvent {
val props = PropertyList<Property>()
val event = VEvent(true /* generates DTSTAMP */)
val props = event.properties
props += Uid(uid)
recurrenceId?.let { props += it }
sequence?.let { if (it != 0) props += Sequence(it) }
sequence?.let {
if (it != 0)
props += Sequence(it)
}
summary?.let { props += Summary(it) }
location?.let { props += Location(it) }
......@@ -269,7 +274,9 @@ class Event: ICalendar() {
lastModified?.let { props += it }
return VEvent(props, ComponentList(alarms))
event.alarms.addAll(alarms)
return event
}
......
......@@ -38,9 +38,9 @@ object ICalPreprocessor {
propertyRules
.filter { rule -> rule.supportedType.isAssignableFrom(property::class.java) }
.forEach {
Constants.log.log(Level.INFO, "Applying rules to ${property.toString()}")
Constants.log.log(Level.FINER, "Applying rules to ${property.toString()}")
(it as Rfc5545PropertyRule<Property>).applyTo(property)
Constants.log.log(Level.INFO, "-> ${property.toString()}")
Constants.log.log(Level.FINER, "-> ${property.toString()}")
}
}
......
......@@ -16,7 +16,6 @@ import net.fortuna.ical4j.data.ParserException
import net.fortuna.ical4j.model.*
import net.fortuna.ical4j.model.Calendar
import net.fortuna.ical4j.model.TimeZone
import net.fortuna.ical4j.model.component.CalendarComponent
import net.fortuna.ical4j.model.component.VAlarm
import net.fortuna.ical4j.model.component.VToDo
import net.fortuna.ical4j.model.property.*
......@@ -140,9 +139,19 @@ class Task: ICalendar() {
fun write(os: OutputStream) {
val props = PropertyList<Property>()
val ical = Calendar()
ical.properties += Version.VERSION_2_0
ical.properties += prodId
val vTodo = VToDo(true /* generates DTSTAMP */)
ical.components += vTodo
val props = vTodo.properties
uid?.let { props += Uid(uid) }
sequence?.let { if (it != 0) props += Sequence(sequence as Int) }
sequence?.let {
if (it != 0)
props += Sequence(it)
}
createdAt?.let { props += Created(DateTime(it)) }
lastModified?.let { props += LastModified(DateTime(it)) }
......@@ -192,20 +201,11 @@ class Task: ICalendar() {
}
percentComplete?.let { props += PercentComplete(it) }
// generate VTODO
val iCalProps = PropertyList<Property>(2)
iCalProps += Version.VERSION_2_0
iCalProps += prodId
val vTodo = VToDo(props)
if (alarms.isNotEmpty())
vTodo.alarms.addAll(alarms)
val iCalComponents = ComponentList<CalendarComponent>(2)
iCalComponents.add(vTodo)
iCalComponents.addAll(usedTimeZones.map { it.vTimeZone })
ical.components.addAll(usedTimeZones.map { it.vTimeZone })
val ical = Calendar(iCalProps, iCalComponents)
CalendarOutputter(false).output(ical, os)
}
......
......@@ -7,8 +7,13 @@
*/
package at.bitfire.ical4android
import net.fortuna.ical4j.model.Dur
import net.fortuna.ical4j.model.TimeZoneRegistryFactory
import net.fortuna.ical4j.model.component.VAlarm
import net.fortuna.ical4j.model.property.DtStart
import org.junit.Assert.*
import org.junit.Test
import java.io.ByteArrayOutputStream
import java.io.FileNotFoundException
import java.io.InputStreamReader
import java.nio.charset.Charset
......@@ -153,6 +158,30 @@ class EventTest {
}
/* generating */
@Test
fun testWrite() {
val e = Event()
e.uid = "SAMPLEUID"
e.dtStart = DtStart("20190101T100000", TimeZoneRegistryFactory.getInstance().createRegistry().getTimeZone("Europe/Berlin"))
e.alarms += VAlarm(Dur(0, -1, 0, 0))
val os = ByteArrayOutputStream()
e.write(os)
val raw = os.toString(Charsets.UTF_8.name())
assertTrue(raw.contains("PRODID:${ICalendar.prodId.value}"))
assertTrue(raw.contains("UID:SAMPLEUID"))
assertTrue(raw.contains("DTSTART;TZID=Europe/Berlin:20190101T100000"))
assertTrue(raw.contains("DTSTAMP:"))
assertTrue(raw.contains("BEGIN:VALARM\r\n" +
"TRIGGER:-PT1H\r\n" +
"END:VALARM\r\n"))
assertTrue(raw.contains("BEGIN:VTIMEZONE"))
}
/* internal tests */
@Test
......
......@@ -9,9 +9,11 @@
package at.bitfire.ical4android
import net.fortuna.ical4j.model.*
import net.fortuna.ical4j.model.component.VAlarm
import net.fortuna.ical4j.model.parameter.RelType
import net.fortuna.ical4j.model.parameter.Value
import net.fortuna.ical4j.model.property.*
import net.fortuna.ical4j.util.TimeZones
import org.junit.Assert.*
import org.junit.Test
import java.io.ByteArrayInputStream
......@@ -106,6 +108,30 @@ class TaskTest {
}
/* generating */
@Test
fun testWrite() {
val t = Task()
t.uid = "SAMPLEUID"
t.dtStart = DtStart("20190101T100000", TimeZoneRegistryFactory.getInstance().createRegistry().getTimeZone("Europe/Berlin"))
t.alarms += VAlarm(Dur(0, -1, 0, 0))
val os = ByteArrayOutputStream()
t.write(os)
val raw = os.toString(Charsets.UTF_8.name())
assertTrue(raw.contains("PRODID:${ICalendar.prodId.value}"))
assertTrue(raw.contains("UID:SAMPLEUID"))
assertTrue(raw.contains("DTSTAMP:"))
assertTrue(raw.contains("DTSTART;TZID=Europe/Berlin:20190101T100000"))
assertTrue(raw.contains("BEGIN:VALARM\r\n" +
"TRIGGER:-PT1H\r\n" +
"END:VALARM\r\n"))
assertTrue(raw.contains("BEGIN:VTIMEZONE"))
}
/* helpers */
private fun parseCalendar(fname: String, charset: Charset = Charsets.UTF_8): Task {
......
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