Show match finish times in the browser timezone
CI / Build and push docker image (push) Successful in 2m18s
CI / Build and push docker image (push) Successful in 2m18s
The history table truncated finished_at, which the API serializes in UTC, so the Finished column always showed UTC wall time. Parse the timestamp with the browser's Date and render its local components, keeping the existing YYYY-MM-DD HH:MM layout.
This commit is contained in:
@@ -68,6 +68,23 @@ fn game_name(game_types: &[GameTypeInfo], game_type: &str) -> String {
|
||||
.unwrap_or_else(|| game_type.to_string())
|
||||
}
|
||||
|
||||
/// The match's finish instant in the browser's local timezone, as
|
||||
/// `YYYY-MM-DD HH:MM`. Falls back to the raw UTC prefix when the browser
|
||||
/// cannot parse the timestamp.
|
||||
fn local_finished(iso: &str) -> String {
|
||||
let date = js_sys::Date::new(&wasm_bindgen::JsValue::from_str(iso));
|
||||
if date.get_time().is_nan() {
|
||||
return iso.replace('T', " ").chars().take(16).collect();
|
||||
}
|
||||
crate::model::fmt_datetime_parts(
|
||||
date.get_full_year(),
|
||||
date.get_month(),
|
||||
date.get_date(),
|
||||
date.get_hours(),
|
||||
date.get_minutes(),
|
||||
)
|
||||
}
|
||||
|
||||
#[component]
|
||||
pub fn HistoryPage() -> View {
|
||||
let page = create_signal(Option::<MatchesPage>::None);
|
||||
@@ -131,12 +148,7 @@ pub fn HistoryPage() -> View {
|
||||
.get_clone()
|
||||
.into_iter()
|
||||
.map(|m| {
|
||||
let finished = m
|
||||
.finished_at
|
||||
.replace('T', " ")
|
||||
.chars()
|
||||
.take(16)
|
||||
.collect::<String>();
|
||||
let finished = local_finished(&m.finished_at);
|
||||
let game = game_name(&names, &m.game_type);
|
||||
let mut cells: Vec<View> = team_columns(&m)
|
||||
.iter()
|
||||
|
||||
Reference in New Issue
Block a user