package utils_test import ( "fmt" "go_dreamfactory/sys/configure" "go_dreamfactory/utils" "strconv" "testing" "time" . "github.com/smartystreets/goconvey/convey" "github.com/spf13/cast" ) func TestIsToday(t *testing.T) { // fmt.Println(utils.IsToday(0)) tt := time.Unix(1658139742, 0) fmt.Println(configure.Now().Before(tt)) } func TestIsYestoday(t *testing.T) { Convey("昨天", t, func() { b := utils.IsYestoday(1661912369) So(b, ShouldEqual, true) }) } func TestSubTime(t *testing.T) { fmt.Println(utils.IsAfterWeek(1657172915)) } func TestRandom(t *testing.T) { fmt.Println(utils.GenValidateCode(6)) } func TestNumber(t *testing.T) { for i := 0; i < 100; i++ { fmt.Println(utils.RandomNumbers(0, 4, 6)) } } func BenchmarkNumber(b *testing.B) { b.Log("begin") b.ReportAllocs() for i := 0; i < b.N; i++ { utils.RandomNumbers(0, 1000, 10) } } func BenchmarkStringToInt32(b *testing.B) { b.Log("begin") b.ReportAllocs() for i := 0; i < b.N; i++ { a := "123123" strconv.Atoi(a) // cast.ToInt32(a) } } func BenchmarkInt32ToString(b *testing.B) { b.Log("begin") b.ReportAllocs() for i := 0; i < b.N; i++ { a := 123123 // strconv.Itoa(a) cast.ToString(a) } } func TestMatrxing(t *testing.T) { utils.MatrixingHour("2022-10-11 00:00:00") } func TestCompre(t *testing.T) { // a := []int32{1, 2, 4, 5} // b := []int32{1, 2, 4} // fmt.Println(utils.ForContainer(a, b)) } func TestDeletex(t *testing.T) { // a := []int32{1, 2, 3, 4} // c := utils.Deletex(a, 2) // fmt.Println(c) } func TestDiffDays(t *testing.T) { // fmt.Println(utils.DiffDays(1614527999, 1614614400)) } func BenchmarkRandNumbers(b *testing.B) { for i := 0; i < b.N; i++ { b.ReportAllocs() utils.RandomNumbers(0, 7, 4) } } func TestIsSameWeek(t *testing.T) { // 将时间戳转换为 time.Time 类型 time1 := time.Now() time2 := time.Now() // 获取时间戳所属的年份和周数 year1, week1 := time1.ISOWeek() year2, week2 := time2.ISOWeek() // 判断是否同一年同一周 if year1 == year2 && week1 == week2 { fmt.Println("两个时间戳属于同一周") } else { fmt.Println("两个时间戳不属于同一周") } } func TestWeekIntervalTime(t *testing.T) { ti := utils.WeekIntervalTime(0) format := "2006-01-02 15:04:05" formattedTime := time.Unix(ti, 0).Format(format) fmt.Println(formattedTime) }