Skip to content

Commit

Permalink
Displaying report timestamp on home page to make that more prevalent.…
Browse files Browse the repository at this point in the history
… Also sharing date formatting utility with the nav section.
  • Loading branch information
handstandsam committed Nov 6, 2024
1 parent 4f36dac commit 07326ea
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
1 change: 1 addition & 0 deletions invert-report/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ kotlin {
api(project(":invert-models"))
api(libs.kotlinx.serialization.json)
api(libs.kotlinx.coroutines.core)
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.4.1")
api("org.jetbrains.kotlinx:kotlinx-html-js:0.9.1")
api(compose.html.core)
api(compose.runtime)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.squareup.invert.common.ReportDataRepo
import com.squareup.invert.common.navigation.NavPage
import com.squareup.invert.common.navigation.NavRouteRepo
import com.squareup.invert.common.navigation.routes.BaseNavRoute
import com.squareup.invert.common.utils.FormattingUtils.dateDisplayStr
import com.squareup.invert.common.utils.FormattingUtils.formatDecimalSeparator
import kotlinx.coroutines.flow.map
import org.jetbrains.compose.web.attributes.ATarget
Expand Down Expand Up @@ -88,6 +89,7 @@ fun HomeComposable(
A(href = commitUrl, { target(ATarget.Blank) }) {
Text(gitSha.substring(0, minOf(7, gitSha.length)))
}
Text(" on " + metadata.dateDisplayStr())
}
if (metadata.branchName != metadata.currentBranch) {
P({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
package com.squareup.invert.common.utils

import com.squareup.invert.models.js.MetadataJsReportModel
import kotlinx.datetime.Instant
import kotlinx.datetime.TimeZone
import kotlinx.datetime.toLocalDateTime

object FormattingUtils {
fun Int.formatDecimalSeparator(): String {
return toString()
.reversed()
.chunked(3)
.joinToString(",")
.reversed()
}
fun Int.formatDecimalSeparator(): String {
return toString()
.reversed()
.chunked(3)
.joinToString(",")
.reversed()
}

internal fun MetadataJsReportModel.dateDisplayStr(): String {
val instant = Instant.fromEpochSeconds(time)
val timeZone = TimeZone.currentSystemDefault()
val dateTime = instant.toLocalDateTime(timeZone)

// Format the date and time in the desired format
val formattedDate = "${
dateTime.month.name.lowercase().replaceFirstChar { it.uppercase() }
} ${dateTime.dayOfMonth}, ${dateTime.year} at " +
"${dateTime.hour.toString().padStart(2, '0')}:${
dateTime.minute.toString().padStart(2, '0')
}:${dateTime.second.toString().padStart(2, '0')} ($timezoneId)"

return formattedDate
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.squareup.invert.common.navigation.NavRoute
import com.squareup.invert.common.navigation.NavRouteRepo
import com.squareup.invert.common.pages.AllStatsReportPage
import com.squareup.invert.common.pages.StatDetailNavRoute
import com.squareup.invert.common.utils.FormattingUtils.dateDisplayStr
import com.squareup.invert.models.StatMetadata
import com.squareup.invert.models.js.CollectedStatTotalsJsReportModel
import org.jetbrains.compose.web.attributes.ATarget.Blank
Expand Down Expand Up @@ -142,9 +143,7 @@ fun LeftNavigationComposable(
}
}
Br()
Text("${metadata.timeStr}")
Br()
Text("(${metadata.timezoneId})")
Text(metadata.dateDisplayStr())
Br()
Br()
Br()
Expand Down

0 comments on commit 07326ea

Please sign in to comment.