Repository: gohugoio/hugo (language: go)

Issue:
May (month) displayed as full instead of only 3 letters when `dateFormat` is `Jan` (Italian)
### What version of Hugo are you using (`hugo version`)?

hugo v0.115.3+extended darwin/arm64 BuildDate=unknown

### Does this issue reproduce with the latest release?

Yes

---

When `defaultContentLanguage` is set to `"it"`, using (for example) `{{ dateFormat "02 Jan 06" .Date }}` returns May as `maggio` instead of `mag`. This only happens with May, other months are displayed correctly.

`{{ .Date | time.Format ":date_medium" }}` is working correctly, returning `mag` instead.

Out of curiosity, I've also tested `es` and `fr` and saw some inconsistencies there too. I'm not a Spanish/French native speaker, so I can't say if this is normal behavior, but both have some months shortened as 3 letters and some others as 4 letters (May in Spanish seems to have the same problem).


Discussion / hints:

Fix patch:
diff --git a/common/htime/time.go b/common/htime/time.go
index f2fff897c44..c71e39ee42d 100644
--- a/common/htime/time.go
+++ b/common/htime/time.go
@@ -124,12 +124,15 @@ func (f TimeFormatter) Format(t time.Time, layout string) string {
 	monthIdx := t.Month() - 1 // Month() starts at 1.
 	dayIdx := t.Weekday()
 
-	s = strings.ReplaceAll(s, longMonthNames[monthIdx], f.ltr.MonthWide(t.Month()))
-	if !strings.Contains(s, f.ltr.MonthWide(t.Month())) {
+	if strings.Contains(layout, "January") {
+		s = strings.ReplaceAll(s, longMonthNames[monthIdx], f.ltr.MonthWide(t.Month()))
+	} else if strings.Contains(layout, "Jan") {
 		s = strings.ReplaceAll(s, shortMonthNames[monthIdx], f.ltr.MonthAbbreviated(t.Month()))
 	}
-	s = strings.ReplaceAll(s, longDayNames[dayIdx], f.ltr.WeekdayWide(t.Weekday()))
-	if !strings.Contains(s, f.ltr.WeekdayWide(t.Weekday())) {
+
+	if strings.Contains(layout, "Monday") {
+		s = strings.ReplaceAll(s, longDayNames[dayIdx], f.ltr.WeekdayWide(t.Weekday()))
+	} else if strings.Contains(layout, "Mon") {
 		s = strings.ReplaceAll(s, shortDayNames[dayIdx], f.ltr.WeekdayAbbreviated(t.Weekday()))
 	}
 


Test patch:
diff --git a/common/htime/integration_test.go b/common/htime/integration_test.go
new file mode 100644
index 00000000000..e72c216d93d
--- /dev/null
+++ b/common/htime/integration_test.go
@@ -0,0 +1,83 @@
+// Copyright 2022 The Hugo Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package htime_test
+
+import (
+	"testing"
+
+	"github.com/gohugoio/hugo/hugolib"
+)
+
+// Issue #11267
+func TestApplyWithContext(t *testing.T) {
+	t.Parallel()
+
+	files := `
+-- config.toml --
+defaultContentLanguage = 'it'
+-- layouts/index.html --
+{{ $dates := slice
+  "2022-01-03"
+  "2022-02-01"
+  "2022-03-02"
+  "2022-04-07"
+  "2022-05-06"
+  "2022-06-04"
+  "2022-07-03"
+  "2022-08-01"
+  "2022-09-06"
+  "2022-10-05"
+  "2022-11-03"
+  "2022-12-02"
+}}
+{{ range $dates }}
+	{{ . | time.Format "month: _January_ weekday: _Monday_" }}
+	{{ . | time.Format "month: _Jan_ weekday: _Mon_" }}
+{{ end }}
+  `
+
+	b := hugolib.NewIntegrationTestBuilder(
+		hugolib.IntegrationTestConfig{
+			T:           t,
+			TxtarString: files,
+		},
+	).Build()
+
+	b.AssertFileContent("public/index.html", `
+month: _gennaio_ weekday: _lunedì_
+month: _gen_ weekday: _lun_
+month: _febbraio_ weekday: _martedì_
+month: _feb_ weekday: _mar_
+month: _marzo_ weekday: _mercoledì_
+month: _mar_ weekday: _mer_
+month: _aprile_ weekday: _giovedì_
+month: _apr_ weekday: _gio_
+month: _maggio_ weekday: _venerdì_
+month: _mag_ weekday: _ven_
+month: _giugno_ weekday: _sabato_
+month: _giu_ weekday: _sab_
+month: _luglio_ weekday: _domenica_
+month: _lug_ weekday: _dom_
+month: _agosto_ weekday: _lunedì_
+month: _ago_ weekday: _lun_
+month: _settembre_ weekday: _martedì_
+month: _set_ weekday: _mar_
+month: _ottobre_ weekday: _mercoledì_
+month: _ott_ weekday: _mer_
+month: _novembre_ weekday: _giovedì_
+month: _nov_ weekday: _gio_
+month: _dicembre_ weekday: _venerdì_
+month: _dic_ weekday: _ven_
+`)
+}