mirror of
https://github.com/eiblog/eiblog.git
synced 2026-02-04 13:52:26 +08:00
fix comments duration
This commit is contained in:
@@ -125,7 +125,7 @@ func ConvertStr(str string) string {
|
||||
} else if h := d*24 + h2 - h1; h > 1 || (h == 1 && mi2-mi1 >= 0) {
|
||||
return fmt.Sprintf(HOURS_AGO, h)
|
||||
} else if mi := h*60 + mi2 - mi1; mi > 1 || (mi == 1 && s2-s1 >= 0) {
|
||||
return fmt.Sprintf(MINUTES_AGO, m)
|
||||
return fmt.Sprintf(MINUTES_AGO, mi)
|
||||
}
|
||||
return JUST_NOW
|
||||
}
|
||||
|
||||
@@ -44,15 +44,21 @@ func TestPickFirstImage(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCovertStr(t *testing.T) {
|
||||
now := time.Now().UTC()
|
||||
testStr := []string{
|
||||
time.Now().Format("2006-01-02T15:04:05"),
|
||||
now.Format("2006-01-02T15:04:05"),
|
||||
now.Add(-time.Second * 20).Format("2006-01-02T15:04:05"),
|
||||
now.Add(-time.Minute).Format("2006-01-02T15:04:05"),
|
||||
now.Add(-time.Minute * 2).Format("2006-01-02T15:04:05"),
|
||||
now.Add(-time.Minute * 20).Format("2006-01-02T15:04:05"),
|
||||
now.Add(-time.Hour).Format("2006-01-02T15:04:05"),
|
||||
now.Add(-time.Hour * 2).Format("2006-01-02T15:04:05"),
|
||||
now.Add(-time.Hour * 24).Format("2006-01-02T15:04:05"),
|
||||
}
|
||||
|
||||
expectStr := []string{
|
||||
JUST_NOW,
|
||||
}
|
||||
|
||||
for i, v := range testStr {
|
||||
assert.Equal(t, expectStr[i], ConvertStr(v))
|
||||
time.Sleep(time.Second)
|
||||
t.Log(now.Format("2006-01-02T15:04:05"))
|
||||
for _, v := range testStr {
|
||||
t.Log(v, ConvertStr(v))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user