shorten a parser code

This commit is contained in:
tibbi 2017-09-24 13:27:08 +02:00
parent 2c535015ba
commit 63d70afae0
1 changed files with 8 additions and 10 deletions

View File

@ -126,25 +126,23 @@ class Parser {
else -> ";$UNTIL=${Formatter.getDayCodeFromTS(event.repeatLimit)}"
}
private fun getByDay(event: Event): String {
return if (event.repeatInterval.isXWeeklyRepetition()) {
private fun getByDay(event: Event) = when {
event.repeatInterval.isXWeeklyRepetition() -> {
val days = getByDayString(event.repeatRule)
";$BYDAY=$days"
} else if (event.repeatInterval.isXMonthlyRepetition()) {
if (event.repeatRule == REPEAT_MONTH_LAST_DAY) {
";$BYMONTHDAY=-1"
} else if (event.repeatRule == REPEAT_MONTH_EVERY_XTH_DAY) {
}
event.repeatInterval.isXMonthlyRepetition() -> when {
event.repeatRule == REPEAT_MONTH_LAST_DAY -> ";$BYMONTHDAY=-1"
event.repeatRule == REPEAT_MONTH_EVERY_XTH_DAY -> {
val start = Formatter.getDateTimeFromTS(event.startTS)
val dayOfMonth = start.dayOfMonth
val order = (dayOfMonth - 1) / 7 + 1
val day = getDayLetters(start.dayOfWeek)
";$BYDAY=$order$day"
} else {
""
}
} else {
""
else -> ""
}
else -> ""
}
private fun getByDayString(rule: Int): String {