add a helper function for checking proper week at weekly repeating events
This commit is contained in:
parent
6a72e746a5
commit
63d39f05e6
|
@ -402,11 +402,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
if (event.startTS >= fromTS) {
|
||||
if (event.repeatInterval % WEEK == 0) {
|
||||
if (event.startTS.isTsOnProperDay(event)) {
|
||||
val initialWeekOfYear = Formatter.getDateTimeFromTS(startTimes[event.id]).weekOfWeekyear
|
||||
val currentWeekOfYear = Formatter.getDateTimeFromTS(event.startTS).weekOfWeekyear
|
||||
|
||||
// check if its the proper week, for events repeating by x weeks
|
||||
if ((currentWeekOfYear - initialWeekOfYear) % (event.repeatInterval / WEEK) == 0) {
|
||||
if (isOnProperWeek(event, startTimes)) {
|
||||
events.add(event.copy())
|
||||
}
|
||||
}
|
||||
|
@ -426,11 +422,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
while (event.repeatLimit < 0 && event.endTS < toTS) {
|
||||
if (event.repeatInterval != 0 && event.repeatInterval % WEEK == 0) {
|
||||
if (event.startTS.isTsOnProperDay(event)) {
|
||||
val initialWeekOfYear = Formatter.getDateTimeFromTS(startTimes[event.id]).weekOfWeekyear
|
||||
val currentWeekOfYear = Formatter.getDateTimeFromTS(event.startTS).weekOfWeekyear
|
||||
|
||||
// check if its the proper week, for events repeating by x weeks
|
||||
if ((currentWeekOfYear - initialWeekOfYear) % (event.repeatInterval / WEEK) == 0) {
|
||||
if (isOnProperWeek(event, startTimes)) {
|
||||
if (event.startTS >= fromTS && event.startTS < toTS) {
|
||||
events.add(event.copy())
|
||||
}
|
||||
|
@ -449,6 +441,13 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||
return events
|
||||
}
|
||||
|
||||
// check if its the proper week, for events repeating by x weeks
|
||||
private fun isOnProperWeek(event: Event, startTimes: SparseIntArray): Boolean {
|
||||
val initialWeekOfYear = Formatter.getDateTimeFromTS(startTimes[event.id]).weekOfWeekyear
|
||||
val currentWeekOfYear = Formatter.getDateTimeFromTS(event.startTS).weekOfWeekyear
|
||||
return (currentWeekOfYear - initialWeekOfYear) % (event.repeatInterval / WEEK) == 0
|
||||
}
|
||||
|
||||
fun getRunningEvents(): List<Event> {
|
||||
val events = ArrayList<Event>()
|
||||
val ts = (System.currentTimeMillis() / 1000).toInt()
|
||||
|
|
Loading…
Reference in New Issue