Ai
1 Star 0 Fork 0

鹏程/studygolang

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
time_test.go 1.08 KB
一键复制 编辑 原始数据 按行查看 历史
xuxinhua 提交于 2017-11-20 17:33 +08:00 . subject
// Copyright 2017 The StudyGolang Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// http://studygolang.com
// Author: polaris polaris@studygolang.com
package util_test
import (
"testing"
"time"
"util"
)
func TestTimeAgo(t *testing.T) {
type args struct {
t time.Time
}
tests := []struct {
name string
args args
want string
}{
{
"小于1分钟",
args{time.Now().Add(-30 * time.Second)},
"约 1 分钟前",
},
{
"约2小时前",
args{time.Now().Add(-100 * time.Minute)},
"约 2 小时前",
},
{
"约1天前",
args{time.Now().Add(-25 * time.Hour)},
"约 1 天前",
},
{
"11-02 14:00",
args{time.Date(2017, 11, 2, 14, 0, 0, 0, time.Local)},
"11-02 14:00",
},
{
"2016-02-02",
args{time.Date(2016, 2, 2, 0, 0, 0, 0, time.Local)},
"2016-02-02",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := util.TimeAgo(tt.args.t); got != tt.want {
t.Errorf("TimeAgo() = %v, want %v", got, tt.want)
}
})
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/barry_zpc/studygolang.git
git@gitee.com:barry_zpc/studygolang.git
barry_zpc
studygolang
studygolang
master

搜索帮助