mirror of
https://gitee.com/dromara/carbon.git
synced 2024-11-29 18:57:37 +08:00
修复 'ToWeekString' 方法忽略 SetWeekStartsAt
设置的bug
This commit is contained in:
parent
b09d48d6de
commit
8a0bbf1487
@ -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 ""
|
||||
@ -103,8 +103,8 @@ func (c Carbon) ToShortWeekString(timezone ...string) string {
|
||||
}
|
||||
if months, ok := c.lang.resources["short_weeks"]; ok {
|
||||
slice := strings.Split(months, "|")
|
||||
if len(slice) == 7 {
|
||||
return slice[c.Week()]
|
||||
if len(slice) == DaysPerWeek {
|
||||
return slice[c.DayOfWeek()%DaysPerWeek]
|
||||
}
|
||||
}
|
||||
return ""
|
||||
|
@ -1789,3 +1789,22 @@ func TestCarbon_ToStdTime(t *testing.T) {
|
||||
actual := Now().ToStdTime().Format(DateTimeLayout)
|
||||
assert.Equal(t, expected, actual)
|
||||
}
|
||||
|
||||
// https://github.com/golang-module/carbon/issues/200
|
||||
func TestCarbon_Issue200(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
tests := []struct {
|
||||
input Carbon
|
||||
expectedWeekString string
|
||||
expectedShortWeekString string
|
||||
}{
|
||||
{Now().StartOfWeek(), "Sunday", "Sun"},
|
||||
{Now().SetWeekStartsAt(Monday).StartOfWeek(), "Monday", "Mon"},
|
||||
{Now().SetWeekStartsAt(Wednesday).StartOfWeek(), "Wednesday", "Wed"},
|
||||
}
|
||||
for index, test := range tests {
|
||||
assert.Equal(test.expectedWeekString, test.input.ToWeekString(), "Current test index is "+strconv.Itoa(index))
|
||||
assert.Equal(test.expectedShortWeekString, test.input.ToShortWeekString(), "Current test index is "+strconv.Itoa(index))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user