Skip to content

Commit 51d6395

Browse files
stuartwdouglasCarrotclaudekalvinnchau
authored
feat(profiles): share and show a local time zone (#3332)
## What People can share their local time zone on their community profile, and others see their local time. - **Field:** kind-0 content gains an optional `tz`, an IANA time zone name such as `"America/Los_Angeles"`. Readers ignore it when it's missing or isn't a zone the runtime accepts (`Intl.DateTimeFormat` throws). It's kept exactly as written, because engines canonicalize aliases differently (for example, Node returns `Asia/Calcutta` for `Asia/Kolkata`). - **Shared by default:** once per launch per community, the fresh read of your own profile that the profile button already makes acts as the trigger. When it shows a profile with **no `tz` key at all**, a strong read (`inspectProfile`, the read Settings uses before saving) runs just before publishing. The skip rules are checked again on that result, and that result plus this device's zone goes through the existing merging writer, so a lagging read never reverts a newer profile. Profiles that already have a `tz` cost no extra read. It never creates a profile, never publishes after a failed or abandoned read, and never publishes when the device zone is unusable. It skips any profile that writer would rewrite (for example a `name` handle that differs from `display_name`), so a background write never renames anyone. It also stands aside while a profile save is running or after one started (`features/communities/profile-saves.ts`, shared with Settings). Joining includes the device zone in the first publication. - **Setting it:** Settings → Profile (community scope) has a **Show my local time on my profile** checkbox and a searchable **Time zone** picker. The picker finds renamed zones under either spelling ("Kolkata" finds `Asia/Calcutta` on engines that list only the old name), always offers `UTC`, and writes the zone exactly as listed. A profile with no `tz` key shows the box checked with this device's zone, with a note that it will be shared, and any save from Settings writes that zone (added only if the read just before publishing still has no `tz`). Unchecking and saving writes `"tz": ""`, an opt-out that readers treat as absent and that sharing by default leaves alone. - **Showing it:** the profile preview and the profile panel header show `3:42 PM local time · 8h ahead`, or `5:42 AM tomorrow local time · 13h 30m ahead` when the calendar dates differ. "tomorrow" and "yesterday" compare the calendar date in each zone. When the dates are two apart (UTC+14 against UTC-11), the label names the weekday instead, in English like the rest of the label. The difference is left out when the clocks match. It handles half-hour and 45-minute zones and each zone's own daylight saving, follows the Appearance hour-cycle setting, and refreshes at each minute boundary while it's on screen. - **No relay, protocol or storage changes.** The relay already stores kind-0 content verbatim. ## Profile writers Both personal-profile write paths already merge into the existing content, so `tz` and other unknown fields survive name, picture and description edits. I didn't change either one: - Native: `src/features/communities/native-api.ts`, the `profile` route (`...profile.existing` first). - Browser host: `browser-host/relay-broker.mjs`, the `/api/relay/profile` route (`...(filters.existing ?? {})` first). - Callers pass the freshly read content: `ProfileSettings.tsx` re-reads it right before publishing, and `join.ts` passes `read.existing`. Settings sets `tz` (or `""` to opt out) in that `existing` object, and only when the time zone control was changed. Sharing by default and joining add `tz` to it only when the key is absent. Not changed: the app-hosted agent profile (`crates/agent-controller/src/app_agent.rs` `profile_event`) rebuilds `{name, bot, picture, about}` from the agent row. The app owns that profile, and nothing in this PR sets `tz` for agents. ## Tests - `src/features/profiles/local-time.test.ts`: daylight saving (US and UK changing on different dates), half-hour and 45-minute offsets, matching clocks, the 24-hour cycle, absent or unknown zones, tomorrow/yesterday, a 2-day gap, and the change at the viewer's midnight. - `src/features/profiles/ProfileLocalTime.test.tsx`: with fake timers, the label changes at the minute boundary (not 60s after mount), and unmounting clears the timer. - `src/features/profiles/TimeZoneField.test.tsx`: "Kolkata", "Kyiv" and "UTC" find and write the listed zone. This fails without the alias filter on V8. - `src/features/profiles/share-time-zone.test.ts`: shares when `tz` is absent and keeps other fields; once per launch; leaves an opt-out, a set zone, an unknown zone and a differing handle alone; never creates a profile; nothing after a failed or aborted read, and the next read retries. It publishes the strong read when the background read is stale, re-checks the skip rules on the strong read, reads strongly only when the trigger would share, and stands aside for a save that is running or that starts during the strong read. The stale-read and save cases fail (5 of 16) when it publishes the background read without re-checking. - `src/app/shell/ProfileButton.test.tsx`: the fresh read of your own profile triggers one `inspectProfile(selected, session)`, and its result plus the device zone goes through `publishProfile`. - `src/app/ProfileSettings.test.tsx`: a profile without `tz` shows checked with the device zone and the "will be shared" note; an unrelated save writes the device zone (fails without the change); unchecking saves `"tz": ""`; checking again after that saves the zone. An unrelated save keeps a saved zone. Unchecking a saved zone writes `"tz": ""`. The first case fails when a missing key shows unchecked. - `src/features/relay/profile-details.test.ts`: the directory notifies on a `tz`-only replacement and drops unknown zones. This fails without the new equality check. - Updated join expectations (`join.test.ts`, `CommunityDialog.test.tsx`, `identity.test.tsx`): the first publication on join includes `tz`. Browser cases added/removed: one added, `tests/browser/account-profile.spec.mjs` "local time shared by default › launch shares the browser's time zone into a profile without one". Browser-only justification: it crosses the profile button's fresh read, the strong read and the browser host's merging `/api/relay/profile` writer, which unit tests stub. It fails when the profile button's share is disabled. The fixture's own profile now carries `"tz": ""` (new `profileTimeZone` option; `null` leaves the key out), so launch doesn't publish a kind 0 into journeys that don't expect one. `new-message.spec.mjs` serves its own viewer profile and carries the same opt-out; without it 4 of its tests fail. Local runs at 197e493: `account-profile.spec.mjs` in chromium and webkit (6/6); CI-failing files in chromium (buzz-links, inbox, live, membership, activity-navigation-focus: 27/27) and webkit (navigation-groups, thread-video, large-channel-unread, live-status: 20/20); `--project chromium-measurements --workers=1` (7/7); settings, hosted-create-join and profiles-appearance in chromium (17/17). Not run locally: the full sharded matrix and WebKit measurements. ## Deferred checks - Rendered check in the native app (both themes, narrow and wide widths, enlarged text, keyboard and pointer use of the picker) hasn't been done yet. - Human test: the opt-in flow from the first commit was tried in the app. Sharing by default, the checked default in Settings, the day marker and alias search haven't been tried yet. - Sharing by default publishes on first launch without jitter. It's at most one write per community per profile, ever, and app upgrades already spread it out. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Stuart Douglas <[email protected]> Signed-off-by: Kalvin Chau <[email protected]> Co-authored-by: Carrot <0aad8f02ba1e9e07ec8e9ee52b865fddc20e872072fd44b32da2f1a9d5447297@remote-agent-pilot.communities.buzz.xyz> Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Kalvin Chau <[email protected]>
1 parent 5228a01 commit 51d6395

32 files changed

Lines changed: 1702 additions & 40 deletions

‎docs/buzz-help.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,18 @@ mention anyone. Explicit agent watches on that room can still receive them.
269269
- Set or clear your status from the profile menu, or with **Update status** /
270270
**Set a status** on your own profile. On a profile or in the profile menu,
271271
hover the status emoji to see its `:name:`.
272+
- Your profile shares your local time by default: joining a community, or
273+
opening one whose profile has never had a time zone, publishes this device's
274+
time zone name, such as `America/Los_Angeles`. Each device does this at most
275+
once per community. To stop, open Settings → **Profile** in that community,
276+
uncheck **Show my local time on my profile** and save. That opt-out is kept in
277+
your profile; if another app rewrites your profile without it, a device that
278+
has never shared there can share once more. Check it again to pick a time
279+
zone. People who share a time zone show their local time on their profile and
280+
its preview, with "tomorrow" or "yesterday" when their date differs from
281+
yours. With **Show time zone details on profiles** on in Settings →
282+
**Appearance**, it also shows how far ahead or behind you they are and their
283+
time zone name.
272284
- Where a community verifies names, the profile check appears beside the verified
273285
full name, or the verified username when no full name is supplied. The profile
274286
shows the issuer and verification time; cached verification has no check.

‎src/app/AppearanceSettings.test.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ afterEach(() => {
6060
hourCycle: "system",
6161
seconds: false,
6262
messageTimestamps: "show",
63+
localTimeDetails: true,
6364
});
6465
localStorage.clear();
6566
vi.unstubAllGlobals();
@@ -425,7 +426,7 @@ it("preserves follow-up choice and save recovery when Appearance is hidden", asy
425426
);
426427
});
427428

428-
it("saves the clock, seconds and message timestamp choices", async () => {
429+
it("saves the clock, seconds, message timestamp and profile local time choices", async () => {
429430
const user = userEvent.setup();
430431
render(preferencesPage(), { wrapper: ToastProvider });
431432
const clock = screen.getByRole("combobox", { name: "Clock" });
@@ -439,10 +440,14 @@ it("saves the clock, seconds and message timestamp choices", async () => {
439440
await user.click(
440441
await screen.findByRole("option", { name: "Hide in Solo chats" }),
441442
);
443+
await user.click(
444+
screen.getByRole("switch", { name: "Show time zone details on profiles" }),
445+
);
442446
expect(clockPreference()).toEqual({
443447
hourCycle: "h23",
444448
seconds: true,
445449
messageTimestamps: "hide-solo",
450+
localTimeDetails: false,
446451
});
447452
expect(JSON.parse(localStorage.getItem("buzz-clock.v1") ?? "")).toEqual(
448453
clockPreference(),

‎src/app/AppearanceSettings.tsx‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,14 @@ export function AppearanceSettings({
300300
checked={clock.seconds}
301301
onCheckedChange={(seconds) => setClockPreference({ seconds })}
302302
/>
303+
<SwitchPreferenceRow
304+
label="Show time zone details on profiles"
305+
description="With someone’s local time, shows how far ahead or behind you they are and their time zone."
306+
checked={clock.localTimeDetails}
307+
onCheckedChange={(localTimeDetails) =>
308+
setClockPreference({ localTimeDetails })
309+
}
310+
/>
303311
</SettingsGroup>
304312
</div>
305313
<div className="mt-section-gap">

‎src/app/ProfileSettings.avatar.test.tsx‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ const original = (name: string, about = "Keep this") => ({
3737
existing: { name, picture: "", about },
3838
exists: true,
3939
});
40+
// Any save into a profile without a `tz` key shares this device's zone.
41+
const device = new Intl.DateTimeFormat().resolvedOptions().timeZone;
42+
const published = (name: string) => ({
43+
...original(name).existing,
44+
tz: device,
45+
});
4046
function deferred<T>() {
4147
let resolve!: (value: T) => void;
4248
const promise = new Promise<T>((done) => {
@@ -164,7 +170,7 @@ it("edits the existing selected community without another destination control an
164170
expect(api.publishProfile).toHaveBeenCalledExactlyOnceWith(
165171
a,
166172
{ name: "Changed", picture: "", about: "Keep this" },
167-
{ ...original("Alpha human").existing, website: "https://new.example" },
173+
{ ...published("Alpha human"), website: "https://new.example" },
168174
);
169175
expect(api.inspectProfile).toHaveBeenCalledTimes(3);
170176
expect(fixture.saveProfile).toHaveBeenCalledWith({
@@ -233,14 +239,14 @@ it("a dispatched save remains bound to A and its late completion cannot clear B'
233239
expect(api.publishProfile).toHaveBeenCalledExactlyOnceWith(
234240
a,
235241
{ name: "Changed", picture: "", about: "Keep this" },
236-
original("Alpha human").existing,
242+
published("Alpha human"),
237243
);
238244
save();
239245
await screen.findByText("Profile updated");
240246
expect(api.publishProfile).toHaveBeenLastCalledWith(
241247
b,
242248
{ name: "Beta draft", picture: "", about: "Keep this" },
243-
original("Beta human").existing,
249+
published("Beta human"),
244250
);
245251
});
246252

@@ -338,7 +344,7 @@ it("accepted but superseded publication retains the avatar draft for explicit re
338344
picture: "https://images.example/new.png",
339345
about: "Keep this",
340346
},
341-
original("Alpha human").existing,
347+
published("Alpha human"),
342348
);
343349
});
344350

@@ -450,7 +456,7 @@ it.each([
450456
expect(api.publishProfile).toHaveBeenCalledExactlyOnceWith(
451457
a,
452458
{ name: "Changed", picture, about: "Keep this" },
453-
original("Alpha human").existing,
459+
published("Alpha human"),
454460
);
455461
expect(fixture.saveProfile).toHaveBeenCalledExactlyOnceWith({
456462
name: "Changed",

0 commit comments

Comments
 (0)