fix #505, use joda for adding event days and weeks

This commit is contained in:
tibbi 2018-05-25 22:58:19 +02:00
parent bdb24effb4
commit 4210808aec
1 changed files with 12 additions and 21 deletions

View File

@ -3,7 +3,6 @@ package com.simplemobiletools.calendar.models
import com.simplemobiletools.calendar.extensions.seconds import com.simplemobiletools.calendar.extensions.seconds
import com.simplemobiletools.calendar.helpers.* import com.simplemobiletools.calendar.helpers.*
import com.simplemobiletools.calendar.helpers.Formatter import com.simplemobiletools.calendar.helpers.Formatter
import com.simplemobiletools.commons.helpers.DAY_SECONDS
import org.joda.time.DateTime import org.joda.time.DateTime
import java.io.Serializable import java.io.Serializable
import java.util.* import java.util.*
@ -21,14 +20,12 @@ data class Event(var id: Int = 0, var startTS: Int = 0, var endTS: Int = 0, var
} }
fun addIntervalTime(original: Event) { fun addIntervalTime(original: Event) {
when (repeatInterval) { val currStart = Formatter.getDateTimeFromTS(startTS)
DAY -> { val newStart: DateTime
startTS += DAY_SECONDS newStart = when (repeatInterval) {
endTS += DAY_SECONDS DAY -> currStart.plusDays(1)
}
else -> { else -> {
val currStart = Formatter.getDateTimeFromTS(startTS) when {
val newStart = when {
repeatInterval % YEAR == 0 -> when (repeatRule) { repeatInterval % YEAR == 0 -> when (repeatRule) {
REPEAT_ORDER_WEEKDAY -> addXthDayInterval(currStart, original, false) REPEAT_ORDER_WEEKDAY -> addXthDayInterval(currStart, original, false)
REPEAT_ORDER_WEEKDAY_USE_LAST -> addXthDayInterval(currStart, original, true) REPEAT_ORDER_WEEKDAY_USE_LAST -> addXthDayInterval(currStart, original, true)
@ -41,23 +38,17 @@ data class Event(var id: Int = 0, var startTS: Int = 0, var endTS: Int = 0, var
else -> currStart.plusMonths(repeatInterval / MONTH).dayOfMonth().withMaximumValue() else -> currStart.plusMonths(repeatInterval / MONTH).dayOfMonth().withMaximumValue()
} }
repeatInterval % WEEK == 0 -> { repeatInterval % WEEK == 0 -> {
// step through weekly repetition by days, as events can trigger multiple times a week // step through weekly repetition by days too, as events can trigger multiple times a week
startTS += DAY_SECONDS currStart.plusDays(1)
endTS += DAY_SECONDS
return
}
else -> {
startTS += repeatInterval
endTS += repeatInterval
return
} }
else -> currStart.plusSeconds(repeatInterval)
} }
val newStartTS = newStart.seconds()
val newEndTS = newStartTS + (endTS - startTS)
startTS = newStartTS
endTS = newEndTS
} }
} }
val newStartTS = newStart.seconds()
val newEndTS = newStartTS + (endTS - startTS)
startTS = newStartTS
endTS = newEndTS
} }
// if an event should happen on 31st with Same Day monthly repetition, dont show it at all at months with 30 or less days // if an event should happen on 31st with Same Day monthly repetition, dont show it at all at months with 30 or less days