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.startTS >= fromTS) {
|
||||||
if (event.repeatInterval % WEEK == 0) {
|
if (event.repeatInterval % WEEK == 0) {
|
||||||
if (event.startTS.isTsOnProperDay(event)) {
|
if (event.startTS.isTsOnProperDay(event)) {
|
||||||
val initialWeekOfYear = Formatter.getDateTimeFromTS(startTimes[event.id]).weekOfWeekyear
|
if (isOnProperWeek(event, startTimes)) {
|
||||||
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) {
|
|
||||||
events.add(event.copy())
|
events.add(event.copy())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -426,11 +422,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
||||||
while (event.repeatLimit < 0 && event.endTS < toTS) {
|
while (event.repeatLimit < 0 && event.endTS < toTS) {
|
||||||
if (event.repeatInterval != 0 && event.repeatInterval % WEEK == 0) {
|
if (event.repeatInterval != 0 && event.repeatInterval % WEEK == 0) {
|
||||||
if (event.startTS.isTsOnProperDay(event)) {
|
if (event.startTS.isTsOnProperDay(event)) {
|
||||||
val initialWeekOfYear = Formatter.getDateTimeFromTS(startTimes[event.id]).weekOfWeekyear
|
if (isOnProperWeek(event, startTimes)) {
|
||||||
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 (event.startTS >= fromTS && event.startTS < toTS) {
|
if (event.startTS >= fromTS && event.startTS < toTS) {
|
||||||
events.add(event.copy())
|
events.add(event.copy())
|
||||||
}
|
}
|
||||||
|
@ -449,6 +441,13 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
||||||
return events
|
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> {
|
fun getRunningEvents(): List<Event> {
|
||||||
val events = ArrayList<Event>()
|
val events = ArrayList<Event>()
|
||||||
val ts = (System.currentTimeMillis() / 1000).toInt()
|
val ts = (System.currentTimeMillis() / 1000).toInt()
|
||||||
|
|
Loading…
Reference in New Issue