49 lines
1.3 KiB
Go
49 lines
1.3 KiB
Go
package helper
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestBuildStr(t *testing.T) {
|
|
uid := "example_uid"
|
|
arr := []int{1, 2, 3}
|
|
result := BuildStr(uid, arr)
|
|
fmt.Println(result)
|
|
|
|
arrStr := []string{"a", "b", "c"}
|
|
resultStr := BuildStr(uid, arrStr)
|
|
fmt.Println(resultStr)
|
|
}
|
|
|
|
func TestAddDate(t *testing.T) {
|
|
// 获取当前时间
|
|
now := time.Now()
|
|
fmt.Println("当前时间:", now.Format(time.DateTime))
|
|
|
|
// 当前时间往后推 7 天
|
|
future := now.AddDate(0, 0, 7)
|
|
fmt.Println("当前时间往后推 7 天:", future.Format(time.DateTime))
|
|
|
|
// 当前时间往前推 7 天
|
|
past := now.AddDate(0, 0, -7)
|
|
fmt.Println("当前时间往前推 7 天:", past.Format(time.DateTime))
|
|
}
|
|
|
|
func TestSevenDaysAgo(t *testing.T) {
|
|
// 获取当前时间
|
|
now := time.Now()
|
|
|
|
sevenDaysAgoEnd := now.AddDate(0, 0, -1)
|
|
// 获取今天 23:59:59 的时间
|
|
endTime := time.Date(sevenDaysAgoEnd.Year(), sevenDaysAgoEnd.Month(), sevenDaysAgoEnd.Day(), 23, 59, 59, 0, sevenDaysAgoEnd.Location())
|
|
// 获取七天前的日期
|
|
sevenDaysAgo := now.AddDate(0, 0, -7)
|
|
// 获取七天前 00:00:00 的时间
|
|
startTime := time.Date(sevenDaysAgo.Year(), sevenDaysAgo.Month(), sevenDaysAgo.Day(), 0, 0, 0, 0, sevenDaysAgo.Location())
|
|
|
|
fmt.Printf("开始时间: %s\n", startTime.Format(time.DateTime))
|
|
fmt.Printf("结束时间: %s\n", endTime.Format(time.DateTime))
|
|
}
|