Skip to content
Snippets Groups Projects
Unverified Commit 4580c7ac authored by Philipp Woessner's avatar Philipp Woessner Committed by GitHub
Browse files

changed timevariables constants to new values and deleted unused DateAndTime...

changed timevariables constants to new values and deleted unused DateAndTime helper functions (#180)
parent a9043b3d
No related branches found
No related tags found
No related merge requests found
...@@ -76,14 +76,14 @@ object TimeVariables { ...@@ -76,14 +76,14 @@ object TimeVariables {
/** /**
* The timeRange until the calculated exposure figures are rated as stale. * The timeRange until the calculated exposure figures are rated as stale.
* In days. * In hours.
*/ */
private const val MAX_STALE_EXPOSURE_RISK_RANGE = 1 private const val MAX_STALE_EXPOSURE_RISK_RANGE = 48
/** /**
* Getter function for [MAX_STALE_EXPOSURE_RISK_RANGE] * Getter function for [MAX_STALE_EXPOSURE_RISK_RANGE]
* *
* @return stale threshold in days * @return stale threshold in hours
*/ */
fun getMaxStaleExposureRiskRange(): Int = MAX_STALE_EXPOSURE_RISK_RANGE fun getMaxStaleExposureRiskRange(): Int = MAX_STALE_EXPOSURE_RISK_RANGE
...@@ -106,6 +106,7 @@ object TimeVariables { ...@@ -106,6 +106,7 @@ object TimeVariables {
* Internal requirements: 2 hours = 7200000 milliseconds * Internal requirements: 2 hours = 7200000 milliseconds
* Test value: 1 minute * Test value: 1 minute
*/ */
// todo exchange with real value (currently 120 min)
private const val MANUAL_KEY_RETRIEVAL_DELAY = 60000L private const val MANUAL_KEY_RETRIEVAL_DELAY = 60000L
/** /**
......
...@@ -33,7 +33,6 @@ import de.rki.coronawarnapp.transaction.RiskLevelTransaction.RiskLevelTransactio ...@@ -33,7 +33,6 @@ import de.rki.coronawarnapp.transaction.RiskLevelTransaction.RiskLevelTransactio
import de.rki.coronawarnapp.transaction.RiskLevelTransaction.RiskLevelTransactionState.RETRIEVE_APPLICATION_CONFIG import de.rki.coronawarnapp.transaction.RiskLevelTransaction.RiskLevelTransactionState.RETRIEVE_APPLICATION_CONFIG
import de.rki.coronawarnapp.transaction.RiskLevelTransaction.RiskLevelTransactionState.RETRIEVE_EXPOSURE_SUMMARY import de.rki.coronawarnapp.transaction.RiskLevelTransaction.RiskLevelTransactionState.RETRIEVE_EXPOSURE_SUMMARY
import de.rki.coronawarnapp.transaction.RiskLevelTransaction.RiskLevelTransactionState.UPDATE_RISK_LEVEL import de.rki.coronawarnapp.transaction.RiskLevelTransaction.RiskLevelTransactionState.UPDATE_RISK_LEVEL
import de.rki.coronawarnapp.util.TimeAndDateExtensions.millisecondsToDays
import de.rki.coronawarnapp.util.TimeAndDateExtensions.millisecondsToHours import de.rki.coronawarnapp.util.TimeAndDateExtensions.millisecondsToHours
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
...@@ -284,7 +283,7 @@ object RiskLevelTransaction : Transaction() { ...@@ -284,7 +283,7 @@ object RiskLevelTransaction : Transaction() {
/** we only return outdated risk level if the threshold is reached AND the active tracing time is above the /** we only return outdated risk level if the threshold is reached AND the active tracing time is above the
defined threshold because [UNKNOWN_RISK_INITIAL] overrules [UNKNOWN_RISK_OUTDATED_RESULTS] */ defined threshold because [UNKNOWN_RISK_INITIAL] overrules [UNKNOWN_RISK_OUTDATED_RESULTS] */
if (timeSinceLastDiagnosisKeyFetchFromServer.millisecondsToDays() > if (timeSinceLastDiagnosisKeyFetchFromServer.millisecondsToHours() >
TimeVariables.getMaxStaleExposureRiskRange() && isActiveTracingTimeAboveThreshold() TimeVariables.getMaxStaleExposureRiskRange() && isActiveTracingTimeAboveThreshold()
) { ) {
return@executeState UNKNOWN_RISK_OUTDATED_RESULTS.also { return@executeState UNKNOWN_RISK_OUTDATED_RESULTS.also {
......
...@@ -2,7 +2,6 @@ package de.rki.coronawarnapp.util ...@@ -2,7 +2,6 @@ package de.rki.coronawarnapp.util
import org.joda.time.DateTime import org.joda.time.DateTime
import org.joda.time.DateTimeZone import org.joda.time.DateTimeZone
import org.joda.time.Instant
import org.joda.time.chrono.GJChronology import org.joda.time.chrono.GJChronology
import org.joda.time.format.DateTimeFormat import org.joda.time.format.DateTimeFormat
import java.util.Date import java.util.Date
...@@ -14,12 +13,6 @@ object TimeAndDateExtensions { ...@@ -14,12 +13,6 @@ object TimeAndDateExtensions {
private const val MS_TO_HOURS = (1000 * 60 * 60) private const val MS_TO_HOURS = (1000 * 60 * 60)
private const val MS_TO_SECONDS = 1000 private const val MS_TO_SECONDS = 1000
fun getCurrentHourUTC(): Int = DateTime(Instant.now(), DateTimeZone.UTC).hourOfDay().get()
fun Date.getHourFromUTCDate(): Int = DateTime(this, DateTimeZone.UTC).hourOfDay().get()
fun String.toMillis(): Long? = DateTime.parse(this).millis
fun Date.toServerFormat(): String = fun Date.toServerFormat(): String =
DateTimeFormat.forPattern("yyyy-MM-dd").withChronology(GJChronology.getInstance()) DateTimeFormat.forPattern("yyyy-MM-dd").withChronology(GJChronology.getInstance())
.withZoneUTC() .withZoneUTC()
...@@ -31,10 +24,6 @@ object TimeAndDateExtensions { ...@@ -31,10 +24,6 @@ object TimeAndDateExtensions {
return this.div(MS_TO_SECONDS) return this.div(MS_TO_SECONDS)
} }
fun Long.millisecondsToDays(): Long {
return this.div(MS_TO_DAYS)
}
fun Long.millisecondsToHours(): Long { fun Long.millisecondsToHours(): Long {
return this.div(MS_TO_HOURS) return this.div(MS_TO_HOURS)
} }
......
...@@ -118,14 +118,15 @@ class RiskLevelTransactionTest { ...@@ -118,14 +118,15 @@ class RiskLevelTransactionTest {
val testRiskLevel = UNKNOWN_RISK_OUTDATED_RESULTS val testRiskLevel = UNKNOWN_RISK_OUTDATED_RESULTS
val twoDaysAboveMaxStale = TimeUnit.DAYS.toMillis(TimeVariables.getMaxStaleExposureRiskRange().plus(2).toLong()) val twoHoursAboveMaxStale =
TimeUnit.HOURS.toMillis(TimeVariables.getMaxStaleExposureRiskRange().plus(2).toLong())
// tracing is activated // tracing is activated
coEvery { InternalExposureNotificationClient.asyncIsEnabled() } returns true coEvery { InternalExposureNotificationClient.asyncIsEnabled() } returns true
// the last time we fetched keys from the server is above the threshold // the last time we fetched keys from the server is above the threshold
every { TimeVariables.getLastTimeDiagnosisKeysFromServerFetch() } returns System.currentTimeMillis() every { TimeVariables.getLastTimeDiagnosisKeysFromServerFetch() } returns System.currentTimeMillis()
.minus(twoDaysAboveMaxStale) .minus(twoHoursAboveMaxStale)
// active tracing time is 1h above the threshold // active tracing time is 1h above the threshold
every { TimeVariables.getTimeActiveTracingDuration() } returns TimeUnit.HOURS.toMillis( every { TimeVariables.getTimeActiveTracingDuration() } returns TimeUnit.HOURS.toMillis(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment