From 62736c982b6b799e6df9745491bf7cf165d2461e Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Sun, 1 Feb 2026 13:30:30 +0100 Subject: [PATCH] render timestamps as human readable strings instead of timestamps for better readability --- AGENTS.md | 23 ++++ Makefile | 6 +- cmd/web/client/html/controls.html | 2 +- cmd/web/client/html/feed.html | 6 +- cmd/web/client/html/form--post.html | 4 +- .../client/html/partial--feed-prompts.html | 2 +- .../client/html/partial--settings_feeds.html | 6 +- cmd/web/client/html/single_post.html | 2 +- cmd/web/client/html/user_home.html | 2 +- cmd/web/main.go | 14 +-- pkg/util/date/date.go | 42 +++++++ pkg/util/date/date_test.go | 112 ++++++++++++++++++ 12 files changed, 197 insertions(+), 24 deletions(-) create mode 100644 pkg/util/date/date.go create mode 100644 pkg/util/date/date_test.go diff --git a/AGENTS.md b/AGENTS.md index 80fffd3..ca9bc5d 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -193,9 +193,32 @@ Located in `/Users/dima/code/pcom/cmd/web/client/scss/_dark-mode.scss`: **Do NOT define ad-hoc colors directly on elements** - always use Bootstrap's CSS variables to ensure proper inheritance and theming. +## Date/Time Rendering + +Use `renderHumanTime` template helper to display timestamps with relative time and full timestamp on hover: + +```html +{{ renderHumanTime .CreatedAt $.User.DBUser }} +``` + +**Output**: `5 minutes ago` + +- First argument: `time.Time` value to display +- Second argument: `*core.User` for timezone localization (can be nil for UTC) +- Implementation: `pkg/util/date` + +## Development + +### Verification +Use `make check` to verify code compiles and tests pass without producing build artifacts: +```bash +make check +``` + ## File Locations - HTML Templates: `/Users/dima/code/pcom/cmd/web/client/html/` - JavaScript: `/Users/dima/code/pcom/cmd/web/client/js/` - Main JS entry: `/Users/dima/code/pcom/cmd/web/client/js/index.js` - Markdown package: `/Users/dima/code/pcom/pkg/markdown/` - Dark mode styles: `/Users/dima/code/pcom/cmd/web/client/scss/_dark-mode.scss` +- Date utilities: `/Users/dima/code/pcom/pkg/util/date/` diff --git a/Makefile b/Makefile index 264a563..c11acc2 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: shell tunnel lint test build +.PHONY: shell tunnel lint test build check shell: flyctl postgres connect -a pcomdb @@ -20,3 +20,7 @@ test: build: go build -v ./... + +check: + go build -o /dev/null ./... + go test ./... diff --git a/cmd/web/client/html/controls.html b/cmd/web/client/html/controls.html index 6b4b66d..baffcbe 100644 --- a/cmd/web/client/html/controls.html +++ b/cmd/web/client/html/controls.html @@ -36,7 +36,7 @@
Drafts
{{ range . }} {{ with .Subject }}{{ . }}{{ else }}No subject{{ end }} - {{ renderTimestamp .LastUpdatedAt $.User.DBUser }} + {{ renderHumanTime .LastUpdatedAt $.User.DBUser }}