aboutsummaryrefslogtreecommitdiffstats
path: root/internal/web/web_test.go
diff options
context:
space:
mode:
authorgrm <grm@eyesin.space>2026-09-14 22:58:08 +0300
committergrm <grm@eyesin.space>2026-09-14 22:58:08 +0300
commit5f9fc2a8667a9438b6336d75026f9a455fc9c4ce (patch)
tree8fa0009b2487e35219bfdbb34f9802704007076e /internal/web/web_test.go
parente14a4250efb828262347f5a4bbc4067cd71d885f (diff)
downloadblogspace-5f9fc2a8667a9438b6336d75026f9a455fc9c4ce.tar.gz
blogspace-5f9fc2a8667a9438b6336d75026f9a455fc9c4ce.tar.bz2
blogspace-5f9fc2a8667a9438b6336d75026f9a455fc9c4ce.zip
Let the blogger set a post's date, when writing it and afterwards
The post date is posts.created_at: it already drives ordering, the archive, the feed and the displayed dates, so making it editable is a form field rather than a new column. The datetime-local input degrades to a text box on old browsers, so the server also accepts the value typed by hand; blank keeps the current date. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Sd8UPWrvyYCLj97JexNw3A
Diffstat (limited to 'internal/web/web_test.go')
-rw-r--r--internal/web/web_test.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/internal/web/web_test.go b/internal/web/web_test.go
index ae26029..d7de43a 100644
--- a/internal/web/web_test.go
+++ b/internal/web/web_test.go
@@ -220,6 +220,24 @@ func TestValidLinkURL(t *testing.T) {
}
}
+func TestParsePostDate(t *testing.T) {
+ for in, want := range map[string]time.Time{
+ "2026-09-14T08:30": time.Date(2026, 9, 14, 8, 30, 0, 0, time.Local),
+ "2026-09-14 08:30": time.Date(2026, 9, 14, 8, 30, 0, 0, time.Local),
+ "2026-09-14T08:30:15": time.Date(2026, 9, 14, 8, 30, 15, 0, time.Local),
+ "2026-09-14": time.Date(2026, 9, 14, 0, 0, 0, 0, time.Local),
+ } {
+ if got, ok := parsePostDate(in); !ok || !got.Equal(want) {
+ t.Errorf("%q: got %v %v, want %v", in, got, ok, want)
+ }
+ }
+ for _, bad := range []string{"", "14/09/2026", "2026-13-01", "yesterday", "2026-09-14T25:00"} {
+ if _, ok := parsePostDate(bad); ok {
+ t.Errorf("%q should be rejected", bad)
+ }
+ }
+}
+
func TestGroupArchive(t *testing.T) {
d := func(y int, m time.Month, day int) time.Time { return time.Date(y, m, day, 12, 0, 0, 0, time.UTC) }
posts := []store.PostRef{{Title: "d", CreatedAt: d(2026, 9, 3)}, {Title: "c", CreatedAt: d(2026, 9, 1)}, {Title: "b", CreatedAt: d(2026, 2, 1)}, {Title: "a", CreatedAt: d(2025, 12, 31)}}