Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Commit

Permalink
Optimized time and flow display
Browse files Browse the repository at this point in the history
  • Loading branch information
sky96111 committed Mar 17, 2023
1 parent 13c6d54 commit d477b21
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions zwu.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,26 @@ func status() error {

MB, _ := strconv.ParseFloat(flow, 64)
MB /= 1024
log.Println("time:", time, "Min")
log.Println("flow:", MB, "MB")

// less than 1h, print minutes, else if less than 24hours print hours, else print days
if timeInt, err := strconv.Atoi(time); err == nil {
if timeInt < 60 {
log.Println("time:", time, "Min")
} else if timeInt < 60*24 {
log.Println("time:", timeInt/60, "Hour")
} else {
log.Println("time:", timeInt/60/24, "Day")
}
} else {
log.Println("time:", time)
}
// less than 1GB, print MB, else if less than 1TB print GB, else print TB
if MB < 1024 {
log.Println("flow:", MB, "MB")
} else if MB < 1024*1024 {
log.Println("flow:", MB/1024, "GB")
} else {
log.Println("flow:", MB/1024/1024, "TB")
}
return nil
}

0 comments on commit d477b21

Please sign in to comment.