From 706dbbc53328dbfe74f70aee38765551d6a836d0 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 1 Nov 2024 00:41:34 -0500 Subject: pretty output for humans d.SprintHeader() Signed-off-by: Jeff Carr --- time.go | 64 ---------------------------------------------------------------- 1 file changed, 64 deletions(-) delete mode 100644 time.go (limited to 'time.go') diff --git a/time.go b/time.go deleted file mode 100644 index 28f4098..0000000 --- a/time.go +++ /dev/null @@ -1,64 +0,0 @@ -package virtbuf - -import ( - "fmt" - "time" -) - -func FormatDuration(d time.Duration) string { - result := "" - - // check if it's more than a year - years := int(d.Hours()) / (24 * 365) - if years > 0 { - result += fmt.Sprintf("%dy ", years) - return result - } - - // check if it's more than a day - days := int(d.Hours()) / 24 - if days > 0 { - result += fmt.Sprintf("%dd ", days) - return result - } - - // check if it's more than an hour - hours := int(d.Hours()) % 24 - if hours > 0 { - result += fmt.Sprintf("%dh ", hours) - return result - } - - // check if it's more than a minute - minutes := int(d.Minutes()) % 60 - if minutes > 0 { - result += fmt.Sprintf("%dm ", minutes) - return result - } - - // check if it's more than a second - seconds := int(d.Seconds()) % 60 - if seconds > 0 { - result += fmt.Sprintf("%ds", seconds) - return result - } - - // report in milliseconds - ms := int(d.Milliseconds()) - if ms > 100 { - // todo: print .3s, etc ? - return fmt.Sprintf("%1.2fs", seconds/1000) - } - result += fmt.Sprintf("%dms", ms) - return result -} - -func GetDurationStamp(t time.Time) string { - // Get the current time - currentTime := time.Now() - - // Calculate the duration between t current time - duration := currentTime.Sub(t) - - return FormatDuration(duration) -} -- cgit v1.2.3