Skip to content

Commit

Permalink
Fix build time zone in about screen
Browse files Browse the repository at this point in the history
And slight cleanup
  • Loading branch information
AntsyLich committed Apr 6, 2024
1 parent d77f2f4 commit aed53d3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ import tachiyomi.presentation.core.icons.Reddit
import tachiyomi.presentation.core.icons.X
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import java.time.Instant
import java.time.LocalDateTime
import java.time.ZoneId
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
import java.util.Locale

Expand Down Expand Up @@ -269,11 +271,15 @@ object AboutScreen : Screen() {

internal fun getFormattedBuildTime(): String {
return try {
val df = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm'Z'", Locale.US)
.withZone(ZoneId.of("UTC"))
val buildTime = LocalDateTime.from(df.parse(BuildConfig.BUILD_TIME))

buildTime!!.toDateTimestampString(UiPreferences.dateFormat(Injekt.get<UiPreferences>().dateFormat().get()))
LocalDateTime.ofInstant(
Instant.parse(BuildConfig.BUILD_TIME),
ZoneId.systemDefault(),
)
.toDateTimestampString(
UiPreferences.dateFormat(
Injekt.get<UiPreferences>().dateFormat().get(),
),
)
} catch (e: Exception) {
BuildConfig.BUILD_TIME
}
Expand Down
15 changes: 8 additions & 7 deletions buildSrc/src/main/kotlin/Commands.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import org.gradle.api.Project
import java.io.ByteArrayOutputStream
import java.text.SimpleDateFormat
import java.util.TimeZone
import java.util.Date
import java.time.LocalDateTime
import java.time.ZoneOffset
import java.time.format.DateTimeFormatter

// Git is needed in your system PATH for these commands to work.
// If it's not installed, you can return a random value as a workaround
Expand All @@ -16,10 +16,11 @@ fun Project.getGitSha(): String {
// return "1"
}

private val BUILD_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'")

@Suppress("UnusedReceiverParameter")
fun Project.getBuildTime(): String {
val df = SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'")
df.timeZone = TimeZone.getTimeZone("UTC")
return df.format(Date())
return LocalDateTime.now(ZoneOffset.UTC).format(BUILD_TIME_FORMATTER)
}

fun Project.runCommand(command: String): String {
Expand All @@ -29,4 +30,4 @@ fun Project.runCommand(command: String): String {
standardOutput = byteOut
}
return String(byteOut.toByteArray()).trim()
}
}

0 comments on commit aed53d3

Please sign in to comment.