Repository navigation
Commit 51d6395
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
File tree
- docs
- src
- app
- shell
- bundled/profiles
- features
- communities
- identity
- profiles
- relay
- tests/browser
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
269 | 269 | | |
270 | 270 | | |
271 | 271 | | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
272 | 284 | | |
273 | 285 | | |
274 | 286 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| 63 | + | |
63 | 64 | | |
64 | 65 | | |
65 | 66 | | |
| |||
425 | 426 | | |
426 | 427 | | |
427 | 428 | | |
428 | | - | |
| 429 | + | |
429 | 430 | | |
430 | 431 | | |
431 | 432 | | |
| |||
439 | 440 | | |
440 | 441 | | |
441 | 442 | | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
442 | 446 | | |
443 | 447 | | |
444 | 448 | | |
445 | 449 | | |
| 450 | + | |
446 | 451 | | |
447 | 452 | | |
448 | 453 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
300 | 300 | | |
301 | 301 | | |
302 | 302 | | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
303 | 311 | | |
304 | 312 | | |
305 | 313 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
40 | 46 | | |
41 | 47 | | |
42 | 48 | | |
| |||
164 | 170 | | |
165 | 171 | | |
166 | 172 | | |
167 | | - | |
| 173 | + | |
168 | 174 | | |
169 | 175 | | |
170 | 176 | | |
| |||
233 | 239 | | |
234 | 240 | | |
235 | 241 | | |
236 | | - | |
| 242 | + | |
237 | 243 | | |
238 | 244 | | |
239 | 245 | | |
240 | 246 | | |
241 | 247 | | |
242 | 248 | | |
243 | | - | |
| 249 | + | |
244 | 250 | | |
245 | 251 | | |
246 | 252 | | |
| |||
338 | 344 | | |
339 | 345 | | |
340 | 346 | | |
341 | | - | |
| 347 | + | |
342 | 348 | | |
343 | 349 | | |
344 | 350 | | |
| |||
450 | 456 | | |
451 | 457 | | |
452 | 458 | | |
453 | | - | |
| 459 | + | |
454 | 460 | | |
455 | 461 | | |
456 | 462 | | |
| |||
0 commit comments