From 6d25ba0029740d1baa3413de833e7ac7990c64b7 Mon Sep 17 00:00:00 2001 From: Jan-Lukas Else Date: Sun, 25 Dec 2022 21:06:23 +0100 Subject: [PATCH] Cover another case of #46 --- postsDb.go | 5 +++++ postsDb_test.go | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/postsDb.go b/postsDb.go index ecf0287..3176688 100644 --- a/postsDb.go +++ b/postsDb.go @@ -63,6 +63,11 @@ func (a *goBlog) checkPost(p *post, new bool) (err error) { // Has published date in the past, so add updated date p.Updated = nowString } + } else if !new && p.Updated != "" { + if updated, err := dateparse.ParseLocal(p.Updated); err == nil && now.After(updated) { + // Has updated date in the past, so add new updated date + p.Updated = nowString + } } // Fix content p.Content = strings.TrimSuffix(strings.TrimPrefix(p.Content, "\n"), "\n") diff --git a/postsDb_test.go b/postsDb_test.go index 7c950d2..6bc3f74 100644 --- a/postsDb_test.go +++ b/postsDb_test.go @@ -478,4 +478,16 @@ func Test_checkPost(t *testing.T) { assert.NotEqual(t, oldUpdate, p.Updated) }) + t.Run("Updated post with just updated date should get new updated date", func(t *testing.T) { + oldUpdate := time.Now().Local().Add(-1 * time.Hour).Format(time.RFC3339) + p := &post{ + Updated: oldUpdate, + } + app.checkPost(p, false) + + assert.Empty(t, p.Published) + assert.NotEmpty(t, p.Updated) + assert.NotEqual(t, oldUpdate, p.Updated) + }) + }