This repository was archived by the owner on Jun 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 487
Fix: Installation time (EXPOSUREAPP-14249) #5665
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
21 changes: 8 additions & 13 deletions
21
Corona-Warn-App/src/main/java/de/rki/coronawarnapp/installTime/InstallTimeProvider.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,25 @@ | ||
package de.rki.coronawarnapp.installTime | ||
|
||
import android.content.Context | ||
import de.rki.coronawarnapp.util.di.AppContext | ||
import de.rki.coronawarnapp.util.TimeStamper | ||
import de.rki.coronawarnapp.util.di.AppInstallTime | ||
import de.rki.coronawarnapp.util.toLocalDateUserTz | ||
import java.time.Instant | ||
import java.time.LocalDate | ||
import java.time.Period | ||
import java.time.temporal.ChronoUnit | ||
|
||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
|
||
@Singleton | ||
class InstallTimeProvider @Inject constructor( | ||
@AppContext private val context: Context | ||
@AppInstallTime private val installTime: Instant, | ||
private val timeStamper: TimeStamper | ||
) { | ||
private val dayOfInstallation: LocalDate = Instant.ofEpochMilli( | ||
context | ||
.packageManager | ||
.getPackageInfo(context.packageName, 0) | ||
.firstInstallTime | ||
) | ||
.toLocalDateUserTz() | ||
private val dayOfInstallation = installTime.toLocalDateUserTz() | ||
|
||
val today: LocalDate | ||
get() = Instant.now().toLocalDateUserTz() | ||
get() = timeStamper.nowUTC.toLocalDateUserTz() | ||
|
||
val daysSinceInstallation: Int | ||
get() = Period.between(dayOfInstallation, today).days | ||
get() = ChronoUnit.DAYS.between(dayOfInstallation, today).toInt() | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
Corona-Warn-App/src/test/java/de/rki/coronawarnapp/installTime/InstallTimeProviderTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package de.rki.coronawarnapp.installTime | ||
|
||
import de.rki.coronawarnapp.util.TimeStamper | ||
import io.kotest.matchers.shouldBe | ||
import io.mockk.MockKAnnotations | ||
import io.mockk.every | ||
import io.mockk.impl.annotations.MockK | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
import testhelpers.BaseTest | ||
import java.time.Instant | ||
|
||
internal class InstallTimeProviderTest : BaseTest() { | ||
@MockK lateinit var timeStamper: TimeStamper | ||
|
||
@BeforeEach | ||
fun setup() { | ||
MockKAnnotations.init(this) | ||
} | ||
|
||
@Test | ||
fun `Days since installation across years`() { | ||
every { timeStamper.nowUTC } returns Instant.parse("2022-11-03T05:35:16.000Z") | ||
|
||
InstallTimeProvider( | ||
installTime = Instant.parse("2020-11-03T05:35:16.000Z"), | ||
timeStamper = timeStamper | ||
).daysSinceInstallation shouldBe 730 | ||
} | ||
|
||
@Test | ||
fun `Days since installation across months`() { | ||
every { timeStamper.nowUTC } returns Instant.parse("2020-12-03T05:35:16.000Z") | ||
|
||
InstallTimeProvider( | ||
installTime = Instant.parse("2020-11-03T05:35:16.000Z"), | ||
timeStamper = timeStamper | ||
).daysSinceInstallation shouldBe 30 | ||
} | ||
|
||
@Test | ||
fun `Days since installation across days`() { | ||
every { timeStamper.nowUTC } returns Instant.parse("2022-11-03T05:35:16.000Z") | ||
|
||
InstallTimeProvider( | ||
installTime = Instant.parse("2022-10-24T05:35:16.000Z"), | ||
timeStamper = timeStamper | ||
).daysSinceInstallation shouldBe 10 | ||
} | ||
|
||
@Test | ||
fun `Days since installation same day`() { | ||
every { timeStamper.nowUTC } returns Instant.parse("2022-11-03T18:35:16.000Z") | ||
|
||
InstallTimeProvider( | ||
installTime = Instant.parse("2022-11-03T05:35:16.000Z"), | ||
timeStamper = timeStamper | ||
).daysSinceInstallation shouldBe 0 | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.