fix(app): fully migrate to java.time

This commit is contained in:
Harsh Shandilya 2023-07-22 15:54:11 +05:30
parent bed8ec76e3
commit d37fdfdbaa
3 changed files with 9 additions and 10 deletions

View file

@ -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 */

View file

@ -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]. */

View file

@ -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
)