Skip to content

Commit 7c9aefb

Browse files
naiming-zededaeriknordmark
authored andcommitted
Change the Edgeview script expire to humnan readable time
- change the expired time from always using seconds to human readable time in seconds, minutes, hours and days Signed-off-by: naiming-zededa <naiming@zededa.com>
1 parent e7a11a2 commit 7c9aefb

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

pkg/edgeview/src/basics.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ func getAddrFromJWT(token string, isServer bool, instID int) (string, string, ty
228228
now := time.Now()
229229
nowSec := uint64(now.Unix())
230230
if nowSec > jdata.Exp {
231-
return addrport, path, evAuth, fmt.Errorf("JWT expired %d sec ago", nowSec-jdata.Exp)
231+
return addrport, path, evAuth, fmt.Errorf("JWT expired %v", humanTimeAgo(nowSec-jdata.Exp))
232232
}
233233

234234
if jdata.Num > 1 && instID < 1 {
@@ -610,6 +610,22 @@ func getKubeServerIPandPort(kubeConfigFile string) (string, error) {
610610
return strings.TrimSpace(matches[1]), nil
611611
}
612612

613+
// convert seconds difference to human readable time ago string
614+
func humanTimeAgo(secDiff uint64) string {
615+
d := time.Duration(secDiff) * time.Second
616+
switch {
617+
case d < time.Minute:
618+
return fmt.Sprintf("%d seconds ago", int(d.Seconds()))
619+
case d < time.Hour:
620+
return fmt.Sprintf("%d minutes ago", int(d.Minutes()))
621+
case d < 24*time.Hour:
622+
return fmt.Sprintf("%d hours ago", int(d.Hours()))
623+
default:
624+
days := int(d.Hours() / 24)
625+
return fmt.Sprintf("%d days ago", days)
626+
}
627+
}
628+
613629
var helpStr = `eve-edgeview [ -token <session-token> ] [ -inst <instance-id> ] <query command>
614630
query options:
615631
`

0 commit comments

Comments
 (0)