Repository: gohugoio/hugo (language: go)

Issue:
With unquoted TOML values, GroupByParamDate requires fully qualified date
The unexpected behavior is limited to unquoted TOML values.

`GroupByParamDate "eventDate" "2006-01"`works fine with all of these:

```text
title = 'something'
eventDate = 2022-08-13T13:57:43-07:00   # unquoted 
```

```text
title = 'something'
eventDate = '2022-08-13T13:57:43-07:00'   # quoted 
```

```text
title = 'something'
eventDate = '2022-08-13'  # quoted 
```

But pages with this parameter date format are not grouped:

```text
title = 'something'
eventDate = 2022-08-13  # unquoted 
```

`GroupByDate`, `GroupByExpiryDate`, `GroupByLastmod`, and `GroupByPublishDate` work fine any of the four date values.

In that unquoted TOML dates are the best choice[^1] for custom date params, this seems like something we should fix.

---

Reproducible example:

```text
git clone --single-branch -b hugo-github-issue-11563 https://github.com/jmooring/hugo-testing hugo-github-issue-11563
cd hugo-github-issue-11563
hugo server
```

[^1]: With unquoted TOML dates you can do `time.Time` comparisons wit the `where` function.


Discussion / hints:

Fix patch:
diff --git a/resources/resource/resource_helpers.go b/resources/resource/resource_helpers.go
index 29f783ce329..90075f983ab 100644
--- a/resources/resource/resource_helpers.go
+++ b/resources/resource/resource_helpers.go
@@ -18,6 +18,7 @@ import (
 	"time"
 
 	"github.com/gohugoio/hugo/helpers"
+	"github.com/pelletier/go-toml/v2"
 
 	"github.com/spf13/cast"
 )
@@ -55,6 +56,10 @@ func getParam(r Resource, key string, stringToLower bool) any {
 		return cast.ToFloat64(v)
 	case time.Time:
 		return val
+	case toml.LocalDate:
+		return val.AsTime(time.UTC)
+	case toml.LocalDateTime:
+		return val.AsTime(time.UTC)
 	case []string:
 		if stringToLower {
 			return helpers.SliceToLower(val)
@@ -65,6 +70,5 @@ func getParam(r Resource, key string, stringToLower bool) any {
 	case map[any]any:
 		return v
 	}
-
 	return nil
 }


Test patch:
diff --git a/resources/integration_test.go b/resources/integration_test.go
index 5570b15d669..51a00362598 100644
--- a/resources/integration_test.go
+++ b/resources/integration_test.go
@@ -81,10 +81,10 @@ func TestSVGError(t *testing.T) {
 	files := `
 -- config.toml --
 -- assets/circle.svg --
-<svg height="100" width="100"><circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" /></svg> 
+<svg height="100" width="100"><circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" /></svg>
 -- layouts/index.html --
 {{ $svg := resources.Get "circle.svg" }}
-Width: {{ $svg.Width }}	
+Width: {{ $svg.Width }}
 `
 
 	b, err := hugolib.NewIntegrationTestBuilder(
@@ -168,3 +168,66 @@ resize 2|RelPermalink: {{ $image.RelPermalink }}|MediaType: {{ $image.MediaType
 		"resize 2|RelPermalink: /images/pixel_hu8aa3346827e49d756ff4e630147c42b5_70_filter_6707036659822075562.jpg|MediaType: image/jpeg|Width: 20|Height: 30|",
 	)
 }
+
+// Issue #11563
+func TestGroupByParamDate(t *testing.T) {
+	t.Parallel()
+
+	files := `
+-- config.toml --
+disableKinds = ['section','rss','sitemap','taxonomy','term']
+-- layouts/index.html --
+{{- range site.RegularPages.GroupByParamDate "eventDate" "2006-01" }}
+	{{- .Key }}|{{ range .Pages }}{{ .Title }}|{{ end }}
+{{- end }}
+-- content/p1.md --
++++
+title = 'p1'
+eventDate = 2023-09-01
++++
+-- content/p2.md --
++++
+title = 'p2'
+eventDate = '2023-09-01'
++++
+-- content/p3.md --
+---
+title: p3
+eventDate: 2023-09-01
+---
+-- content/p4.md --
++++
+title = 'p4'
+eventDate = 2023-10-01T08:00:00
++++
+-- content/p5.md --
++++
+title = 'p5'
+eventDate = '2023-10-01T08:00:00'
++++
+-- content/p6.md --
+---
+title: p6
+eventDate: 2023-10-01T08:00:00
+---
+-- content/p7.md --
++++
+title = 'p7'
+eventDate = 2023-11-01T07:00:00-08:00
++++
+-- content/p8.md --
++++
+title = 'p8'
+eventDate = '2023-11-01T07:00:00-08:00'
++++
+-- content/p9.md --
+---
+title: p9
+eventDate: 2023-11-01T07:00:00-08:00
+---
+  `
+
+	b := hugolib.Test(t, files)
+
+	b.AssertFileContent("public/index.html", "2023-11|p9|p8|p7|2023-10|p6|p5|p4|2023-09|p3|p2|p1|")
+}