diff --git a/helper.go b/helper.go index e90659e..4f72bcf 100644 --- a/helper.go +++ b/helper.go @@ -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 } diff --git a/helper_test.go b/helper_test.go index d5242d9..4502161 100644 --- a/helper_test.go +++ b/helper_test.go @@ -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)) } }