Skip to content

Commit

Permalink
Fix 'ToWeekString' method ignores SetWeekStartsAt #200
Browse files Browse the repository at this point in the history
  • Loading branch information
gouguoyin committed Nov 30, 2023
1 parent 004e90d commit 25dea18
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
10 changes: 3 additions & 7 deletions outputer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand All @@ -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])
}
Expand All @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions outputer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 25dea18

Please sign in to comment.