Skip to content

[Bug]: Improper post date format in some cases #1865

Description

@Habetdin

What happened?

Raw (unformatted) .Date is used here:

{{- $scratch.Add "meta" (slice (printf "<span title='%s'>%s</span>" (.Date) (.Date | time.Format (default ":date_long" site.Params.DateFormat)))) }}

... which leads to duplicate timezone information. Reasons are described here: gohugoio/hugo#5907, gohugoio/hugo#9096

This issue could be fixed by using explicit formatting like this:

diff --git a/layouts/_partials/post_meta.html b/layouts/_partials/post_meta.html
index c7c2635..decaef3 100644
--- a/layouts/_partials/post_meta.html
+++ b/layouts/_partials/post_meta.html
@@ -1,7 +1,7 @@
 {{- $scratch := newScratch }}

 {{- if not .Date.IsZero -}}
-    {{- $scratch.Add "meta" (slice (printf "<span title='%s'>%s</span>" (.Date) (.Date | time.Format (default ":date_long" site.Params.DateFormat)))) }}
+    {{- $scratch.Add "meta" (slice (printf "<span title='%s'>%s</span>" (.Date | time.Format "2006-01-02T15:04:05-07:00") (.Date | time.Format (default ":date_long" site.Params.DateFormat)))) }}
 {{- end }}

 {{- if (.Param "ShowReadingTime") -}}

Another file worth checking:

"datePublished": {{ .PublishDate }},
"dateModified": {{ .Lastmod }},

Steps to reproduce

  1. Create post with date in timezone that doesn't match system timezone
  2. Publish it
  3. Check the date format in the post meta

Hugo Version

Hugo >= 0.146.0 (Recommended - Minimum version required for PaperMod)

PaperMod Version

154d006

What kind of devices are you seeing the problem on?

Desktop

What browsers are you seeing the problem on?

No response

Browser Version

No response

Relevant log output

<span title='2023-06-08 01:32:03 +0200 +0200'>

Repository/Source Code link where this issue can be reproduced

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions