代码拉取完成,页面将自动刷新
package carbon
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestCarbon_StartOfCentury(t *testing.T) {
tests := []struct {
name string
carbon Carbon
want string
}{
{
name: "case1",
carbon: Parse(""),
want: "",
},
{
name: "case2",
carbon: Parse("xxx"),
want: "",
},
{
name: "case3",
carbon: Parse("2020-01-01 00:00:00"),
want: "2000-01-01 00:00:00",
},
{
name: "case4",
carbon: Parse("2020-01-31 23:59:59"),
want: "2000-01-01 00:00:00",
},
{
name: "case5",
carbon: Parse("2020-02-01 13:14:15"),
want: "2000-01-01 00:00:00",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, tt.carbon.StartOfCentury().ToDateTimeString(), "StartOfCentury()")
})
}
}
func TestCarbon_EndOfCentury(t *testing.T) {
tests := []struct {
name string
carbon Carbon
want string
}{
{
name: "case1",
carbon: Parse(""),
want: "",
},
{
name: "case2",
carbon: Parse("xxx"),
want: "",
},
{
name: "case3",
carbon: Parse("2020-01-01 00:00:00"),
want: "2099-12-31 23:59:59",
},
{
name: "case4",
carbon: Parse("2020-01-31 23:59:59"),
want: "2099-12-31 23:59:59",
},
{
name: "case5",
carbon: Parse("2020-02-01 13:14:15"),
want: "2099-12-31 23:59:59",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, tt.carbon.EndOfCentury().ToDateTimeString(), "EndOfCentury()")
})
}
}
func TestCarbon_StartOfDecade(t *testing.T) {
tests := []struct {
name string
carbon Carbon
want string
}{
{
name: "case1",
carbon: Parse(""),
want: "",
},
{
name: "case2",
carbon: Parse("xxx"),
want: "",
},
{
name: "case3",
carbon: Parse("2020-01-31 23:59:59"),
want: "2020-01-01 00:00:00",
},
{
name: "case4",
carbon: Parse("2021-01-01 00:00:00"),
want: "2020-01-01 00:00:00",
},
{
name: "case5",
carbon: Parse("2029-01-31 23:59:59"),
want: "2020-01-01 00:00:00",
},
{
name: "case6",
carbon: Parse("2020-02-01 13:14:15"),
want: "2020-01-01 00:00:00",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, tt.carbon.StartOfDecade().ToDateTimeString(), "StartOfDecade()")
})
}
}
func TestCarbon_EndOfDecade(t *testing.T) {
tests := []struct {
name string
carbon Carbon
want string
}{
{
name: "case1",
carbon: Parse(""),
want: "",
},
{
name: "case2",
carbon: Parse("xxx"),
want: "",
},
{
name: "case3",
carbon: Parse("2020-01-31 23:59:59"),
want: "2029-12-31 23:59:59",
},
{
name: "case4",
carbon: Parse("2021-01-01 00:00:00"),
want: "2029-12-31 23:59:59",
},
{
name: "case5",
carbon: Parse("2029-01-31 23:59:59"),
want: "2029-12-31 23:59:59",
},
{
name: "case6",
carbon: Parse("2020-02-01 13:14:15"),
want: "2029-12-31 23:59:59",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, tt.carbon.EndOfDecade().ToDateTimeString(), "EndOfDecade()")
})
}
}
func TestCarbon_StartOfYear(t *testing.T) {
tests := []struct {
name string
carbon Carbon
want string
}{
{
name: "case1",
carbon: Parse(""),
want: "",
},
{
name: "case2",
carbon: Parse("xxx"),
want: "",
},
{
name: "case3",
carbon: Parse("2020-01-01 00:00:00"),
want: "2020-01-01 00:00:00",
},
{
name: "case4",
carbon: Parse("2020-01-31 23:59:59"),
want: "2020-01-01 00:00:00",
},
{
name: "case5",
carbon: Parse("2020-02-01 13:14:15"),
want: "2020-01-01 00:00:00",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, tt.carbon.StartOfYear().ToDateTimeString(), "StartOfYear()")
})
}
}
func TestCarbon_EndOfYear(t *testing.T) {
tests := []struct {
name string
carbon Carbon
want string
}{
{
name: "case1",
carbon: Parse(""),
want: "",
},
{
name: "case2",
carbon: Parse("xxx"),
want: "",
},
{
name: "case3",
carbon: Parse("2020-01-01 00:00:00"),
want: "2020-12-31 23:59:59",
},
{
name: "case4",
carbon: Parse("2020-01-31 23:59:59"),
want: "2020-12-31 23:59:59",
},
{
name: "case5",
carbon: Parse("2020-02-01 13:14:15"),
want: "2020-12-31 23:59:59",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, tt.carbon.EndOfYear().ToDateTimeString(), "EndOfYear()")
})
}
}
func TestCarbon_StartOfQuarter(t *testing.T) {
tests := []struct {
name string
carbon Carbon
want string
}{
{
name: "case1",
carbon: Parse(""),
want: "",
},
{
name: "case2",
carbon: Parse("xxx"),
want: "",
},
{
name: "case3",
carbon: Parse("2020-01-15 00:00:00"),
want: "2020-01-01 00:00:00",
},
{
name: "case4",
carbon: Parse("2020-02-15 00:00:00"),
want: "2020-01-01 00:00:00",
},
{
name: "case5",
carbon: Parse("2020-03-15 00:00:00"),
want: "2020-01-01 00:00:00",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, tt.carbon.StartOfQuarter().ToDateTimeString(), "StartOfQuarter()")
})
}
}
func TestCarbon_EndOfQuarter(t *testing.T) {
tests := []struct {
name string
carbon Carbon
want string
}{
{
name: "case1",
carbon: Parse(""),
want: "",
},
{
name: "case2",
carbon: Parse("xxx"),
want: "",
},
{
name: "case3",
carbon: Parse("2020-01-15 00:00:00"),
want: "2020-03-31 23:59:59",
},
{
name: "case4",
carbon: Parse("2020-02-15 00:00:00"),
want: "2020-03-31 23:59:59",
},
{
name: "case5",
carbon: Parse("2020-03-15 00:00:00"),
want: "2020-03-31 23:59:59",
},
{
name: "case6",
carbon: Parse("2020-04-15 23:59:59"),
want: "2020-06-30 23:59:59",
},
{
name: "case7",
carbon: Parse("2020-05-15 23:59:59"),
want: "2020-06-30 23:59:59",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, tt.carbon.EndOfQuarter().ToDateTimeString(), "EndOfQuarter()")
})
}
}
func TestCarbon_StartOfMonth(t *testing.T) {
tests := []struct {
name string
carbon Carbon
want string
}{
{
name: "case1",
carbon: Parse(""),
want: "",
},
{
name: "case2",
carbon: Parse("xxx"),
want: "",
},
{
name: "case3",
carbon: Parse("2020-01-15 00:00:00"),
want: "2020-01-01 00:00:00",
},
{
name: "case4",
carbon: Parse("2020-02-15 00:00:00"),
want: "2020-02-01 00:00:00",
},
{
name: "case5",
carbon: Parse("2020-03-15 00:00:00"),
want: "2020-03-01 00:00:00",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, tt.carbon.StartOfMonth().ToDateTimeString(), "StartOfMonth()")
})
}
}
func TestCarbon_EndOfMonth(t *testing.T) {
tests := []struct {
name string
carbon Carbon
want string
}{
{
name: "case1",
carbon: Parse(""),
want: "",
},
{
name: "case2",
carbon: Parse("xxx"),
want: "",
},
{
name: "case3",
carbon: Parse("2020-01-15 00:00:00"),
want: "2020-01-31 23:59:59",
},
{
name: "case4",
carbon: Parse("2020-02-15 00:00:00"),
want: "2020-02-29 23:59:59",
},
{
name: "case5",
carbon: Parse("2020-03-15 00:00:00"),
want: "2020-03-31 23:59:59",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, tt.carbon.EndOfMonth().ToDateTimeString(), "EndOfMonth()")
})
}
}
func TestCarbon_StartOfWeek(t *testing.T) {
tests := []struct {
name string
carbon Carbon
want string
}{
{
name: "case1",
carbon: Parse(""),
want: "",
},
{
name: "case2",
carbon: Parse("xxx"),
want: "",
},
{
name: "case3",
carbon: Parse("2021-06-13"),
want: "2021-06-13 00:00:00",
},
{
name: "case4",
carbon: Parse("2021-06-14"),
want: "2021-06-13 00:00:00",
},
{
name: "case5",
carbon: Parse("2021-06-18"),
want: "2021-06-13 00:00:00",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, tt.carbon.StartOfWeek().ToDateTimeString(), "StartOfWeek()")
})
}
}
func TestCarbon_EndOfWeek(t *testing.T) {
tests := []struct {
name string
carbon Carbon
want string
}{
{
name: "case1",
carbon: Parse(""),
want: "",
},
{
name: "case2",
carbon: Parse("xxx"),
want: "",
},
{
name: "case3",
carbon: Parse("2021-06-13"),
want: "2021-06-19 23:59:59",
},
{
name: "case4",
carbon: Parse("2021-06-14"),
want: "2021-06-19 23:59:59",
},
{
name: "case5",
carbon: Parse("2021-06-18"),
want: "2021-06-19 23:59:59",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, tt.carbon.EndOfWeek().ToDateTimeString(), "EndOfWeek()")
})
}
}
func TestCarbon_StartOfDay(t *testing.T) {
tests := []struct {
name string
carbon Carbon
want string
}{
{
name: "case1",
carbon: Parse(""),
want: "",
},
{
name: "case2",
carbon: Parse("xxx"),
want: "",
},
{
name: "case3",
carbon: Parse("2020-01-15 00:00:00"),
want: "2020-01-15 00:00:00",
},
{
name: "case4",
carbon: Parse("2020-02-15 00:00:00"),
want: "2020-02-15 00:00:00",
},
{
name: "case5",
carbon: Parse("2020-03-15 00:00:00"),
want: "2020-03-15 00:00:00",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, tt.carbon.StartOfDay().ToDateTimeString(), "StartOfDay()")
})
}
}
func TestCarbon_EndOfDay(t *testing.T) {
tests := []struct {
name string
carbon Carbon
want string
}{
{
name: "case1",
carbon: Parse(""),
want: "",
},
{
name: "case2",
carbon: Parse("xxx"),
want: "",
},
{
name: "case3",
carbon: Parse("2020-01-15 00:00:00"),
want: "2020-01-15 23:59:59",
},
{
name: "case4",
carbon: Parse("2020-02-15 00:00:00"),
want: "2020-02-15 23:59:59",
},
{
name: "case5",
carbon: Parse("2020-03-15 00:00:00"),
want: "2020-03-15 23:59:59",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, tt.carbon.EndOfDay().ToDateTimeString(), "EndOfDay()")
})
}
}
func TestCarbon_StartOfHour(t *testing.T) {
tests := []struct {
name string
carbon Carbon
want string
}{
{
name: "case1",
carbon: Parse(""),
want: "",
},
{
name: "case2",
carbon: Parse("xxx"),
want: "",
},
{
name: "case3",
carbon: Parse("2020-01-15 00:00:00"),
want: "2020-01-15 00:00:00",
},
{
name: "case4",
carbon: Parse("2020-02-15 00:00:00"),
want: "2020-02-15 00:00:00",
},
{
name: "case5",
carbon: Parse("2020-03-15 00:00:00"),
want: "2020-03-15 00:00:00",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, tt.carbon.StartOfHour().ToDateTimeString(), "StartOfHour()")
})
}
}
func TestCarbon_EndOfHour(t *testing.T) {
tests := []struct {
name string
carbon Carbon
want string
}{
{
name: "case1",
carbon: Parse(""),
want: "",
},
{
name: "case2",
carbon: Parse("xxx"),
want: "",
},
{
name: "case3",
carbon: Parse(""),
want: "",
},
{
name: "case4",
carbon: Parse("xxx"),
want: "",
},
{
name: "case5",
carbon: Parse("2020-01-15 00:00:00"),
want: "2020-01-15 00:59:59",
},
{
name: "case6",
carbon: Parse("2020-02-15 00:00:00"),
want: "2020-02-15 00:59:59",
},
{
name: "case7",
carbon: Parse("2020-03-15 00:00:00"),
want: "2020-03-15 00:59:59",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, tt.carbon.EndOfHour().ToDateTimeString(), "EndOfHour()")
})
}
}
func TestCarbon_StartOfMinute(t *testing.T) {
tests := []struct {
name string
carbon Carbon
want string
}{
{
name: "case1",
carbon: Parse(""),
want: "",
},
{
name: "case2",
carbon: Parse("xxx"),
want: "",
},
{
name: "case3",
carbon: Parse(""),
want: "",
},
{
name: "case4",
carbon: Parse("xxx"),
want: "",
},
{
name: "case5",
carbon: Parse("2020-01-15 00:00:00"),
want: "2020-01-15 00:00:00",
},
{
name: "case6",
carbon: Parse("2020-02-15 00:00:00"),
want: "2020-02-15 00:00:00",
},
{
name: "case7",
carbon: Parse("2020-03-15 00:00:00"),
want: "2020-03-15 00:00:00",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, tt.carbon.StartOfMinute().ToDateTimeString(), "StartOfMinute()")
})
}
}
func TestCarbon_EndOfMinute(t *testing.T) {
tests := []struct {
name string
carbon Carbon
want string
}{
{
name: "case1",
carbon: Parse(""),
want: "",
},
{
name: "case2",
carbon: Parse("xxx"),
want: "",
},
{
name: "case3",
carbon: Parse("2020-01-15 00:00:00"),
want: "2020-01-15 00:00:59",
},
{
name: "case4",
carbon: Parse("2020-02-15 00:00:00"),
want: "2020-02-15 00:00:59",
},
{
name: "case5",
carbon: Parse("2020-03-15 00:00:00"),
want: "2020-03-15 00:00:59",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, tt.carbon.EndOfMinute().ToDateTimeString(), "EndOfMinute()")
})
}
}
func TestCarbon_StartOfSecond(t *testing.T) {
tests := []struct {
name string
carbon Carbon
want string
}{
{
name: "case1",
carbon: Parse(""),
want: "",
},
{
name: "case2",
carbon: Parse("xxx"),
want: "",
},
{
name: "case3",
carbon: Parse("2020-01-15 00:00:00.999999999", PRC),
want: "2020-01-15 00:00:00 +0800 CST",
},
{
name: "case4",
carbon: Parse("2020-02-15 00:00:00.999999999", PRC),
want: "2020-02-15 00:00:00 +0800 CST",
},
{
name: "case5",
carbon: Parse("2020-03-15 00:00:00.999999999", PRC),
want: "2020-03-15 00:00:00 +0800 CST",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, tt.carbon.StartOfSecond().ToString(), "StartOfSecond()")
})
}
}
func TestCarbon_EndOfSecond(t *testing.T) {
tests := []struct {
name string
carbon Carbon
want string
}{
{
name: "case1",
carbon: Parse(""),
want: "",
},
{
name: "case2",
carbon: Parse("xxx"),
want: "",
},
{
name: "case3",
carbon: Parse("2020-01-15 00:00:00.123", PRC),
want: "2020-01-15 00:00:00.999999999 +0800 CST",
},
{
name: "case4",
carbon: Parse("2020-02-15 00:00:00.123", PRC),
want: "2020-02-15 00:00:00.999999999 +0800 CST",
},
{
name: "case5",
carbon: Parse("2020-03-15 00:00:00.123", PRC),
want: "2020-03-15 00:00:00.999999999 +0800 CST",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, tt.carbon.EndOfSecond().ToString(), "EndOfSecond()")
})
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。