handle exporting and importing events repeating monthly on last day

This commit is contained in:
tibbi 2017-05-08 22:33:10 +02:00
parent e53f7f9a87
commit 57fb030d96
3 changed files with 16 additions and 3 deletions

View File

@ -84,6 +84,7 @@ val CATEGORIES = "CATEGORIES:"
val STATUS = "STATUS:"
val EXDATE = "EXDATE"
val BYDAY = "BYDAY"
val BYMONTHDAY = "BYMONTHDAY"
val DISPLAY = "DISPLAY"
val FREQ = "FREQ"

View File

@ -2,6 +2,8 @@ package com.simplemobiletools.calendar.helpers
import com.simplemobiletools.calendar.activities.SimpleActivity
import com.simplemobiletools.calendar.extensions.dbHelper
import com.simplemobiletools.calendar.extensions.isXMonthlyRepetition
import com.simplemobiletools.calendar.extensions.isXWeeklyRepetition
import com.simplemobiletools.calendar.extensions.writeLn
import com.simplemobiletools.calendar.helpers.IcsExporter.ExportResult.*
import com.simplemobiletools.calendar.models.Event
@ -103,11 +105,17 @@ class IcsExporter {
}
private fun getByDay(event: Event): String {
return if (event.repeatInterval == 0 || event.repeatInterval % WEEK != 0) {
""
} else {
return if (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 {
""
}
} else {
""
}
}

View File

@ -202,6 +202,8 @@ class IcsImporter {
if (value == WEEKLY) {
val start = Formatter.getDateTimeFromTS(curStart)
curRepeatRule = Math.pow(2.0, (start.dayOfWeek - 1).toDouble()).toInt()
} else if (value == MONTHLY) {
curRepeatRule = REPEAT_MONTH_SAME_DAY
}
} else if (key == COUNT) {
curRepeatLimit = -value.toInt()
@ -211,6 +213,8 @@ class IcsImporter {
frequencySeconds *= value.toInt()
} else if (key == BYDAY) {
handleRepeatRule(value)
} else if (key == BYMONTHDAY && value.toInt() == -1) {
curRepeatRule = REPEAT_MONTH_LAST_DAY
}
}
return frequencySeconds