Enhance shortHumanDuration to handle more situation

Allow 2 seconds deviation of current time. For time more than 2
seconds from current time, output as '<invalid>'.
This commit is contained in:
hurf
2015-08-14 17:10:22 +08:00
parent 501594f8c7
commit c20ed0344a
2 changed files with 9 additions and 1 deletions

View File

@@ -1104,6 +1104,8 @@ type stringTestList []struct {
func TestTranslateTimestamp(t *testing.T) {
tl := stringTestList{
{"a while from now", translateTimestamp(util.Time{Time: time.Now().Add(2.1e9)}), "<invalid>"},
{"almost now", translateTimestamp(util.Time{Time: time.Now().Add(1.9e9)}), "0s"},
{"now", translateTimestamp(util.Time{Time: time.Now()}), "0s"},
{"unknown", translateTimestamp(util.Time{}), "<unknown>"},
{"30 seconds ago", translateTimestamp(util.Time{Time: time.Now().Add(-3e10)}), "30s"},