代码拉取完成,页面将自动刷新
同步操作将从 dromara/carbon 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
package carbon
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestCarbon_Lunar(t *testing.T) {
tests := []struct {
name string
carbon Carbon
want string
}{
{
name: "case1",
carbon: Parse("xxx", PRC),
want: "",
},
{
name: "case2",
carbon: Parse("2024-01-18", PRC),
want: "2023-12-08 00:00:00",
},
{
name: "case3",
carbon: Parse("2024-01-21", PRC),
want: "2023-12-11 00:00:00",
},
{
name: "case4",
carbon: Parse("2024-01-24", PRC),
want: "2023-12-14 00:00:00",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, tt.carbon.Lunar().String(), "Lunar()")
})
}
}
func TestCreateFromLunar(t *testing.T) {
tests := []struct {
name string
carbon Carbon
want string
}{
{
name: "case1",
carbon: CreateFromLunar(2023, 12, 11, 0, 0, 0, false),
want: "2024-01-21 00:00:00",
},
{
name: "case2",
carbon: CreateFromLunar(2023, 12, 8, 0, 0, 0, false),
want: "2024-01-18 00:00:00",
},
{
name: "case3",
carbon: CreateFromLunar(2023, 12, 14, 12, 0, 0, false),
want: "2024-01-24 12:00:00",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, tt.carbon.ToDateTimeString(), "CreateFromLunar()")
})
}
}
func TestCarbon_Julian(t *testing.T) {
tests := []struct {
name string
carbon Carbon
wantJD float64
wantMJD float64
}{
{
name: "case1",
carbon: Parse("xxx"),
wantJD: 0,
wantMJD: 0,
},
{
name: "case2",
carbon: Parse("2024-01-24 12:00:00"),
wantJD: 2460334,
wantMJD: 60333.5,
},
{
name: "case3",
carbon: CreateFromJulian(2460334),
wantJD: 2460334,
wantMJD: 60333.5,
},
{
name: "case4",
carbon: CreateFromJulian(60333.5),
wantJD: 2460334,
wantMJD: 60333.5,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.wantJD, tt.carbon.Julian().JD(), "JD()")
assert.Equalf(t, tt.wantMJD, tt.carbon.Julian().MJD(), "MJD()")
})
}
}
func TestCarbon_CreateFromJulian(t *testing.T) {
tests := []struct {
name string
carbon Carbon
want string
}{
{
name: "case1",
carbon: CreateFromJulian(2460334),
want: "2024-01-24 12:00:00",
},
{
name: "case2",
carbon: CreateFromJulian(60333.5),
want: "2024-01-24 12:00:00",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, tt.carbon.ToDateTimeString(), "CreateFromJulian()")
})
}
}
func TestCarbon_Persian(t *testing.T) {
tests := []struct {
name string
carbon Carbon
want string
}{
{
name: "case1",
carbon: Parse("xxx", PRC),
want: "",
},
{
name: "case2",
carbon: Parse("1800-01-01 00:00:00", PRC),
want: "1178-10-11 00:00:00",
},
{
name: "case3",
carbon: Parse("2020-08-05 13:14:15", PRC),
want: "1399-05-15 13:14:15",
},
{
name: "case4",
carbon: Parse("2024-01-01 00:00:00", PRC),
want: "1402-10-11 00:00:00",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, tt.carbon.Persian().String(), "Persian()")
})
}
}
func TestCarbon_CreateFromPersian(t *testing.T) {
tests := []struct {
name string
carbon Carbon
want string
}{
{
name: "case1",
carbon: CreateFromPersian(1178, 10, 11, 0, 0, 0),
want: "1800-01-01 00:00:00",
},
{
name: "case2",
carbon: CreateFromPersian(1402, 10, 11, 0, 0, 0),
want: "2024-01-01 00:00:00",
},
{
name: "case3",
carbon: CreateFromPersian(1403, 5, 15, 12, 0, 0),
want: "2024-08-05 12:00:00",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, tt.carbon.ToDateTimeString(), "CreateFromPersian()")
})
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。