fix comments duration

This commit is contained in:
deepzz0
2018-05-07 20:45:37 +08:00
parent 01b7643ca5
commit f016b28cb6
2 changed files with 14 additions and 8 deletions

View File

@@ -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
}

View File

@@ -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))
}
}