Render notification times in local time instead of UTC - #629
Open
badbread wants to merge 2 commits into
Open
Conversation
Every channel message formatted the event timestamp in UTC with a literal "UTC" suffix, so an alert read on a phone in another zone showed the wrong time at a glance. Timestamps are now rendered per destination. Discord gets its own <t:UNIX:f|t|d> markup and Slack gets <!date^UNIX^tokens|fallback> markup, both of which those clients resolve in each viewer's own zone. ntfy, Pushover, Telegram, the generic webhook, and any future kind render "%Y-%m-%d %H:%M:%S %Z" in the server's configured zone, resolved once at startup from TZ into ApiConfig::server_tz and threaded into the notification engine the way the go2rtc credentials already are. The %date%, %time% and %datetime% template tokens follow the same style. Stored event timestamps stay UTC, and the generic webhook's JSON ts field stays a raw UTC instant since it is a machine contract. Signed-off-by: badbread <badbread@users.noreply.github.com>
Signed-off-by: badbread <badbread@users.noreply.github.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 changed
Notification timestamps were formatted in UTC with a literal "UTC" suffix, so an
alert read on a phone in another zone showed the wrong time at a glance. The
rendering is now chosen per destination:
<t:UNIX:f>for a date-time (%datetime%and the legacy "at ..."wording),
<t:UNIX:t>for%time%,<t:UNIX:d>for%date%. The text goesinto the webhook's
contentfield, which renders Discord markup, so everyviewer's client shows their own local time.
<!date^UNIX^{date_short_pretty} at {time}|FALLBACK>(and thesingle-token forms for
%date%/%time%), where FALLBACK is the server-zonerendering. The text goes into the incoming webhook's top-level
textfield,which renders that markup.
%Y-%m-%d %H:%M:%S %Zin the server's configured zone, so the zoneabbreviation is visible.
%date%and%time%render without the suffix.The zone comes from
TZ, resolved once at startup by a newcrumb_common::config::server_tz()wrapper around the existingparse_tz_envhelper, stored as
ApiConfig::server_tz, and threaded into the notificationengine the same way the go2rtc credentials already are. No new env keys.
The style is picked by
channel_notify::time_style_for(kind, tz)and applied byChannelMessage::text_for(style)/token_map_for(style)/rendered_title_for(style), so the template engine is not duplicated. Thezero-argument
text()/rendered_title()had no remaining callers once everydispatcher passed a style, so they were removed rather than left unused (an
unused method would fail the
-D warningsclippy gate).Stored event timestamps stay UTC. The generic webhook's JSON
tsfield alsostays a raw UTC instant, since that is a machine contract. There is no email
provider in the dispatcher, and the device push path does not format the
timestamp at all (the client renders it), so neither needed a change.
Docs
The alert-text editor in the admin console previously said "Times are UTC"; it
now states the per-provider rule and names the server's zone, and its live
preview stamps the sample
%datetime%with the server's zone abbreviationinstead of "UTC". Also updated:
docs-site/docs/notifications/index.md(new"Times in alerts" section), the
TZrow indocs-site/docs/configuration/environment-reference.md, the alert-templatingbullet in
docs/AI-INSTALL.md, theTZcomment indocker-compose.yml, adocs/COMPONENT-MAP.mdrow, and adocs/DECISIONS.mdentry recording why themarkup-vs-server-zone split was chosen over a per-user timezone setting.
How tested
Build-box gate green on
8fa62fb:cargo fmt --check,cargo clippy --all-targets -D warnings,cargo test --workspaceagainst a throwawayPostgres, ending in
GATE_OK fix/notification-local-time.New unit tests in
channel_notify.rscover the Discord markup and its unixseconds, the Slack markup with its server-zone fallback, and the zone rendering
of fixed UTC instants under
America/Los_Angelesfor both a winter (PST) and asummer (PDT, which also shifts the calendar date) instant. The tests pass the
Tzin explicitly and never read the process environment.Fixes #628