Skip to content

Commit

Permalink
Merge pull request #15 from maxmielchen/problem-with-special-characters
Browse files Browse the repository at this point in the history
add umlaut function
  • Loading branch information
maxmielchen authored Mar 12, 2023
2 parents 050737e + 2c98519 commit 3541e26
Showing 1 changed file with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@ import net.fortuna.ical4j.model.*
import net.fortuna.ical4j.model.component.VEvent
import net.fortuna.ical4j.model.property.CalScale
import net.fortuna.ical4j.model.property.Description
import net.fortuna.ical4j.model.property.DtEnd
import net.fortuna.ical4j.model.property.DtStart
import net.fortuna.ical4j.model.property.ProdId
import net.fortuna.ical4j.model.property.Version
import org.bytedream.untis4j.UntisUtils
import org.bytedream.untis4j.responseObjects.Timetable
import java.time.ZoneId
import java.time.ZoneOffset


fun Timetable.getCalender() : Calendar
{
Expand All @@ -32,15 +28,31 @@ fun Timetable.getCalender() : Calendar
val event = VEvent(
DateTime(Date.from(lesson.startTime.atDate(lesson.date).atZone(ZoneId.of(Config.timezone)).toInstant())),
DateTime(Date.from(lesson.endTime.atDate(lesson.date).atZone(ZoneId.of(Config.timezone)).toInstant())),
name
name.replaceUmlaute()
)
try
{
event.properties.add(Description("${Config.defaultRoomAlias}: ${lesson.rooms[0].longName} \n${Config.defaultTeacherAlias}: ${lesson.teachers[0].fullName}"))
event.properties.add(Description("${Config.defaultRoomAlias.replaceUmlaute()}: ${lesson.rooms[0].longName.replaceUmlaute()} \n${Config.defaultTeacherAlias.replaceUmlaute()}: ${lesson.teachers[0].fullName.replaceUmlaute()}"))
} catch (_ : Exception) { }
calendar.components.add(
event
)
}
return calendar
}

fun String.replaceUmlaute(): String {
val umlauteMap = mapOf(
"ä" to "ae",
"ö" to "oe",
"ü" to "ue",
"Ä" to "Ae",
"Ö" to "Oe",
"Ü" to "Ue"
)
var outputString = this
umlauteMap.forEach { (umlaut, replacement) ->
outputString = outputString.replace(umlaut, replacement)
}
return outputString
}

0 comments on commit 3541e26

Please sign in to comment.