add proper logic at yearly repetition rules

This commit is contained in:
tibbi 2018-05-10 15:04:20 +02:00
parent 8218bfb190
commit 5fabba4032
2 changed files with 7 additions and 4 deletions

View File

@ -424,8 +424,7 @@ class EventActivity : SimpleActivity() {
private fun getYearlyRepetitionRuleText() = when (mRepeatRule) { private fun getYearlyRepetitionRuleText() = when (mRepeatRule) {
REPEAT_SAME_DAY -> getString(R.string.the_same_day) REPEAT_SAME_DAY -> getString(R.string.the_same_day)
REPEAT_ORDER_WEEKDAY -> getRepeatXthDayInMonthString(false, mRepeatRule) else -> getRepeatXthDayInMonthString(false, mRepeatRule)
else -> ""
} }
private fun showEventTypeDialog() { private fun showEventTypeDialog() {

View File

@ -29,11 +29,15 @@ data class Event(var id: Int = 0, var startTS: Int = 0, var endTS: Int = 0, var
else -> { else -> {
val currStart = Formatter.getDateTimeFromTS(startTS) val currStart = Formatter.getDateTimeFromTS(startTS)
val newStart = when { val newStart = when {
repeatInterval % YEAR == 0 -> currStart.plusYears(repeatInterval / YEAR) repeatInterval % YEAR == 0 -> when (repeatRule) {
REPEAT_ORDER_WEEKDAY -> addXthDayInterval(currStart, original, false)
REPEAT_ORDER_WEEKDAY_USE_LAST -> addXthDayInterval(currStart, original, true)
else -> currStart.plusYears(repeatInterval / YEAR)
}
repeatInterval % MONTH == 0 -> when (repeatRule) { repeatInterval % MONTH == 0 -> when (repeatRule) {
REPEAT_SAME_DAY -> addMonthsWithSameDay(currStart, original) REPEAT_SAME_DAY -> addMonthsWithSameDay(currStart, original)
REPEAT_ORDER_WEEKDAY_USE_LAST -> addXthDayInterval(currStart, original, true)
REPEAT_ORDER_WEEKDAY -> addXthDayInterval(currStart, original, false) REPEAT_ORDER_WEEKDAY -> addXthDayInterval(currStart, original, false)
REPEAT_ORDER_WEEKDAY_USE_LAST -> addXthDayInterval(currStart, original, true)
else -> currStart.plusMonths(repeatInterval / MONTH).dayOfMonth().withMaximumValue() else -> currStart.plusMonths(repeatInterval / MONTH).dayOfMonth().withMaximumValue()
} }
repeatInterval % WEEK == 0 -> { repeatInterval % WEEK == 0 -> {