Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use time.Format to format dates. It allows dates to be localized. #537

Merged
merged 2 commits into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ Dates of blog posts and single pages are rendered with the default date format c
date_format = "2. January 2006"
```

See hugo's documentation of the [`dateFormat` function](https://gohugo.io/functions/dateformat/) for more details.
See hugo's documentation of the [`time.Format` function](https://gohugo.io/functions/dateformat/) for more details.


### Nearly finished
Expand Down
2 changes: 1 addition & 1 deletion layouts/_default/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ <h1 class="f1 athelas mt3 mb1">
{{/* Hugo uses Go's date formatting is set by example. Here are two formats */}}
{{ if not .Date.IsZero }}
<time class="f6 mv4 dib tracked" {{ printf `datetime="%s"` (.Date.Format "2006-01-02T15:04:05Z07:00") | safeHTMLAttr }}>
{{- .Date.Format (default "January 2, 2006" .Site.Params.date_format) -}}
{{- .Date | time.Format (default ":date_full" .Site.Params.date_format) -}}
</time>
{{end}}

Expand Down
2 changes: 1 addition & 1 deletion layouts/post/summary.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="mb3 pa4 {{ $.Param "text_color" | default "mid-gray" }} overflow-hidden">
{{ if .Date }}
<div class="f6">
{{ .Date.Format (default "January 2, 2006" .Site.Params.date_format) }}
{{ .Date | time.Format (default ":date_full" .Site.Params.date_format) }}
</div>
{{ end }}
<h1 class="f3 near-black">
Expand Down