1 Star 0 Fork 63

jangocheng/carbon

forked from dromara/carbon 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
calendar.lunar_unit_test.go 28.16 KB
一键复制 编辑 原始数据 按行查看 历史
gouguoyin 提交于 2023-12-28 14:35 . xxx_test.go -> xxx_unit_test.go
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201
package carbon
import (
"fmt"
"strconv"
"testing"
"github.com/stretchr/testify/assert"
)
func TestLunar_Animal(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string
expected string
}{
0: {"", ""},
1: {"0", ""},
2: {"0000-00-00", ""},
3: {"00:00:00", ""},
4: {"0000-00-00 00:00:00", ""},
5: {"2020-05-01", "鼠"},
6: {"2020-08-05", "鼠"},
7: {"2021-07-07", "牛"},
8: {"2010-08-05", "虎"},
9: {"2011-08-05", "兔"},
10: {"2012-08-05", "龙"},
11: {"2013-08-05", "蛇"},
12: {"2014-08-05", "马"},
13: {"2015-08-05", "羊"},
14: {"2016-08-05", "猴"},
15: {"2017-08-05", "鸡"},
16: {"2018-08-05", "狗"},
17: {"2019-08-05", "猪"},
18: {"2020-04-23", "鼠"},
19: {"2020-05-23", "鼠"}, // special boundary
20: {"2020-06-21", "鼠"}, // special boundary
21: {"2020-08-05", "鼠"},
22: {"2021-05-12", "牛"},
23: {"2021-08-05", "牛"},
24: {"2200-08-05", ""},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Lunar().Animal(), "Current test index is "+strconv.Itoa(index))
}
}
func TestLunar_Festival(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string
expected string
}{
0: {"", ""},
1: {"0", ""},
2: {"0000-00-00", ""},
3: {"00:00:00", ""},
4: {"0000-00-00 00:00:00", ""},
5: {"2020-04-23", ""},
6: {"2021-02-12", "春节"},
7: {"2021-02-26", "元宵节"},
8: {"2021-05-12", ""},
9: {"2021-06-14", "端午节"},
10: {"2021-08-14", "七夕节"},
11: {"2021-08-22", "中元节"},
12: {"2021-09-21", "中秋节"},
13: {"2021-10-14", "重阳节"},
14: {"2021-10-14", "重阳节"},
15: {"2021-11-05", "寒衣节"},
16: {"2021-11-19", "下元节"},
17: {"2022-01-10", "腊八节"},
18: {"2022-01-25", "小年"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Lunar().Festival(), "Current test index is "+strconv.Itoa(index))
}
}
func TestLunar_DateTime(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string
year, month, day, hour, minute, second int
}{
0: {"", 0, 0, 0, 0, 0, 0},
1: {"0", 0, 0, 0, 0, 0, 0},
2: {"0000-00-00", 0, 0, 0, 0, 0, 0},
3: {"00:00:00", 0, 0, 0, 0, 0, 0},
4: {"0000-00-00 00:00:00", 0, 0, 0, 0, 0, 0},
5: {"2020-08-05 13:14:15", 2020, 6, 16, 13, 14, 15},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
year, month, day, hour, minute, second := c.Lunar().DateTime()
assert.Equal(test.year, year, "Current test index is "+strconv.Itoa(index))
assert.Equal(test.month, month, "Current test index is "+strconv.Itoa(index))
assert.Equal(test.day, day, "Current test index is "+strconv.Itoa(index))
assert.Equal(test.hour, hour, "Current test index is "+strconv.Itoa(index))
assert.Equal(test.minute, minute, "Current test index is "+strconv.Itoa(index))
assert.Equal(test.second, second, "Current test index is "+strconv.Itoa(index))
}
}
func TestLunar_Date(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string
year, month, day int
}{
0: {"", 0, 0, 0},
1: {"0", 0, 0, 0},
2: {"0000-00-00", 0, 0, 0},
3: {"00:00:00", 0, 0, 0},
4: {"0000-00-00 00:00:00", 0, 0, 0},
5: {"2020-08-05 13:14:15", 2020, 6, 16},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
year, month, day := c.Lunar().Date()
assert.Equal(test.year, year, "Current test index is "+strconv.Itoa(index))
assert.Equal(test.month, month, "Current test index is "+strconv.Itoa(index))
assert.Equal(test.day, day, "Current test index is "+strconv.Itoa(index))
}
}
func TestLunar_Time(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string
hour, minute, second int
}{
0: {"", 0, 0, 0},
1: {"0", 0, 0, 0},
2: {"0000-00-00", 0, 0, 0},
3: {"00:00:00", 0, 0, 0},
4: {"0000-00-00 00:00:00", 0, 0, 0},
5: {"2020-08-05 13:14:15", 13, 14, 15},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
hour, minute, second := c.Lunar().Time()
assert.Equal(test.hour, hour, "Current test index is "+strconv.Itoa(index))
assert.Equal(test.minute, minute, "Current test index is "+strconv.Itoa(index))
assert.Equal(test.second, second, "Current test index is "+strconv.Itoa(index))
}
}
func TestLunar_Year(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string
expected int
}{
0: {"", 0},
1: {"0", 0},
2: {"0000-00-00", 0},
3: {"00:00:00", 0},
4: {"0000-00-00 00:00:00", 0},
5: {"2020-04-23", 2020},
6: {"2020-05-01", 2020},
7: {"2020-08-05", 2020},
8: {"2021-01-01", 2020},
9: {"2021-05-12", 2021},
10: {"2021-07-07", 2021},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Lunar().Year(), "Current test index is "+strconv.Itoa(index))
}
}
func TestLunar_Month(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string
expected int
}{
0: {"", 0},
1: {"0", 0},
2: {"0000-00-00", 0},
3: {"00:00:00", 0},
4: {"0000-00-00 00:00:00", 0},
5: {"2021-01-05", 11},
6: {"2021-02-05", 12},
7: {"2021-03-05", 1},
8: {"2021-04-05", 2},
9: {"2021-05-05", 3},
10: {"2021-06-05", 4},
11: {"2021-07-05", 5},
12: {"2021-08-05", 6},
13: {"2021-09-05", 7},
14: {"2021-10-05", 8},
15: {"2021-11-05", 10},
16: {"2021-12-05", 11},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Lunar().Month(), "Current test index is "+strconv.Itoa(index))
}
}
func TestLunar_Day(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string
expected int
}{
0: {"", 0},
1: {"0", 0},
2: {"0000-00-00", 0},
3: {"00:00:00", 0},
4: {"0000-00-00 00:00:00", 0},
5: {"2020-08-01", 12},
6: {"2020-08-02", 13},
7: {"2020-08-03", 14},
8: {"2020-08-04", 15},
9: {"2020-08-05", 16},
10: {"2020-08-06", 17},
11: {"2020-08-07", 18},
12: {"2020-08-08", 19},
13: {"2020-08-09", 20},
14: {"2020-08-10", 21},
15: {"2020-08-11", 22},
16: {"2020-08-12", 23},
17: {"2020-08-13", 24},
18: {"2020-08-14", 25},
19: {"2020-08-15", 26},
20: {"2020-08-16", 27},
21: {"2020-08-17", 28},
22: {"2020-08-18", 29},
23: {"2020-08-19", 1},
24: {"2020-08-20", 2},
25: {"2020-08-21", 3},
26: {"2020-08-22", 4},
27: {"2020-08-23", 5},
28: {"2020-08-24", 6},
29: {"2020-08-25", 7},
30: {"2020-08-26", 8},
31: {"2020-08-27", 9},
32: {"2020-08-28", 10},
33: {"2020-08-29", 11},
34: {"2020-08-30", 12},
35: {"2020-08-31", 13},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Lunar().Day(), "Current test index is "+strconv.Itoa(index))
}
}
func TestLunar_LeapMonth(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string
expected int
}{
0: {"", 0},
1: {"0", 0},
2: {"0000-00-00", 0},
3: {"00:00:00", 0},
4: {"0000-00-00 00:00:00", 0},
5: {"2020-04-23", 4},
6: {"2020-05-01", 4},
7: {"2020-08-05", 4},
8: {"2021-07-07", 0},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Lunar().LeapMonth(), "Current test index is "+strconv.Itoa(index))
}
}
func TestLunar_ToYearString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string
expected string
}{
0: {"", ""},
1: {"0", ""},
2: {"0000-00-00", ""},
3: {"00:00:00", ""},
4: {"0000-00-00 00:00:00", ""},
5: {"2020-04-23", "二零二零"},
6: {"2020-05-01", "二零二零"},
7: {"2020-08-05", "二零二零"},
8: {"2021-01-01", "二零二零"},
9: {"2021-05-12", "二零二一"},
10: {"2021-07-07", "二零二一"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Lunar().ToYearString(), "Current test index is "+strconv.Itoa(index))
}
}
func TestLunar_ToMonthString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string
expected string
}{
0: {"", ""},
1: {"0", ""},
2: {"0000-00-00", ""},
3: {"00:00:00", ""},
4: {"0000-00-00 00:00:00", ""},
5: {"2020-01-01", "腊月"},
6: {"2020-02-01", "正月"},
7: {"2020-03-01", "二月"},
8: {"2020-04-01", "三月"},
9: {"2020-04-23", "四月"},
10: {"2020-05-01", "四月"},
11: {"2020-06-01", "四月"},
12: {"2020-07-01", "五月"},
13: {"2020-07-07", "五月"},
14: {"2020-08-01", "六月"},
15: {"2020-09-01", "七月"},
16: {"2020-10-01", "八月"},
17: {"2020-11-01", "九月"},
18: {"2020-12-01", "十月"},
19: {"2021-01-01", "十一月"},
20: {"2021-02-01", "腊月"},
21: {"2021-05-12", "四月"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Lunar().ToMonthString(), "Current test index is "+strconv.Itoa(index))
}
}
func TestLunar_ToDayString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string
expected string
}{
0: {"", ""},
1: {"0", ""},
2: {"0000-00-00", ""},
3: {"00:00:00", ""},
4: {"0000-00-00 00:00:00", ""},
5: {"2020-01-01", "初七"},
6: {"2020-02-01", "初八"},
7: {"2020-03-01", "初八"},
8: {"2020-04-01", "初九"},
9: {"2020-04-23", "初一"},
10: {"2020-05-01", "初九"},
11: {"2020-06-01", "初十"},
12: {"2020-07-01", "十一"},
13: {"2020-08-01", "十二"},
14: {"2020-09-01", "十四"},
15: {"2020-10-01", "十五"},
16: {"2020-11-01", "十六"},
17: {"2020-12-01", "十七"},
18: {"2021-01-03", "二十"},
19: {"2021-01-05", "廿二"},
20: {"2021-04-11", "三十"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Lunar().ToDayString(), "Current test index is "+strconv.Itoa(index))
}
}
func TestLunar_String(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string
expected string
}{
0: {"", ""},
1: {"0", ""},
2: {"0000-00-00", ""},
3: {"00:00:00", ""},
4: {"0000-00-00 00:00:00", ""},
5: {"2020-01-01", "2019-12-07 00:00:00"},
6: {"2020-02-01", "2020-01-08 00:00:00"},
7: {"2020-03-01", "2020-02-08 00:00:00"},
8: {"2020-04-01", "2020-03-09 00:00:00"},
9: {"2020-04-23", "2020-04-01 00:00:00"},
10: {"2020-05-01", "2020-04-09 00:00:00"},
11: {"2020-06-01", "2020-04-10 00:00:00"},
12: {"2020-07-01", "2020-05-11 00:00:00"},
13: {"2020-08-01", "2020-06-12 00:00:00"},
14: {"2020-09-01", "2020-07-14 00:00:00"},
15: {"2020-10-01", "2020-08-15 00:00:00"},
16: {"2020-11-01", "2020-09-16 00:00:00"},
17: {"2020-12-01", "2020-10-17 00:00:00"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, fmt.Sprintf("%s", c.Lunar()), "Current test index is "+strconv.Itoa(index))
}
}
func TestLunar_ToDateString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string
expected string
}{
0: {"", ""},
1: {"0", ""},
2: {"0000-00-00", ""},
3: {"00:00:00", ""},
4: {"0000-00-00 00:00:00", ""},
5: {"2020-01-01", "二零一九年腊月初七"},
6: {"2020-02-01", "二零二零年正月初八"},
7: {"2020-03-01", "二零二零年二月初八"},
8: {"2020-04-01", "二零二零年三月初九"},
9: {"2020-04-23", "二零二零年四月初一"},
10: {"2020-05-01", "二零二零年四月初九"},
11: {"2020-06-01", "二零二零年四月初十"},
12: {"2020-07-01", "二零二零年五月十一"},
13: {"2020-08-01", "二零二零年六月十二"},
14: {"2020-09-01", "二零二零年七月十四"},
15: {"2020-10-01", "二零二零年八月十五"},
16: {"2020-11-01", "二零二零年九月十六"},
17: {"2020-12-01", "二零二零年十月十七"},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Lunar().ToDateString(), "Current test index is "+strconv.Itoa(index))
}
}
func TestLunar_IsLeapYear(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string
expected bool
}{
0: {"", false},
1: {"0", false},
2: {"0000-00-00", false},
3: {"00:00:00", false},
4: {"0000-00-00 00:00:00", false},
5: {"2020-04-23", true},
6: {"2020-05-01", true},
7: {"2020-08-05", true},
8: {"2021-01-01", true},
9: {"2021-07-07", false},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Lunar().IsLeapYear(), "Current test index is "+strconv.Itoa(index))
}
}
func TestLunar_IsLeapMonth(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string
expected bool
}{
0: {"", false},
1: {"0", false},
2: {"0000-00-00", false},
3: {"00:00:00", false},
4: {"0000-00-00 00:00:00", false},
5: {"2020-04-23", true},
6: {"2020-05-01", true},
7: {"2020-08-05", false},
8: {"2021-01-01", false},
9: {"2021-07-07", false},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Lunar().IsLeapMonth(), "Current test index is "+strconv.Itoa(index))
}
}
func TestLunar_IsRatYear(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string
expected bool
}{
0: {"", false},
1: {"0", false},
2: {"0000-00-00", false},
3: {"00:00:00", false},
4: {"0000-00-00 00:00:00", false},
5: {"2020-05-01", true},
6: {"2020-08-05", true},
7: {"2021-01-01", true},
8: {"2021-07-07", false},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Lunar().IsRatYear(), "Current test index is "+strconv.Itoa(index))
}
}
func TestLunar_IsOxYear(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string
expected bool
}{
0: {"", false},
1: {"0", false},
2: {"0000-00-00", false},
3: {"00:00:00", false},
4: {"0000-00-00 00:00:00", false},
5: {"2020-05-01", false},
6: {"2020-08-05", false},
7: {"2021-01-01", false},
8: {"2021-07-07", true},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Lunar().IsOxYear(), "Current test index is "+strconv.Itoa(index))
}
}
func TestLunar_IsTigerYear(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string
expected bool
}{
0: {"", false},
1: {"0", false},
2: {"0000-00-00", false},
3: {"00:00:00", false},
4: {"0000-00-00 00:00:00", false},
5: {"2020-05-01", false},
6: {"2020-08-05", false},
7: {"2021-01-01", false},
8: {"2021-07-07", false},
9: {"2022-08-05", true},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Lunar().IsTigerYear(), "Current test index is "+strconv.Itoa(index))
}
}
func TestLunar_IsRabbitYear(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string
expected bool
}{
0: {"", false},
1: {"0", false},
2: {"0000-00-00", false},
3: {"00:00:00", false},
4: {"0000-00-00 00:00:00", false},
5: {"2020-05-01", false},
6: {"2020-08-05", false},
7: {"2021-01-01", false},
8: {"2021-07-07", false},
9: {"2023-08-05", true},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Lunar().IsRabbitYear(), "Current test index is "+strconv.Itoa(index))
}
}
func TestLunar_IsDragonYear(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string
expected bool
}{
0: {"", false},
1: {"0", false},
2: {"0000-00-00", false},
3: {"00:00:00", false},
4: {"0000-00-00 00:00:00", false},
5: {"2020-05-01", false},
6: {"2020-08-05", false},
7: {"2021-01-01", false},
8: {"2021-07-07", false},
9: {"2024-08-05", true},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Lunar().IsDragonYear(), "Current test index is "+strconv.Itoa(index))
}
}
func TestLunar_IsSnakeYear(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string
expected bool
}{
0: {"", false},
1: {"0", false},
2: {"0000-00-00", false},
3: {"00:00:00", false},
4: {"0000-00-00 00:00:00", false},
5: {"2020-05-01", false},
6: {"2020-08-05", false},
7: {"2021-01-01", false},
8: {"2021-07-07", false},
9: {"2025-08-05", true},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Lunar().IsSnakeYear(), "Current test index is "+strconv.Itoa(index))
}
}
func TestLunar_IsHorseYear(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string
expected bool
}{
0: {"", false},
1: {"0", false},
2: {"0000-00-00", false},
3: {"00:00:00", false},
4: {"0000-00-00 00:00:00", false},
5: {"2020-05-01", false},
6: {"2020-08-05", false},
7: {"2021-01-01", false},
8: {"2021-07-07", false},
9: {"2026-08-05", true},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Lunar().IsHorseYear(), "Current test index is "+strconv.Itoa(index))
}
}
func TestLunar_IsGoatYear(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string
expected bool
}{
0: {"", false},
1: {"0", false},
2: {"0000-00-00", false},
3: {"00:00:00", false},
4: {"0000-00-00 00:00:00", false},
5: {"2020-05-01", false},
6: {"2020-08-05", false},
7: {"2021-01-01", false},
8: {"2021-07-07", false},
9: {"2027-08-05", true},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Lunar().IsGoatYear(), "Current test index is "+strconv.Itoa(index))
}
}
func TestLunar_IsMonkeyYear(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string
expected bool
}{
0: {"", false},
1: {"0", false},
2: {"0000-00-00", false},
3: {"00:00:00", false},
4: {"0000-00-00 00:00:00", false},
5: {"2020-05-01", false},
6: {"2020-08-05", false},
7: {"2021-01-01", false},
8: {"2021-07-07", false},
9: {"2028-08-05", true},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Lunar().IsMonkeyYear(), "Current test index is "+strconv.Itoa(index))
}
}
func TestLunar_IsRoosterYear(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string
expected bool
}{
0: {"", false},
1: {"0", false},
2: {"0000-00-00", false},
3: {"00:00:00", false},
4: {"0000-00-00 00:00:00", false},
5: {"2020-05-01", false},
6: {"2020-08-05", false},
7: {"2021-01-01", false},
8: {"2021-07-07", false},
9: {"2029-08-05", true},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Lunar().IsRoosterYear(), "Current test index is "+strconv.Itoa(index))
}
}
func TestLunar_IsDogYear(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string
expected bool
}{
0: {"", false},
1: {"0", false},
2: {"0000-00-00", false},
3: {"00:00:00", false},
4: {"0000-00-00 00:00:00", false},
5: {"2020-05-01", false},
6: {"2020-08-05", false},
7: {"2021-01-01", false},
8: {"2021-07-07", false},
9: {"2030-08-05", true},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Lunar().IsDogYear(), "Current test index is "+strconv.Itoa(index))
}
}
func TestLunar_IsPigYear(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string
expected bool
}{
0: {"", false},
1: {"0", false},
2: {"0000-00-00", false},
3: {"00:00:00", false},
4: {"0000-00-00 00:00:00", false},
5: {"2020-05-01", false},
6: {"2020-08-05", false},
7: {"2021-01-01", false},
8: {"2021-07-07", false},
9: {"2031-08-05", true},
}
for index, test := range tests {
c := Parse(test.input, PRC)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Lunar().IsPigYear(), "Current test index is "+strconv.Itoa(index))
}
}
func TestLunar_DoubleHour(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string
expected string
}{
0: {"", ""},
1: {"0", ""},
2: {"0000-00-00", ""},
3: {"00:00:00", ""},
4: {"0000-00-00 00:00:00", ""},
5: {"2020-01-05 23:23:45", "子时"},
6: {"2020-01-05 00:59:45", "子时"},
7: {"2020-02-05 01:00:00", "丑时"},
8: {"2020-02-05 03:40:00", "寅时"},
9: {"2020-02-05 05:00:00", "卯时"},
10: {"2020-02-05 07:30:00", "辰时"},
11: {"2020-02-05 09:00:00", "巳时"},
12: {"2020-02-05 11:00:00", "午时"},
13: {"2020-02-05 13:00:00", "未时"},
14: {"2020-02-05 15:00:00", "申时"},
15: {"2020-02-05 14:59:00", "未时"},
16: {"2020-02-05 17:00:00", "酉时"},
17: {"2020-02-05 19:00:00", "戌时"},
18: {"2020-02-05 21:00:00", "亥时"},
}
for index, test := range tests {
c := SetTimezone(PRC).Parse(test.input)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Lunar().DoubleHour(), "Current test index is "+strconv.Itoa(index))
}
}
func TestLunar_IsFirstDoubleHour(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string
expected bool
}{
0: {"", false},
1: {"0", false},
2: {"0000-00-00", false},
3: {"00:00:00", false},
4: {"0000-00-00 00:00:00", false},
5: {"2020-03-21 00:00:00", true},
6: {"2020-04-19 00:59:59", true},
7: {"2020-08-05 23:00:00", true},
8: {"2020-08-05 01:00:00", false},
}
for index, test := range tests {
c := SetTimezone(PRC).Parse(test.input)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Lunar().IsFirstDoubleHour(), "Current test index is "+strconv.Itoa(index))
}
}
func TestLunar_IsSecondDoubleHour(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string
expected bool
}{
0: {"", false},
1: {"0", false},
2: {"0000-00-00", false},
3: {"00:00:00", false},
4: {"0000-00-00 00:00:00", false},
5: {"2020-03-21 01:00:00", true},
6: {"2020-04-19 02:59:59", true},
7: {"2020-08-05 03:00:00", false},
}
for index, test := range tests {
c := SetTimezone(PRC).Parse(test.input)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Lunar().IsSecondDoubleHour(), "Current test index is "+strconv.Itoa(index))
}
}
func TestLunar_IsThirdDoubleHour(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string
expected bool
}{
0: {"", false},
1: {"0", false},
2: {"0000-00-00", false},
3: {"00:00:00", false},
4: {"0000-00-00 00:00:00", false},
5: {"2020-03-21 03:00:00", true},
6: {"2020-04-19 04:59:59", true},
7: {"2020-08-05 05:00:00", false},
}
for index, test := range tests {
c := SetTimezone(PRC).Parse(test.input)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Lunar().IsThirdDoubleHour(), "Current test index is "+strconv.Itoa(index))
}
}
func TestLunar_IsFourthDoubleHour(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string
expected bool
}{
0: {"", false},
1: {"0", false},
2: {"0000-00-00", false},
3: {"00:00:00", false},
4: {"0000-00-00 00:00:00", false},
5: {"2020-03-21 05:00:00", true},
6: {"2020-04-19 06:59:59", true},
7: {"2020-08-05 07:00:00", false},
}
for index, test := range tests {
c := SetTimezone(PRC).Parse(test.input)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Lunar().IsFourthDoubleHour(), "Current test index is "+strconv.Itoa(index))
}
}
func TestLunar_IsFifthDoubleHour(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string
expected bool
}{
0: {"", false},
1: {"0", false},
2: {"0000-00-00", false},
3: {"00:00:00", false},
4: {"0000-00-00 00:00:00", false},
5: {"2020-03-21 07:00:00", true},
6: {"2020-04-19 08:59:59", true},
7: {"2020-08-05 09:00:00", false},
}
for index, test := range tests {
c := SetTimezone(PRC).Parse(test.input)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Lunar().IsFifthDoubleHour(), "Current test index is "+strconv.Itoa(index))
}
}
func TestLunar_IsSixthDoubleHour(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string
expected bool
}{
0: {"", false},
1: {"0", false},
2: {"0000-00-00", false},
3: {"00:00:00", false},
4: {"0000-00-00 00:00:00", false},
5: {"2020-03-21 09:00:00", true},
6: {"2020-04-19 10:59:59", true},
7: {"2020-08-05 11:00:00", false},
}
for index, test := range tests {
c := SetTimezone(PRC).Parse(test.input)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Lunar().IsSixthDoubleHour(), "Current test index is "+strconv.Itoa(index))
}
}
func TestLunar_IsSeventhDoubleHour(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string
expected bool
}{
0: {"", false},
1: {"0", false},
2: {"0000-00-00", false},
3: {"00:00:00", false},
4: {"0000-00-00 00:00:00", false},
5: {"2020-03-21 11:00:00", true},
6: {"2020-04-19 12:59:59", true},
7: {"2020-08-05 13:00:00", false},
}
for index, test := range tests {
c := SetTimezone(PRC).Parse(test.input)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Lunar().IsSeventhDoubleHour(), "Current test index is "+strconv.Itoa(index))
}
}
func TestLunar_IsEighthDoubleHour(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string
expected bool
}{
0: {"", false},
1: {"0", false},
2: {"0000-00-00", false},
3: {"00:00:00", false},
4: {"0000-00-00 00:00:00", false},
5: {"2020-03-21 13:00:00", true},
6: {"2020-04-19 14:59:59", true},
7: {"2020-08-05 15:00:00", false},
}
for index, test := range tests {
c := SetTimezone(PRC).Parse(test.input)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Lunar().IsEighthDoubleHour(), "Current test index is "+strconv.Itoa(index))
}
}
func TestLunar_IsNinthDoubleHour(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string
expected bool
}{
0: {"", false},
1: {"0", false},
2: {"0000-00-00", false},
3: {"00:00:00", false},
4: {"0000-00-00 00:00:00", false},
5: {"2020-03-21 15:00:00", true},
6: {"2020-04-19 16:59:59", true},
7: {"2020-08-05 17:00:00", false},
}
for index, test := range tests {
c := SetTimezone(PRC).Parse(test.input)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Lunar().IsNinthDoubleHour(), "Current test index is "+strconv.Itoa(index))
}
}
func TestLunar_IsTenthDoubleHour(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string
expected bool
}{
0: {"", false},
1: {"0", false},
2: {"0000-00-00", false},
3: {"00:00:00", false},
4: {"0000-00-00 00:00:00", false},
5: {"2020-03-21 17:00:00", true},
6: {"2020-04-19 18:59:59", true},
7: {"2020-08-05 19:00:00", false},
}
for index, test := range tests {
c := SetTimezone(PRC).Parse(test.input)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Lunar().IsTenthDoubleHour(), "Current test index is "+strconv.Itoa(index))
}
}
func TestLunar_IsEleventhDoubleHour(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string
expected bool
}{
0: {"", false},
1: {"0", false},
2: {"0000-00-00", false},
3: {"00:00:00", false},
4: {"0000-00-00 00:00:00", false},
5: {"2020-03-21 19:00:00", true},
6: {"2020-04-19 20:59:59", true},
7: {"2020-08-05 21:00:00", false},
}
for index, test := range tests {
c := SetTimezone(PRC).Parse(test.input)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Lunar().IsEleventhDoubleHour(), "Current test index is "+strconv.Itoa(index))
}
}
func TestLunar_IsTwelfthDoubleHour(t *testing.T) {
assert := assert.New(t)
tests := []struct {
input string
expected bool
}{
0: {"", false},
1: {"0", false},
2: {"0000-00-00", false},
3: {"00:00:00", false},
4: {"0000-00-00 00:00:00", false},
5: {"2020-03-21 21:00:00", true},
6: {"2020-04-19 22:59:59", true},
7: {"2020-08-05 23:00:00", false},
}
for index, test := range tests {
c := SetTimezone(PRC).Parse(test.input)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Lunar().IsTwelfthDoubleHour(), "Current test index is "+strconv.Itoa(index))
}
}
func TestError_Lunar(t *testing.T) {
c := CreateFromDate(1840, 1, 1, "xxx").Lunar()
assert.NotNil(t, c.Error, "It should catch an exception in Lunar()")
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/jangocheng/carbon.git
git@gitee.com:jangocheng/carbon.git
jangocheng
carbon
carbon
master

搜索帮助