diff options
author | Harsh Shandilya <me@msfjarvis.dev> | 2023-07-22 15:54:11 +0530 |
---|---|---|
committer | Harsh Shandilya <me@msfjarvis.dev> | 2023-07-22 15:54:11 +0530 |
commit | d37fdfdbaabeab63b994e6f454d94c347e79c761 (patch) | |
tree | 0c94f914469b9185e72c5987156b1b48fb62b12f /app/src/main/java | |
parent | bed8ec76e33c165aa23d48c5f88df1409a9ce2bb (diff) |
fix(app): fully migrate to `java.time`
Diffstat (limited to 'app/src/main/java')
3 files changed, 9 insertions, 10 deletions
diff --git a/app/src/main/java/app/passwordstore/ui/git/log/GitLogAdapter.kt b/app/src/main/java/app/passwordstore/ui/git/log/GitLogAdapter.kt index 29ffbe9b..9b7b77ed 100644 --- a/app/src/main/java/app/passwordstore/ui/git/log/GitLogAdapter.kt +++ b/app/src/main/java/app/passwordstore/ui/git/log/GitLogAdapter.kt @@ -11,8 +11,8 @@ import androidx.recyclerview.widget.RecyclerView import app.passwordstore.databinding.GitLogRowLayoutBinding import app.passwordstore.util.git.GitCommit import app.passwordstore.util.git.GitLogModel -import java.text.DateFormat -import java.util.Date +import java.time.Instant +import java.time.format.DateTimeFormatter import logcat.LogPriority.ERROR import logcat.logcat @@ -20,8 +20,8 @@ private fun shortHash(hash: String): String { return hash.substring(0 until 8) } -private fun stringFrom(date: Date): String { - return DateFormat.getDateTimeInstance().format(date) +private fun stringFrom(date: Instant): String { + return DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(date) } /** @see GitLogActivity */ diff --git a/app/src/main/java/app/passwordstore/util/extensions/Extensions.kt b/app/src/main/java/app/passwordstore/util/extensions/Extensions.kt index c0b40aa4..c6fd9ceb 100644 --- a/app/src/main/java/app/passwordstore/util/extensions/Extensions.kt +++ b/app/src/main/java/app/passwordstore/util/extensions/Extensions.kt @@ -10,7 +10,7 @@ import com.github.michaelbull.result.Result import com.github.michaelbull.result.getOrElse import com.github.michaelbull.result.runCatching import java.io.File -import java.util.Date +import java.time.Instant import logcat.asLog import org.eclipse.jgit.lib.ObjectId import org.eclipse.jgit.revwalk.RevCommit @@ -57,11 +57,10 @@ val RevCommit.hash: String * * @see RevCommit.commitTime */ -val RevCommit.time: Date +val RevCommit.time: Instant get() { val epochSeconds = commitTime.toLong() - val epochMilliseconds = epochSeconds * 1000 - return Date(epochMilliseconds) + return Instant.ofEpochSecond(epochSeconds) } /** Alias to [lazy] with thread safety mode always set to [LazyThreadSafetyMode.NONE]. */ diff --git a/app/src/main/java/app/passwordstore/util/git/GitCommit.kt b/app/src/main/java/app/passwordstore/util/git/GitCommit.kt index 0a5d2020..559b0e4a 100644 --- a/app/src/main/java/app/passwordstore/util/git/GitCommit.kt +++ b/app/src/main/java/app/passwordstore/util/git/GitCommit.kt @@ -5,7 +5,7 @@ package app.passwordstore.util.git -import java.util.Date +import java.time.Instant /** * Basic information about a git commit. @@ -19,5 +19,5 @@ data class GitCommit( val hash: String, val shortMessage: String, val authorName: String, - val time: Date + val time: Instant ) |