diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt index 6aab771fa..03f125b06 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/Constants.kt @@ -82,6 +82,7 @@ val RRULE = "RRULE:" val CATEGORIES = "CATEGORIES:" val STATUS = "STATUS:" val EXDATE = "EXDATE" +val BYDAY = "BYDAY" val DISPLAY = "DISPLAY" val FREQ = "FREQ" @@ -96,3 +97,11 @@ val DAILY = "DAILY" val WEEKLY = "WEEKLY" val MONTHLY = "MONTHLY" val YEARLY = "YEARLY" + +val MO = "MO" +val TU = "TU" +val WE = "WE" +val TH = "TH" +val FR = "FR" +val SA = "SA" +val SU = "SU" diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/IcsExporter.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/IcsExporter.kt index a407ae265..c41bc07bf 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/IcsExporter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/helpers/IcsExporter.kt @@ -64,7 +64,8 @@ class IcsExporter { val freq = getFreq(repeatInterval) val interval = getInterval(repeatInterval) val repeatLimit = getRepeatLimitString(event) - val rrule = "$RRULE$FREQ=$freq;$INTERVAL=$interval$repeatLimit" + val byDay = getByDay(event) + val rrule = "$RRULE$FREQ=$freq;$INTERVAL=$interval$repeatLimit$byDay" out.writeLn(rrule) } @@ -97,6 +98,34 @@ class IcsExporter { ";$UNTIL=${Formatter.getDayCodeFromTS(event.repeatLimit)}" } + private fun getByDay(event: Event): String { + return if (event.repeatInterval != WEEK) { + "" + } else { + val days = getByDayString(event.repeatRule) + ";$BYDAY=$days" + } + } + + private fun getByDayString(rule: Int): String { + var result = "" + if (rule and MONDAY != 0) + result += "$MO," + if (rule and TUESDAY != 0) + result += "$TU," + if (rule and WEDNESDAY != 0) + result += "$WE," + if (rule and THURSDAY != 0) + result += "$TH," + if (rule and FRIDAY != 0) + result += "$FR," + if (rule and SATURDAY != 0) + result += "$SA," + if (rule and SUNDAY != 0) + result += "$SU," + return result.trimEnd(',') + } + private fun fillReminders(event: Event, out: BufferedWriter) { checkReminder(event.reminder1Minutes, out) checkReminder(event.reminder2Minutes, out)