use a helper function for checking if the timestamp is at a valid day

This commit is contained in:
tibbi 2017-04-16 10:13:55 +02:00
parent 005fa01001
commit 31e5c72a87
3 changed files with 13 additions and 10 deletions

View File

@ -85,9 +85,7 @@ private fun isWrongDay(event: Event, startTS: Int, reminderSeconds: Int): Boolea
if (event.repeatInterval == DAY)
return false
val dateTime = Formatter.getDateTimeFromTS(startTS + reminderSeconds)
val power = Math.pow(2.0, (dateTime.dayOfWeek - 1).toDouble()).toInt()
return event.repeatRule and power == 0
return !(startTS + reminderSeconds).isTsOnValidDay(event)
}
private fun getNewTS(ts: Int, isMonthly: Boolean): Int {

View File

@ -0,0 +1,10 @@
package com.simplemobiletools.calendar.extensions
import com.simplemobiletools.calendar.helpers.Formatter
import com.simplemobiletools.calendar.models.Event
fun Int.isTsOnValidDay(event: Event): Boolean {
val dateTime = Formatter.getDateTimeFromTS(this)
val power = Math.pow(2.0, (dateTime.dayOfWeek - 1).toDouble()).toInt()
return event.repeatRule and power != 0
}

View File

@ -10,10 +10,7 @@ import android.database.sqlite.SQLiteQueryBuilder
import android.text.TextUtils
import android.util.SparseIntArray
import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.extensions.config
import com.simplemobiletools.calendar.extensions.scheduleReminder
import com.simplemobiletools.calendar.extensions.seconds
import com.simplemobiletools.calendar.extensions.updateWidgets
import com.simplemobiletools.calendar.extensions.*
import com.simplemobiletools.calendar.models.Event
import com.simplemobiletools.calendar.models.EventType
import com.simplemobiletools.commons.extensions.getIntValue
@ -388,9 +385,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
while (it.startTS < toTS && (it.repeatLimit == 0 || it.repeatLimit >= it.startTS)) {
if (it.startTS >= fromTS) {
if (it.repeatInterval % WEEK == 0) {
val dateTime = Formatter.getDateTimeFromTS(it.startTS)
val power = Math.pow(2.0, (dateTime.dayOfWeek - 1).toDouble()).toInt()
if (it.repeatRule and power != 0) {
if (it.startTS.isTsOnValidDay(it)) {
newEvents.add(it.copy())
}
} else {