diff --git a/app/src/main/kotlin/jackall/moncalc/db/QuestRecordRealmHelper.kt b/app/src/main/kotlin/jackall/moncalc/db/QuestRecordRealmHelper.kt index abe39c5..a19eab0 100644 --- a/app/src/main/kotlin/jackall/moncalc/db/QuestRecordRealmHelper.kt +++ b/app/src/main/kotlin/jackall/moncalc/db/QuestRecordRealmHelper.kt @@ -3,6 +3,7 @@ import io.realm.RealmResults import jackall.moncalc.vo.QuestRecord import java.util.* +import kotlin.collections.LinkedHashMap /** * Created by matsumoto_k on 2017/11/03. @@ -123,6 +124,28 @@ val yesterday = Calendar.getInstance().apply { add(Calendar.DATE, -7) } return realm.where(QuestRecord::class.java).greaterThan("createAt", yesterday.time).sum("dropCount").toInt() } + + fun countTempleDaysAgo(priod: Int): LinkedHashMap { + val end = Calendar.getInstance() + end.set(Calendar.HOUR, 12) + end.set(Calendar.MINUTE, 0) + end.set(Calendar.SECOND, 0) + val start = Calendar.getInstance().apply { + time = end.time + add(Calendar.DATE, -1) + } + val results = LinkedHashMap() + var count = 0 + + for (i in 0 until priod) { + count = realm.where(QuestRecord::class.java).between("createAt", start.time, end.time).findAll().count() + if (count > 0) + results.put(start.time, count) + start.apply { add(Calendar.DATE, -1) } + end.apply { add(Calendar.DATE, -1) } + } + return results + } // // fun findByPeriod(period: Int): ArrayList { // val startCalender = Calendar.getInstance()