fix(room): display backend timestamps in the viewer's local zone#345
Merged
Conversation
Backend timestamps are UTC instants. Two room display sites read calendar fields without converting to local first: the document card's date+time formatter and the thread tile's >7-day date fallback. Both showed the wrong time-of-day (or a date off by one) for viewers outside UTC. Add .toLocal() at both sites. Consolidate the duplicated relative-time formatter into a shared, already-localized formatRelativeTime in lib/src/shared/, normalizing to local at the top so the fallback cannot regress; lobby and room both call it. Keep the lobby-specific activity buckets where they are. Closes #338 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Backend timestamps arrive as UTC instants (
parseTimestampappendsZand calls.toUtc()). Two room display sites read calendar fields off those instants without.toLocal()first, so they rendered the wrong time-of-day (or a date off by one) for any viewer outside UTC:documents_card.dart_formatDateTime— full date and time, wrong hour on every render.thread_tile.dart_formatRelativeTime— the>7-daynumeric-date fallback only.Both bugs originated from copy-pasting a relative-time formatter that read raw fields, so the fix also removes that duplication.
Changes
.toLocal()at both display sites.formatRelativeTimeinlib/src/shared/relative_time.dart, with.toLocal()normalized at the top of the function so the fallback can't regress.thread_tile,room_card, androom_grid_cardall call it; the duplicate_formatRelativeTimeand lobby'sformatRelativeActivityare deleted.bucketFor/ActivityBucket(single consumer, lobby-specific section headers);documents_card's absolute formatter (different concept, single caller — not shared).Design notes
shared/(notcore/) is the home:core/is shell infrastructure, and a pure presentation helper shared by two sibling modules must live below both —room → lobbywould be a wrong directional dependency.shared/already holds the pure-functionfile_type_icons.dart.Tests
test/shared/relative_time_test.dart— thresholds + a UTC-instant fallback regression case.documents_card_test.dart— the existing timestamp test used a localDateTime, so it never exercised the UTC→local path (confirmed RED before the fix, GREEN after).Full suite green,
dart formatclean,flutter analyzezero warnings.Closes #338
🤖 Generated with Claude Code