diff --git a/outputer.go b/outputer.go index 5a6aa43e..fa6f3a0d 100644 --- a/outputer.go +++ b/outputer.go @@ -82,8 +82,8 @@ func (c Carbon) ToWeekString(timezone ...string) string { } if months, ok := c.lang.resources["weeks"]; ok { slice := strings.Split(months, "|") - if len(slice) == 7 { - return slice[c.Week()] + if len(slice) == DaysPerWeek { + return slice[c.DayOfWeek()%DaysPerWeek] } } return "" @@ -92,10 +92,6 @@ func (c Carbon) ToWeekString(timezone ...string) string { // ToShortWeekString outputs a string in short week layout like "Sun", i18n is supported. // 输出缩写星期字符串,支持i18n func (c Carbon) ToShortWeekString(timezone ...string) string { - return c.toWeekString("short_weeks", timezone) -} - -func (c Carbon) toWeekString(resourceKey string, timezone []string) string { if len(timezone) > 0 { c.loc, c.Error = getLocationByTimezone(timezone[0]) } @@ -105,7 +101,7 @@ func (c Carbon) toWeekString(resourceKey string, timezone []string) string { if len(c.lang.resources) == 0 { c.lang.SetLocale(defaultLocale) } - if months, ok := c.lang.resources[resourceKey]; ok { + if months, ok := c.lang.resources["short_weeks"]; ok { slice := strings.Split(months, "|") if len(slice) == DaysPerWeek { return slice[c.DayOfWeek()%DaysPerWeek] diff --git a/outputer_test.go b/outputer_test.go index 4083b176..45a0a80b 100644 --- a/outputer_test.go +++ b/outputer_test.go @@ -2,11 +2,10 @@ package carbon import ( "fmt" + "github.com/stretchr/testify/assert" "strconv" "testing" "time" - - "github.com/stretchr/testify/assert" ) func TestCarbon_String(t *testing.T) { @@ -1791,6 +1790,7 @@ func TestCarbon_ToStdTime(t *testing.T) { assert.Equal(t, expected, actual) } +// https://github.com/golang-module/carbon/issues/200 func TestCarbon_Issue200(t *testing.T) { assert := assert.New(t)