From ff7ef52c20eb6d6fb632f4a51be52a20a72733d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=80=A7=E9=A9=8A?= Date: Wed, 11 Nov 2026 13:54:59 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=88=E6=9C=AC:=20the=20phone=20shows=20the?= =?UTF-8?q?=20build=20time=20in=20its=20own=20time=20zone,=20not=20the=20s?= =?UTF-8?q?erver's=20UTC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- mobile/index.html | 8 +++++++- src/app/remote_ui.rs | 2 +- src/version.rs | 12 ++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/mobile/index.html b/mobile/index.html index e6fc3d8..db70b26 100644 --- a/mobile/index.html +++ b/mobile/index.html @@ -614,6 +614,12 @@ function ago(ms) { return `${d.getMonth() + 1}/${d.getDate()}`; } function clock(ms) { return ms ? new Date(ms).toLocaleTimeString("zh-TW", {hour: "numeric", minute: "2-digit"}) : ""; } +// "2026-11-11 13:52" in this phone's time zone (the brain may be a server running in UTC). +function stamp(ms) { + if (typeof ms !== "number") return String(ms ?? ""); + const d = new Date(ms), p = (n) => String(n).padStart(2, "0"); + return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}`; +} function dayLabel(ms) { const d = new Date(ms), now = new Date(), y = new Date(now); y.setDate(now.getDate() - 1); if (d.toDateString() === now.toDateString()) return "今天"; @@ -1826,7 +1832,7 @@ function drawSettings(kind, quiet) { h += group("這支手機", acts.join("")); } if (kind === "updates") { - h += group("", item({icon: "info", k: "版本", v: st.built ? `${st.built} 建置` : "", r: st.version || ""}) + (st.newer ? item({icon: "download", k: "有新版", v: "電腦上的 AnyBot 已經下載新版,重新啟動就會換上"}) : item({icon: "circle-check", k: "已是最新版"}))); + h += group("", item({icon: "info", k: "版本", v: st.built ? `${stamp(st.built)} 建置` : "", r: st.version || ""}) + (st.newer ? item({icon: "download", k: "有新版", v: "電腦上的 AnyBot 已經下載新版,重新啟動就會換上"}) : item({icon: "circle-check", k: "已是最新版"}))); h += `
Bot 的電腦的更新在「電腦」裡。
`; } el.innerHTML = h + `
`; diff --git a/src/app/remote_ui.rs b/src/app/remote_ui.rs index 67f0e23..fa29af3 100644 --- a/src/app/remote_ui.rs +++ b/src/app/remote_ui.rs @@ -1374,7 +1374,7 @@ impl App { let log = crate::cloudbox::log_lines(); let mut out = json!({ "role": if owner { "owner" } else { "admin" }, - "host": st.remote.host_name, "version": crate::version::LABEL, "built": crate::version::time_label(self.exe_built), "newer": self.newer_build.is_some(), + "host": st.remote.host_name, "version": crate::version::LABEL, "built": crate::version::epoch_ms(self.exe_built), "newer": self.newer_build.is_some(), "theme": match st.theme { Theme::Light => "light", Theme::Dark => "dark", Theme::System => "system" }, "accent": serde_json::to_value(st.accent).unwrap_or_default(), "timezone": st.timezone, "notify": st.notify, "language": st.language, diff --git a/src/version.rs b/src/version.rs index 520c837..765ed68 100644 --- a/src/version.rs +++ b/src/version.rs @@ -16,6 +16,12 @@ pub fn time_label(t: Option) -> String { t.map(|t| chrono::DateTime::::from(t).format("%Y-%m-%d %H:%M").to_string()).unwrap_or_else(|| "?".into()) } +/// Milliseconds since 1970, for the phone: it shows the time in its own zone (a server's container +/// runs in UTC, so its own "local time" would be hours off for the person reading it). +pub fn epoch_ms(t: Option) -> Option { + t.and_then(|t| t.duration_since(SystemTime::UNIX_EPOCH).ok()).map(|d| d.as_millis() as u64) +} + /// "v0.0.1-36bc2be · 2026-11-11 14:20": the version and when this build was made. pub fn full(built: Option) -> String { match built { @@ -43,4 +49,10 @@ mod tests { let s = full(Some(SystemTime::UNIX_EPOCH)); assert!(s.starts_with(&format!("{LABEL} · ")) && s.len() > LABEL.len() + 10, "{s}"); } + + #[test] + fn epoch_ms_for_the_phone() { + assert_eq!(epoch_ms(None), None); + assert_eq!(epoch_ms(Some(SystemTime::UNIX_EPOCH + std::time::Duration::from_millis(1500))), Some(1500)); + } }