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) {
DAY -> {
startTS += DAY_SECONDS
endTS += DAY_SECONDS
}
else -> {
val currStart = Formatter.getDateTimeFromTS(startTS) val currStart = Formatter.getDateTimeFromTS(startTS)
val newStart = when { val newStart: DateTime
newStart = when (repeatInterval) {
DAY -> currStart.plusDays(1)
else -> {
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,15 +38,11 @@ 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 -> currStart.plusSeconds(repeatInterval)
} }
else -> {
startTS += repeatInterval
endTS += repeatInterval
return
} }
} }
val newStartTS = newStart.seconds() val newStartTS = newStart.seconds()
@ -57,8 +50,6 @@ data class Event(var id: Int = 0, var startTS: Int = 0, var endTS: Int = 0, var
startTS = newStartTS startTS = newStartTS
endTS = newEndTS 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
private fun addMonthsWithSameDay(currStart: DateTime, original: Event): DateTime { private fun addMonthsWithSameDay(currStart: DateTime, original: Event): DateTime {