diff --git a/database/impl/src/androidTest/java/info/nightscout/database/impl/HeartRateDaoTest.kt b/database/impl/src/androidTest/java/info/nightscout/database/impl/HeartRateDaoTest.kt index 29e94cccc1..dcd3e6bb6a 100644 --- a/database/impl/src/androidTest/java/info/nightscout/database/impl/HeartRateDaoTest.kt +++ b/database/impl/src/androidTest/java/info/nightscout/database/impl/HeartRateDaoTest.kt @@ -92,8 +92,26 @@ internal class HeartRateDaoTest { } } - companion object { + @Test + fun getFromTimeToTime() { + createDatabase().use { db -> + val dao = db.heartRateDao + val timestamp = System.currentTimeMillis() + val hr1 = createHeartRate(timestamp = timestamp, beatsPerMinute = 80.0) + val hr2 = createHeartRate(timestamp = timestamp + 1, beatsPerMinute = 150.0) + val hr3 = createHeartRate(timestamp = timestamp + 2, beatsPerMinute = 160.0) + dao.insertNewEntry(hr1) + dao.insertNewEntry(hr2) + dao.insertNewEntry(hr3) + assertEquals(listOf(hr1, hr2, hr3), dao.getFromTimeToTime(timestamp, timestamp + 2)) + assertEquals(listOf(hr1, hr2), dao.getFromTimeToTime(timestamp, timestamp + 1)) + assertEquals(listOf(hr2), dao.getFromTimeToTime(timestamp + 1, timestamp + 1)) + assertTrue(dao.getFromTimeToTime(timestamp + 3, timestamp + 10).isEmpty()) + } + } + + companion object { private const val TEST_DB_NAME = "testDatabase" fun createHeartRate(timestamp: Long? = null, beatsPerMinute: Double = 80.0) = diff --git a/database/impl/src/main/java/info/nightscout/database/impl/AppRepository.kt b/database/impl/src/main/java/info/nightscout/database/impl/AppRepository.kt index 91b4863668..12e1c629cc 100644 --- a/database/impl/src/main/java/info/nightscout/database/impl/AppRepository.kt +++ b/database/impl/src/main/java/info/nightscout/database/impl/AppRepository.kt @@ -934,6 +934,9 @@ import kotlin.math.roundToInt fun getHeartRatesFromTime(timeMillis: Long) = database.heartRateDao.getFromTime(timeMillis) + fun getHeartRatesFromTimeToTime(startMillis: Long, endMillis: Long) = + database.heartRateDao.getFromTimeToTime(startMillis, endMillis) + suspend fun collectNewEntriesSince(since: Long, until: Long, limit: Int, offset: Int) = NewEntries( apsResults = database.apsResultDao.getNewEntriesSince(since, until, limit, offset), apsResultLinks = database.apsResultLinkDao.getNewEntriesSince(since, until, limit, offset), diff --git a/database/impl/src/main/java/info/nightscout/database/impl/daos/HeartRateDao.kt b/database/impl/src/main/java/info/nightscout/database/impl/daos/HeartRateDao.kt index 516a8025d7..82ce3f3c38 100644 --- a/database/impl/src/main/java/info/nightscout/database/impl/daos/HeartRateDao.kt +++ b/database/impl/src/main/java/info/nightscout/database/impl/daos/HeartRateDao.kt @@ -23,6 +23,9 @@ internal interface HeartRateDao : TraceableDao { @Query("SELECT * FROM $TABLE_HEART_RATE WHERE timestamp >= :timestamp ORDER BY timestamp") fun getFromTime(timestamp: Long): List + @Query("SELECT * FROM $TABLE_HEART_RATE WHERE timestamp BETWEEN :startMillis AND :endMillis ORDER BY timestamp") + fun getFromTimeToTime(startMillis: Long, endMillis: Long): List + @Query("SELECT * FROM $TABLE_HEART_RATE WHERE timestamp > :since AND timestamp <= :until LIMIT :limit OFFSET :offset") fun getNewEntriesSince(since: Long, until: Long, limit: Int, offset: Int): List }