From 111b90407f28e89af409c59ecd15b9c957c3e11b Mon Sep 17 00:00:00 2001 From: Andrea Vaccaro Date: Sun, 10 Nov 2024 16:30:41 +0100 Subject: [PATCH] HOT-FIX: time was expressed wrong, fixed. --- libs/libs.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/libs/libs.go b/libs/libs.go index 4935992..d38affc 100644 --- a/libs/libs.go +++ b/libs/libs.go @@ -304,18 +304,17 @@ func ParseMac(mac string) (hwAddr net.HardwareAddr) { // Seconds to format model 00h00m00s func SecondsToHMS(seconds int) (formattedTime string) { - elap := time.Duration(seconds) * time.Second - hours, minutes, seconds2 := int(elap / 60 / 60), int(elap / 60), int(elap) - if hours > 0 { - formattedTime += fmt.Sprintf("%dh ", hours) - } - if minutes > 0 || hours > 0 { - formattedTime += fmt.Sprintf("%dm ", minutes) - } - if seconds2 > 0 || formattedTime == "" { - formattedTime += fmt.Sprintf("%ds", seconds2) + var hours int = seconds / 3600 + var minutes int = (seconds % 3600) / 60 + seconds = seconds % 60 + switch { + case hours > 0: + return fmt.Sprintf("%dh %dm %ds", hours, minutes, seconds) + case minutes > 0: + return fmt.Sprintf("%dm %ds", minutes, seconds) + default: + return fmt.Sprintf("%ds", seconds) } - return formattedTime } // Radiolocalize a device from data and return meters (approximately)