版本: the phone shows the build time in its own time zone, not the server's UTC
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
9d6b346462
commit
ff7ef52c20
|
|
@ -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 += `<div class="note">Bot 的電腦的更新在「電腦」裡。</div>`;
|
||||
}
|
||||
el.innerHTML = h + `<div style="height:calc(var(--safe-b) + 24px)"></div>`;
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -16,6 +16,12 @@ pub fn time_label(t: Option<SystemTime>) -> String {
|
|||
t.map(|t| chrono::DateTime::<chrono::Local>::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<SystemTime>) -> Option<u64> {
|
||||
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<SystemTime>) -> 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));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue