aboutsummaryrefslogtreecommitdiffhomepage
path: root/hugolib/dates_test.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2022-06-06 09:48:40 +0200
committerBjørn Erik Pedersen <[email protected]>2022-06-07 13:02:58 +0200
commit0566bbf7c7f2898fcd1d6156b27733cd48aa0449 (patch)
tree69ee0bde4d334cb0565afd5fb4e17247c946aad9 /hugolib/dates_test.go
parent534e7155bb504682a37f5663d8c913e439b11e07 (diff)
downloadhugo-0566bbf7c7f2898fcd1d6156b27733cd48aa0449.tar.gz
hugo-0566bbf7c7f2898fcd1d6156b27733cd48aa0449.zip
Fix raw TOML dates in where/eq
Note that this has only been a problem with "raw dates" in TOML files in /data and similar. The predefined front matter dates `.Date` etc. are converted to a Go Time and has worked fine even after upgrading to v2 of the go-toml lib. Fixes #9979
Diffstat (limited to 'hugolib/dates_test.go')
-rw-r--r--hugolib/dates_test.go59
1 files changed, 59 insertions, 0 deletions
diff --git a/hugolib/dates_test.go b/hugolib/dates_test.go
index 4b4dc29d2..47629fb0a 100644
--- a/hugolib/dates_test.go
+++ b/hugolib/dates_test.go
@@ -214,3 +214,62 @@ func TestTimeOnError(t *testing.T) {
b.Assert(b.BuildE(BuildCfg{}), qt.Not(qt.IsNil))
}
+
+func TestTOMLDates(t *testing.T) {
+ t.Parallel()
+
+ files := `
+-- config.toml --
+timeZone = "America/Los_Angeles"
+-- content/_index.md --
+---
+date: "2020-10-20"
+---
+-- content/p1.md --
++++
+title = "TOML Date with UTC offset"
+date = 2021-08-16T06:00:00+00:00
++++
+
+
+## Foo
+-- data/mydata.toml --
+date = 2020-10-20
+talks = [
+ { date = 2017-01-23, name = "Past talk 1" },
+ { date = 2017-01-24, name = "Past talk 2" },
+ { date = 2017-01-26, name = "Past talk 3" },
+ { date = 2050-02-12, name = "Future talk 1" },
+ { date = 2050-02-13, name = "Future talk 2" },
+]
+-- layouts/index.html --
+{{ $futureTalks := where site.Data.mydata.talks "date" ">" now }}
+{{ $pastTalks := where site.Data.mydata.talks "date" "<" now }}
+
+{{ $homeDate := site.Home.Date }}
+{{ $p1Date := (site.GetPage "p1").Date }}
+Future talks: {{ len $futureTalks }}
+Past talks: {{ len $pastTalks }}
+
+Home's Date should be greater than past: {{ gt $homeDate (index $pastTalks 0).date }}
+Home's Date should be less than future: {{ lt $homeDate (index $futureTalks 0).date }}
+Home's Date should be equal mydata date: {{ eq $homeDate site.Data.mydata.date }}
+Full time: {{ $p1Date | time.Format ":time_full" }}
+`
+
+ b := NewIntegrationTestBuilder(
+ IntegrationTestConfig{
+ T: t,
+ TxtarString: files,
+ },
+ ).Build()
+
+ b.AssertFileContent("public/index.html", `
+Future talks: 2
+Past talks: 3
+Home's Date should be greater than past: true
+Home's Date should be less than future: true
+Home's Date should be equal mydata date: true
+Full time: 6:00:00 am UTC
+`)
+}