From 63d70afae01dd27d10c4dcc7f4d1d6ded3f79b52 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 24 Sep 2017 13:27:08 +0200 Subject: [PATCH] shorten a parser code --- .../calendar/helpers/Parser.kt | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Parser.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Parser.kt index d78a5f61a..b116733c5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Parser.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Parser.kt @@ -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 {