Finish the cron things.
This commit is contained in:
@ -2,8 +2,12 @@ package test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/eyebluecn/tank/code/tool/util"
|
||||
"github.com/robfig/cron"
|
||||
"log"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestHello(t *testing.T) {
|
||||
@ -12,3 +16,34 @@ func TestHello(t *testing.T) {
|
||||
fmt.Printf("%v", split)
|
||||
|
||||
}
|
||||
|
||||
//测试cron表达式
|
||||
func TestCron(t *testing.T) {
|
||||
|
||||
i := 0
|
||||
c := cron.New()
|
||||
spec := "*/1 * * * * ?"
|
||||
err := c.AddFunc(spec, func() {
|
||||
i++
|
||||
log.Println("cron running:", i)
|
||||
})
|
||||
util.PanicError(err)
|
||||
|
||||
c.Start()
|
||||
|
||||
//当前线程阻塞 20s
|
||||
time.Sleep(3 * time.Second)
|
||||
|
||||
}
|
||||
|
||||
//测试 时间
|
||||
func TestDayAgo(t *testing.T) {
|
||||
|
||||
dayAgo := time.Now()
|
||||
dayAgo = dayAgo.AddDate(0, 0, -8)
|
||||
|
||||
thenDay := util.FirstSecondOfDay(dayAgo)
|
||||
|
||||
fmt.Printf("%s\n", util.ConvertTimeToDateTimeString(thenDay))
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user