2021-02-18 14:32:31 +08:00
|
|
|
package carbon
|
|
|
|
|
|
|
|
import (
|
2021-07-19 09:33:57 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
2024-04-09 20:12:49 +08:00
|
|
|
"testing"
|
2021-02-18 14:32:31 +08:00
|
|
|
)
|
|
|
|
|
2023-11-06 20:17:40 +08:00
|
|
|
func TestCarbon_IsDST(t *testing.T) {
|
|
|
|
tzWithDST, tzWithoutDST := "Australia/Sydney", "Australia/Brisbane"
|
|
|
|
|
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
carbon Carbon
|
|
|
|
want bool
|
2023-11-06 20:17:40 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
carbon: Parse(""),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon: NewCarbon(),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
carbon: Parse("0000-01-01 00:00:00 +0000 UTC", tzWithDST),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case4",
|
|
|
|
carbon: Parse("0001-01-01 00:00:00 +0000 UTC", tzWithDST),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case5",
|
|
|
|
carbon: Parse("2009-01-01", tzWithDST),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case6",
|
|
|
|
carbon: Parse("2009-01-01", tzWithoutDST),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.carbon.IsDST(), "IsDST()")
|
|
|
|
})
|
2023-11-06 20:17:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-18 14:32:31 +08:00
|
|
|
func TestCarbon_IsZero(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
carbon Carbon
|
|
|
|
want bool
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
carbon: Parse(""),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon: NewCarbon(),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
carbon: Parse("0000-01-01 00:00:00 +0000 UTC"),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case4",
|
|
|
|
carbon: Parse("0001-01-01 00:00:00 +0000 UTC"),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case5",
|
2024-11-29 15:35:28 +08:00
|
|
|
carbon: Parse("2020-08-00 00:00:00"),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case6",
|
|
|
|
carbon: Parse("2020-00-05 00:00:00"),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case7",
|
|
|
|
carbon: Parse("2020-00-00 00:00:00"),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case8",
|
2024-04-09 20:12:49 +08:00
|
|
|
carbon: Parse("2020-08-05 00:00:00"),
|
|
|
|
want: false,
|
|
|
|
},
|
2024-11-29 11:21:54 +08:00
|
|
|
{
|
2024-11-29 15:35:28 +08:00
|
|
|
name: "case9",
|
2024-11-29 11:21:54 +08:00
|
|
|
carbon: Parse("0000-01-01 13:14:15"),
|
|
|
|
want: false,
|
|
|
|
},
|
2024-04-09 20:12:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.carbon.IsZero(), "IsZero()")
|
|
|
|
})
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-21 15:04:03 +08:00
|
|
|
func TestCarbon_IsValid(t *testing.T) {
|
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
carbon Carbon
|
|
|
|
want bool
|
2022-04-21 15:04:03 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
carbon: Parse(""),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon: NewCarbon(),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
2024-11-29 15:09:43 +08:00
|
|
|
carbon: Parse("2024-00-00 00:00:00 +0000 UTC"),
|
2024-04-09 20:12:49 +08:00
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case4",
|
2024-11-29 15:09:43 +08:00
|
|
|
carbon: Parse("0000-01-01 00:00:00 +0000 UTC"),
|
2024-11-29 11:21:54 +08:00
|
|
|
want: true,
|
2024-04-09 20:12:49 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case5",
|
2024-11-29 15:09:43 +08:00
|
|
|
carbon: Parse("0001-01-01 13:14:15 +0000 UTC"),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case6",
|
2024-04-09 20:12:49 +08:00
|
|
|
carbon: Parse("2020-08-05"),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.carbon.IsValid(), "IsValid()")
|
|
|
|
})
|
2022-04-21 15:04:03 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-23 10:53:27 +08:00
|
|
|
func TestCarbon_IsInvalid(t *testing.T) {
|
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
carbon Carbon
|
|
|
|
want bool
|
2021-07-23 10:53:27 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
carbon: Parse(""),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon: NewCarbon(),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
carbon: Parse("0000-01-01 00:00:00 +0000 UTC"),
|
2024-11-29 15:09:43 +08:00
|
|
|
want: false,
|
2024-04-09 20:12:49 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case4",
|
2024-11-29 11:21:54 +08:00
|
|
|
carbon: Parse("0001-01-01 13:14:15 +0000 UTC"),
|
|
|
|
want: false,
|
2024-04-09 20:12:49 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case5",
|
|
|
|
carbon: Parse("2020-08-05"),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.carbon.IsInvalid(), "IsInvalid()")
|
|
|
|
})
|
2021-07-23 10:53:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-12 10:57:10 +08:00
|
|
|
func TestCarbon_IsAM(t *testing.T) {
|
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
carbon Carbon
|
|
|
|
want bool
|
2024-01-12 10:57:10 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
carbon: Parse(""),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon: Parse("2020-08-05 00:00:00"),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
carbon: Parse("2020-08-05 08:00:00"),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case4",
|
|
|
|
carbon: Parse("2020-08-05 12:00:00"),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.carbon.IsAM(), "IsAM()")
|
|
|
|
})
|
2024-01-12 10:57:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsPM(t *testing.T) {
|
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
carbon Carbon
|
|
|
|
want bool
|
2024-01-12 10:57:10 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
carbon: Parse(""),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon: Parse("2020-08-05 00:00:00"),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
carbon: Parse("2020-08-05 08:00:00"),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case4",
|
|
|
|
carbon: Parse("2020-08-05 12:00:00"),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.carbon.IsPM(), "IsPM()")
|
|
|
|
})
|
2024-01-12 10:57:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-18 14:32:31 +08:00
|
|
|
func TestCarbon_IsNow(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
carbon Carbon
|
|
|
|
want bool
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
carbon: Parse(""),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon: Tomorrow(),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
carbon: Yesterday(),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case4",
|
|
|
|
carbon: Now(),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.carbon.IsNow(), "IsNow()")
|
|
|
|
})
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsFuture(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
carbon Carbon
|
|
|
|
want bool
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
carbon: Parse(""),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon: Tomorrow(),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
carbon: Yesterday(),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case4",
|
|
|
|
carbon: Now(),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.carbon.IsFuture(), "IsFuture()")
|
|
|
|
})
|
2021-07-19 09:33:57 +08:00
|
|
|
}
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsPast(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
carbon Carbon
|
|
|
|
want bool
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
carbon: Parse(""),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon: Tomorrow(),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
carbon: Yesterday(),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case4",
|
|
|
|
carbon: Now(),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.carbon.IsPast(), "IsPast()")
|
|
|
|
})
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsLeapYear(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
carbon Carbon
|
|
|
|
want bool
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
carbon: Parse(""),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon: Parse("2015-01-01"),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
carbon: Parse("2016-01-01"),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case4",
|
|
|
|
carbon: Parse("2017-01-01"),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.carbon.IsLeapYear(), "IsLeapYear()")
|
|
|
|
})
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsLongYear(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
carbon Carbon
|
|
|
|
want bool
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
carbon: Parse(""),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon: Parse("2015-01-01"),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
carbon: Parse("2016-01-01"),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case4",
|
|
|
|
carbon: Parse("2017-01-01"),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.carbon.IsLongYear(), "IsLongYear()")
|
|
|
|
})
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsJanuary(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
carbon Carbon
|
|
|
|
want bool
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
carbon: Parse(""),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon: Parse("2020-01-01"),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
carbon: Parse("2020-02-01"),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.carbon.IsJanuary(), "IsJanuary()")
|
|
|
|
})
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsFebruary(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
carbon Carbon
|
|
|
|
want bool
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
carbon: Parse(""),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon: Parse("2020-01-01"),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
carbon: Parse("2020-02-01"),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.carbon.IsFebruary(), "IsFebruary()")
|
|
|
|
})
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsMarch(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
carbon Carbon
|
|
|
|
want bool
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
carbon: Parse(""),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon: Parse("2020-01-01"),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
carbon: Parse("2020-03-01"),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.carbon.IsMarch(), "IsMarch()")
|
|
|
|
})
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsApril(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
carbon Carbon
|
|
|
|
want bool
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
carbon: Parse(""),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon: Parse("2020-01-01"),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
carbon: Parse("2020-04-01"),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.carbon.IsApril(), "IsApril()")
|
|
|
|
})
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsMay(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
carbon Carbon
|
|
|
|
want bool
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
carbon: Parse(""),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon: Parse("2020-01-01"),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
carbon: Parse("2020-05-01"),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.carbon.IsMay(), "IsMay()")
|
|
|
|
})
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsJune(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
carbon Carbon
|
|
|
|
want bool
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
carbon: Parse(""),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon: Parse("2020-01-01"),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
carbon: Parse("2020-06-01"),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.carbon.IsJune(), "IsJune()")
|
|
|
|
})
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsJuly(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
carbon Carbon
|
|
|
|
want bool
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
carbon: Parse(""),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon: Parse("2020-01-01"),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
carbon: Parse("2020-07-01"),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.carbon.IsJuly(), "IsJuly()")
|
|
|
|
})
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsAugust(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
carbon Carbon
|
|
|
|
want bool
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
carbon: Parse(""),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon: Parse("2020-01-01"),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
carbon: Parse("2020-08-01"),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.carbon.IsAugust(), "IsAugust()")
|
|
|
|
})
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsSeptember(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
carbon Carbon
|
|
|
|
want bool
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
carbon: Parse(""),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon: Parse("2020-01-01"),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
carbon: Parse("2020-09-01"),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.carbon.IsSeptember(), "IsSeptember()")
|
|
|
|
})
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsOctober(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
carbon Carbon
|
|
|
|
want bool
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
carbon: Parse(""),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon: Parse("2020-01-01"),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
carbon: Parse("2020-10-01"),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.carbon.IsOctober(), "IsOctober()")
|
|
|
|
})
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsNovember(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
carbon Carbon
|
|
|
|
want bool
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
carbon: Parse(""),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon: Parse("2020-01-01"),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
carbon: Parse("2020-11-01"),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.carbon.IsNovember(), "IsNovember()")
|
|
|
|
})
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsDecember(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
carbon Carbon
|
|
|
|
want bool
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
carbon: Parse(""),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon: Parse("2020-01-01"),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
carbon: Parse("2020-12-01"),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.carbon.IsDecember(), "IsDecember()")
|
|
|
|
})
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsMonday(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
carbon Carbon
|
|
|
|
want bool
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
carbon: Parse(""),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon: Parse("2020-10-01"),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
carbon: Parse("2020-10-05"),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.carbon.IsMonday(), "IsMonday()")
|
|
|
|
})
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsTuesday(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
carbon Carbon
|
|
|
|
want bool
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
carbon: Parse(""),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon: Parse("2020-10-01"),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
carbon: Parse("2020-10-06"),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.carbon.IsTuesday(), "IsTuesday()")
|
|
|
|
})
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsWednesday(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
carbon Carbon
|
|
|
|
want bool
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
carbon: Parse(""),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon: Parse("2020-10-01"),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
carbon: Parse("2020-10-07"),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.carbon.IsWednesday(), "IsWednesday()")
|
|
|
|
})
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsThursday(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
carbon Carbon
|
|
|
|
want bool
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
carbon: Parse(""),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon: Parse("2020-10-05"),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
carbon: Parse("2020-10-08"),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.carbon.IsThursday(), "IsThursday()")
|
|
|
|
})
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsFriday(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
carbon Carbon
|
|
|
|
want bool
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
carbon: Parse(""),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon: Parse("2020-10-01"),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
carbon: Parse("2020-10-09"),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.carbon.IsFriday(), "IsFriday()")
|
|
|
|
})
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsSaturday(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
carbon Carbon
|
|
|
|
want bool
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
carbon: Parse(""),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon: Parse("2020-10-01"),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
carbon: Parse("2020-10-10"),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.carbon.IsSaturday(), "IsSaturday()")
|
|
|
|
})
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsSunday(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
carbon Carbon
|
|
|
|
want bool
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
carbon: Parse(""),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon: Parse("2020-10-01"),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
carbon: Parse("2020-10-11"),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.carbon.IsSunday(), "IsSunday()")
|
|
|
|
})
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsWeekday(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
carbon Carbon
|
|
|
|
want bool
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
carbon: Parse(""),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon: Parse("2020-10-05"),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
carbon: Parse("2020-10-10"),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.carbon.IsWeekday(), "IsWeekday()")
|
|
|
|
})
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsWeekend(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
carbon Carbon
|
|
|
|
want bool
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
carbon: Parse(""),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon: Parse("2020-10-05"),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
carbon: Parse("2020-10-10"),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.carbon.IsWeekend(), "IsWeekend()")
|
|
|
|
})
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsYesterday(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
carbon Carbon
|
|
|
|
want bool
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
carbon: Parse(""),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon: NewCarbon(),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
carbon: Yesterday(),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case4",
|
|
|
|
carbon: Tomorrow(),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case5",
|
|
|
|
carbon: Now(),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.carbon.IsYesterday(), "IsYesterday()")
|
|
|
|
})
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsToday(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
carbon Carbon
|
|
|
|
want bool
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
carbon: Parse(""),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon: NewCarbon(),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
carbon: Yesterday(),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case4",
|
|
|
|
carbon: Tomorrow(),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case5",
|
|
|
|
carbon: Now(),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.carbon.IsToday(), "IsToday()")
|
|
|
|
})
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsTomorrow(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
|
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
carbon Carbon
|
|
|
|
want bool
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
carbon: Parse(""),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon: NewCarbon(),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
carbon: Yesterday(),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case4",
|
|
|
|
carbon: Tomorrow(),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case5",
|
|
|
|
carbon: Now(),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.carbon.IsTomorrow(), "IsTomorrow()")
|
|
|
|
})
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-20 00:02:30 +08:00
|
|
|
func TestCarbon_IsSameCentury(t *testing.T) {
|
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
carbon1 Carbon
|
|
|
|
carbon2 Carbon
|
|
|
|
want bool
|
2022-05-20 00:02:30 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
carbon1: Parse(""),
|
|
|
|
carbon2: Parse(""),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon1: Parse("xxx"),
|
|
|
|
carbon2: Parse("xxx"),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon1: Parse("2020-08-05"),
|
|
|
|
carbon2: Parse("3020-08-05"),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
carbon1: Parse("2020-08-05"),
|
|
|
|
carbon2: Parse("2099-08-05"),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.carbon1.IsSameCentury(tt.carbon2), "IsSameCentury()")
|
|
|
|
})
|
2022-05-20 00:02:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsSameDecade(t *testing.T) {
|
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
carbon1 Carbon
|
|
|
|
carbon2 Carbon
|
|
|
|
want bool
|
2022-05-20 00:02:30 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
carbon1: Parse(""),
|
|
|
|
carbon2: Parse(""),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon1: Parse("2020-08-05"),
|
|
|
|
carbon2: Parse("2030-08-05"),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
carbon1: Parse("2020-08-05"),
|
|
|
|
carbon2: Parse("2021-08-05"),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.carbon1.IsSameDecade(tt.carbon2), "IsSameDecade()")
|
|
|
|
})
|
2022-05-20 00:02:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsSameYear(t *testing.T) {
|
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
carbon1 Carbon
|
|
|
|
carbon2 Carbon
|
|
|
|
want bool
|
2022-05-20 00:02:30 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
carbon1: Parse(""),
|
|
|
|
carbon2: Parse(""),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon1: Parse("2020-08-05"),
|
|
|
|
carbon2: Parse("2021-08-05"),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
carbon1: Parse("2020-01-01"),
|
|
|
|
carbon2: Parse("2020-12-31"),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.carbon1.IsSameYear(tt.carbon2), "IsSameYear()")
|
|
|
|
})
|
2022-05-20 00:02:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsSameQuarter(t *testing.T) {
|
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
carbon1 Carbon
|
|
|
|
carbon2 Carbon
|
|
|
|
want bool
|
2022-05-20 00:02:30 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
carbon1: Parse(""),
|
|
|
|
carbon2: Parse(""),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon1: Parse("2020-08-05"),
|
|
|
|
carbon2: Parse("2020-01-05"),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
carbon1: Parse("2020-01-01"),
|
|
|
|
carbon2: Parse("2020-01-31"),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.carbon1.IsSameQuarter(tt.carbon2), "IsSameQuarter()")
|
|
|
|
})
|
2022-05-20 00:02:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsSameMonth(t *testing.T) {
|
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
carbon1 Carbon
|
|
|
|
carbon2 Carbon
|
|
|
|
want bool
|
2022-05-20 00:02:30 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
carbon1: Parse(""),
|
|
|
|
carbon2: Parse(""),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon1: Parse("2020-08-05"),
|
|
|
|
carbon2: Parse("2021-08-05"),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
carbon1: Parse("2020-01-01"),
|
|
|
|
carbon2: Parse("2020-01-31"),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.carbon1.IsSameMonth(tt.carbon2), "IsSameMonth()")
|
|
|
|
})
|
2022-05-20 00:02:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsSameDay(t *testing.T) {
|
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
carbon1 Carbon
|
|
|
|
carbon2 Carbon
|
|
|
|
want bool
|
2022-05-20 00:02:30 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
carbon1: Parse(""),
|
|
|
|
carbon2: Parse(""),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon1: Parse("2020-08-05 13:14:15"),
|
|
|
|
carbon2: Parse("2021-08-05 13:14:15"),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
carbon1: Parse("2020-08-05 00:00:00"),
|
|
|
|
carbon2: Parse("2020-08-05 13:14:15"),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.carbon1.IsSameDay(tt.carbon2), "IsSameDay()")
|
|
|
|
})
|
2022-05-20 00:02:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsSameHour(t *testing.T) {
|
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
carbon1 Carbon
|
|
|
|
carbon2 Carbon
|
|
|
|
want bool
|
2022-05-20 00:02:30 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
carbon1: Parse(""),
|
|
|
|
carbon2: Parse(""),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon1: Parse("2020-08-05 13:14:15"),
|
|
|
|
carbon2: Parse("2021-08-05 13:14:15"),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
carbon1: Parse("2020-08-05 13:00:00"),
|
|
|
|
carbon2: Parse("2020-08-05 13:14:15"),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.carbon1.IsSameHour(tt.carbon2), "IsSameDay()")
|
|
|
|
})
|
2022-05-20 00:02:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsSameMinute(t *testing.T) {
|
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
carbon1 Carbon
|
|
|
|
carbon2 Carbon
|
|
|
|
want bool
|
2022-05-20 00:02:30 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
carbon1: Parse(""),
|
|
|
|
carbon2: Parse(""),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon1: Parse("2020-08-05 13:14:15"),
|
|
|
|
carbon2: Parse("2021-08-05 13:14:15"),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
carbon1: Parse("2020-08-05 13:14:00"),
|
|
|
|
carbon2: Parse("2020-08-05 13:14:15"),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.carbon1.IsSameMinute(tt.carbon2), "IsSameMinute()")
|
|
|
|
})
|
2022-05-20 00:02:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_IsSameSecond(t *testing.T) {
|
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
carbon1 Carbon
|
|
|
|
carbon2 Carbon
|
|
|
|
want bool
|
2022-05-20 00:02:30 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
carbon1: Parse(""),
|
|
|
|
carbon2: Parse(""),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
carbon1: Parse("2020-08-05 13:14:15"),
|
|
|
|
carbon2: Parse("2021-08-05 13:14:15"),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
carbon1: Parse("2020-08-05 13:14:15"),
|
|
|
|
carbon2: Parse("2020-08-05 13:14:15"),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.carbon1.IsSameSecond(tt.carbon2), "IsSameSecond()")
|
|
|
|
})
|
2022-05-20 00:02:30 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-18 14:32:31 +08:00
|
|
|
func TestCarbon_Compare(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
actual bool
|
|
|
|
want bool
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
actual: Parse("xxx").Compare(">", Parse("2020-08-04")),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
actual: Parse("2020-08-05").Compare(">", Parse("2020-08-04")),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
actual: Parse("2020-08-05").Compare("<", Parse("2020-08-04")),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case4",
|
|
|
|
actual: Parse("2020-08-05").Compare("<", Parse("2020-08-06")),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case5",
|
|
|
|
actual: Parse("2020-08-05").Compare("=", Parse("2020-08-05")),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case6",
|
|
|
|
actual: Parse("2020-08-05").Compare(">=", Parse("2020-08-05")),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case7",
|
|
|
|
actual: Parse("2020-08-05").Compare("<=", Parse("2020-08-05")),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case8",
|
|
|
|
actual: Parse("2020-08-05").Compare("<>", Parse("2020-08-06")),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case9",
|
|
|
|
actual: Parse("2020-08-05").Compare("+", Parse("2020-08-06")),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.actual, "Compare()")
|
|
|
|
})
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_Gt(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
actual bool
|
|
|
|
want bool
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
actual: Parse("xxx").Gt(Parse("2020-08-04")),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
actual: Parse("2020-08-05").Gt(Parse("2020-08-04")),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
actual: Parse("2020-08-05").Gt(Parse("2020-08-04")),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case4",
|
|
|
|
actual: Parse("2020-08-05").Gt(Parse("2020-08-06")),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.actual, "Gt()")
|
|
|
|
})
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_Lt(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
actual bool
|
|
|
|
want bool
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
actual: Parse("xxx").Lt(Parse("2020-08-04")),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
actual: Parse("2020-08-05").Lt(Parse("2020-08-04")),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
actual: Parse("2020-08-05").Lt(Parse("2020-08-04")),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case4",
|
|
|
|
actual: Parse("2020-08-05").Lt(Parse("2020-08-06")),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.actual, "Lt()")
|
|
|
|
})
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_Eq(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
actual bool
|
|
|
|
want bool
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
actual: Parse("xxx").Eq(Parse("2020-08-05")),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
actual: Parse("2020-08-05").Eq(Parse("2020-08-05")),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
actual: Parse("2020-08-05").Eq(Parse("2020-08-04")),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case4",
|
|
|
|
actual: Parse("2020-08-05").Eq(Parse("2020-08-06")),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.actual, "Eq()")
|
|
|
|
})
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_Ne(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
actual bool
|
|
|
|
want bool
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
actual: Parse("xxx").Ne(Parse("2020-08-05")),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
actual: Parse("2020-08-05").Ne(Parse("2020-08-05")),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
actual: Parse("2020-08-05").Ne(Parse("2020-08-04")),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case4",
|
|
|
|
actual: Parse("2020-08-05").Ne(Parse("2020-08-06")),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.actual, "Ne()")
|
|
|
|
})
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_Gte(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
actual bool
|
|
|
|
want bool
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
actual: Parse("xxx").Gte(Parse("2020-08-05")),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
actual: Parse("2020-08-05").Gte(Parse("2020-08-05")),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
actual: Parse("2020-08-05").Gte(Parse("2020-08-04")),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case4",
|
|
|
|
actual: Parse("2020-08-05").Gte(Parse("2020-08-06")),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.actual, "Gte()")
|
|
|
|
})
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_Lte(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
actual bool
|
|
|
|
want bool
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
actual: Parse("xxx").Lte(Parse("2020-08-05")),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
actual: Parse("2020-08-05").Lte(Parse("2020-08-05")),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
actual: Parse("2020-08-05").Lte(Parse("2020-08-04")),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case4",
|
|
|
|
actual: Parse("2020-08-05").Lte(Parse("2020-08-06")),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.actual, "Lte()")
|
|
|
|
})
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCarbon_Between(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
actual bool
|
|
|
|
want bool
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
actual: Parse("xxx").Between(Parse("2020-08-05"), Parse("2020-08-05")),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
actual: Parse("2020-08-05").Between(Parse("2020-08-05"), Parse("2020-08-05")),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
actual: Parse("2020-08-05").Between(Parse("2020-08-05"), Parse("2020-08-06")),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case4",
|
|
|
|
actual: Parse("2020-08-05").Between(Parse("2020-08-05"), Parse("2020-08-05")),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case5",
|
|
|
|
actual: Parse("2020-08-05").Between(Parse("2020-08-04"), Parse("2020-08-06")),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.actual, "Between()")
|
|
|
|
})
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-23 23:03:13 +08:00
|
|
|
func TestCarbon_BetweenIncludedStart(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
actual bool
|
|
|
|
want bool
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
actual: Parse("xxx").BetweenIncludedStart(Parse("2020-08-05"), Parse("2020-08-05")),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
actual: Parse("2020-08-05").BetweenIncludedStart(Parse("2020-08-05"), Parse("2020-08-05")),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
actual: Parse("2020-08-05").BetweenIncludedStart(Parse("2020-08-05"), Parse("2020-08-06")),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case4",
|
|
|
|
actual: Parse("2020-08-05").BetweenIncludedStart(Parse("2020-08-04"), Parse("2020-08-05")),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case5",
|
|
|
|
actual: Parse("2020-08-05").BetweenIncludedStart(Parse("2020-08-04"), Parse("2020-08-06")),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.actual, "BetweenIncludedStart()")
|
|
|
|
})
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-23 23:03:13 +08:00
|
|
|
func TestCarbon_BetweenIncludedEnd(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
actual bool
|
|
|
|
want bool
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
actual: Parse("xxx").BetweenIncludedEnd(Parse("2020-08-05"), Parse("2020-08-05")),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
actual: Parse("2020-08-05").BetweenIncludedEnd(Parse("2020-08-05"), Parse("2020-08-05")),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
actual: Parse("2020-08-05").BetweenIncludedEnd(Parse("2020-08-05"), Parse("2020-08-06")),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case4",
|
|
|
|
actual: Parse("2020-08-05").BetweenIncludedEnd(Parse("2020-08-04"), Parse("2020-08-05")),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case5",
|
|
|
|
actual: Parse("2020-08-05").BetweenIncludedEnd(Parse("2020-08-04"), Parse("2020-08-06")),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.actual, "BetweenIncludedEnd()")
|
|
|
|
})
|
2021-02-18 14:32:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-23 23:03:13 +08:00
|
|
|
func TestCarbon_BetweenIncludedBoth(t *testing.T) {
|
2021-07-19 09:33:57 +08:00
|
|
|
tests := []struct {
|
2024-04-09 20:12:49 +08:00
|
|
|
name string
|
|
|
|
actual bool
|
|
|
|
want bool
|
2021-02-18 14:32:31 +08:00
|
|
|
}{
|
2024-04-09 20:12:49 +08:00
|
|
|
{
|
|
|
|
name: "case1",
|
|
|
|
actual: Parse("xxx").BetweenIncludedBoth(Parse("2020-08-05"), Parse("2020-08-05")),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case2",
|
|
|
|
actual: Parse("2020-08-05").BetweenIncludedBoth(Parse("2020-08-05"), Parse("2020-08-05")),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case3",
|
|
|
|
actual: Parse("2020-08-05").BetweenIncludedBoth(Parse("2020-08-05"), Parse("2020-08-06")),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case4",
|
|
|
|
actual: Parse("2020-08-05").BetweenIncludedBoth(Parse("2020-08-04"), Parse("2020-08-05")),
|
|
|
|
want: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "case5",
|
|
|
|
actual: Parse("2020-08-05").BetweenIncludedBoth(Parse("2020-08-06"), Parse("2020-08-06")),
|
|
|
|
want: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
assert.Equalf(t, tt.want, tt.actual, "BetweenIncludedBoth()")
|
|
|
|
})
|
2021-07-19 09:33:57 +08:00
|
|
|
}
|
2022-04-14 10:40:28 +08:00
|
|
|
}
|