summaryrefslogtreecommitdiffstats
path: root/tpl/time
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2022-04-05 09:57:58 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2022-04-05 16:11:11 +0200
commit658e11ebaa94de219f941699d119a97a18301eea (patch)
tree76330777138b792bac1dfcf05e9948d9f5839bcc /tpl/time
parente0a882fd3b9825dc9a95b83d72fc330dcbbbcce9 (diff)
Localize all the GroupBy*Date methods
Fixes #9745
Diffstat (limited to 'tpl/time')
-rw-r--r--tpl/time/init.go2
-rw-r--r--tpl/time/time.go6
-rw-r--r--tpl/time/time_test.go9
3 files changed, 8 insertions, 9 deletions
diff --git a/tpl/time/init.go b/tpl/time/init.go
index a76348b7a..4bb2ddf67 100644
--- a/tpl/time/init.go
+++ b/tpl/time/init.go
@@ -28,7 +28,7 @@ func init() {
if d.Language == nil {
panic("Language must be set")
}
- ctx := New(langs.GetTranslator(d.Language), langs.GetLocation(d.Language))
+ ctx := New(langs.GetTimeFormatter(d.Language), langs.GetLocation(d.Language))
ns := &internal.TemplateFuncsNamespace{
Name: name,
diff --git a/tpl/time/time.go b/tpl/time/time.go
index 66ea721fa..f82d63c44 100644
--- a/tpl/time/time.go
+++ b/tpl/time/time.go
@@ -21,15 +21,13 @@ import (
"github.com/gohugoio/hugo/common/htime"
- "github.com/gohugoio/locales"
-
"github.com/spf13/cast"
)
// New returns a new instance of the time-namespaced template functions.
-func New(translator locales.Translator, location *time.Location) *Namespace {
+func New(timeFormatter htime.TimeFormatter, location *time.Location) *Namespace {
return &Namespace{
- timeFormatter: htime.NewTimeFormatter(translator),
+ timeFormatter: timeFormatter,
location: location,
}
}
diff --git a/tpl/time/time_test.go b/tpl/time/time_test.go
index f368ea43f..9001f6b6b 100644
--- a/tpl/time/time_test.go
+++ b/tpl/time/time_test.go
@@ -20,6 +20,7 @@ import (
qt "github.com/frankban/quicktest"
+ "github.com/gohugoio/hugo/common/htime"
translators "github.com/gohugoio/localescompressed"
)
@@ -27,7 +28,7 @@ func TestTimeLocation(t *testing.T) {
t.Parallel()
loc, _ := time.LoadLocation("America/Antigua")
- ns := New(translators.GetTranslator("en"), loc)
+ ns := New(htime.NewTimeFormatter(translators.GetTranslator("en")), loc)
for i, test := range []struct {
name string
@@ -86,7 +87,7 @@ func TestFormat(t *testing.T) {
c.Run("UTC", func(c *qt.C) {
c.Parallel()
- ns := New(translators.GetTranslator("en"), time.UTC)
+ ns := New(htime.NewTimeFormatter(translators.GetTranslator("en")), time.UTC)
for i, test := range []struct {
layout string
@@ -129,7 +130,7 @@ func TestFormat(t *testing.T) {
loc, err := time.LoadLocation("America/Los_Angeles")
c.Assert(err, qt.IsNil)
- ns := New(translators.GetTranslator("en"), loc)
+ ns := New(htime.NewTimeFormatter(translators.GetTranslator("en")), loc)
d, err := ns.Format(":time_full", "2020-03-09T11:00:00")
@@ -143,7 +144,7 @@ func TestFormat(t *testing.T) {
func TestDuration(t *testing.T) {
t.Parallel()
- ns := New(translators.GetTranslator("en"), time.UTC)
+ ns := New(htime.NewTimeFormatter(translators.GetTranslator("en")), time.UTC)
for i, test := range []struct {
unit any